Skip to content

Commit

Permalink
feat(docs): add guides alias (#647)
Browse files Browse the repository at this point in the history
* feat: create guides aliases

* test: alias tests

* docs: make OAS category name more generic

* docs: rename docs header

* chore: rearrange categories

* docs: update headings, add alias docs
  • Loading branch information
kanadgupta authored Oct 27, 2022
1 parent 7552501 commit d412a04
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 11 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ rdme openapi:reduce [path-to-file.json]

The command will ask you a couple questions about how you wish to reduce the file and then do so. And as with the `openapi` command, you can also [omit the file path](#omitting-the-file-path).

### Docs
### Docs (a.k.a. Guides)

The Markdown files will require YAML front matter with certain ReadMe documentation attributes. Check out [our docs](https://docs.readme.com/docs/rdme#markdown-file-setup) for more info on setting up your front matter.

Expand All @@ -203,6 +203,12 @@ Passing in a path to a directory will also sync any Markdown files that are loca
rdme docs [path] --version={project-version}
```

This command also has an alias called `guides`:

```
rdme guides [path] --version={project-version}
```

This command also has a dry run mode, which can be useful for initial setup and debugging. You can read more about dry run mode [in our docs](https://docs.readme.com/docs/rdme#dry-run-mode).

#### Prune
Expand All @@ -213,7 +219,13 @@ If you wish to delete documents from ReadMe that are no longer present in your l
rdme docs:prune path-to-directory-of-markdown
```

### Changelogs
This command also has an alias called `guides:prune`:

```sh
rdme guides:prune path-to-directory-of-markdown
```

### Changelog

The Markdown files will require YAML front matter with certain ReadMe documentation attributes. Check out [our docs](https://docs.readme.com/docs/rdme#markdown-file-setup) for more info on setting up your front matter.

Expand Down
18 changes: 18 additions & 0 deletions __tests__/cmds/docs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import nock from 'nock';
import prompts from 'prompts';

import DocsCommand from '../../../src/cmds/docs';
import GuidesCommand from '../../../src/cmds/guides';
import APIError from '../../../src/lib/apiError';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock';
import { after, before } from '../../helpers/get-gha-setup';
import hashFileContents from '../../helpers/hash-file-contents';

const docs = new DocsCommand();
const guides = new GuidesCommand();

const fixturesBaseDir = '__fixtures__/docs';
const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
Expand Down Expand Up @@ -626,3 +628,19 @@ describe('rdme docs', () => {
});
});
});

describe('rdme guides', () => {
beforeAll(() => nock.disableNetConnect());

afterAll(() => nock.cleanAll());

it('should error if no path provided', async () => {
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

await expect(guides.run({ key, version: '1.0.0' })).rejects.toStrictEqual(
new Error('No path provided. Usage `rdme guides <path> [options]`.')
);

versionMock.done();
});
});
14 changes: 14 additions & 0 deletions __tests__/cmds/docs/prune.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import nock from 'nock';
import prompts from 'prompts';

import DocsPruneCommand from '../../../src/cmds/docs/prune';
import GuidesPruneCommand from '../../../src/cmds/guides/prune';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock';

const docsPrune = new DocsPruneCommand();
const guidesPrune = new GuidesPruneCommand();

const fixturesBaseDir = '__fixtures__/docs';

Expand Down Expand Up @@ -118,3 +120,15 @@ describe('rdme docs:prune', () => {
versionMock.done();
});
});

describe('rdme guides:prune', () => {
beforeAll(() => nock.disableNetConnect());

afterAll(() => nock.cleanAll());

it('should error if no folder provided', () => {
return expect(guidesPrune.run({ key, version: '1.0.0' })).rejects.toStrictEqual(
new Error('No folder provided. Usage `rdme guides:prune <folder> [options]`.')
);
});
});
2 changes: 1 addition & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('cli', () => {
});

it('should not error with undefined cmd', async () => {
await expect(cli([])).resolves.toContain('Upload OpenAPI/Swagger definitions');
await expect(cli([])).resolves.toContain('OpenAPI / Swagger');
});

it('should add stored apiKey to opts', async () => {
Expand Down
16 changes: 14 additions & 2 deletions __tests__/lib/__snapshots__/commands.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports[`utils #listByCategory should list commands by category 1`] = `
"position": 5,
},
],
"description": "Upload OpenAPI/Swagger definitions",
"description": "OpenAPI / Swagger",
},
"categories": {
"commands": [
Expand Down Expand Up @@ -119,8 +119,20 @@ exports[`utils #listByCategory should list commands by category 1`] = `
"name": "docs:edit",
"position": 3,
},
{
"description": "Alias for \`rdme docs\`.",
"hidden": false,
"name": "guides",
"position": 3,
},
{
"description": "Alias for \`rdme docs:prune\`.",
"hidden": false,
"name": "guides:prune",
"position": 4,
},
],
"description": "Documentation",
"description": "Docs (a.k.a. Guides)",
},
"utilities": {
"commands": [
Expand Down
19 changes: 19 additions & 0 deletions src/cmds/guides/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { CommandOptions } from '../../lib/baseCommand';
import type { Options } from '../docs';

import DocsCommand from '../docs';

export default class GuidesCommand extends DocsCommand {
constructor() {
super();

this.command = 'guides';
this.usage = 'guides <path> [options]';
this.description = 'Alias for `rdme docs`.';
this.position = 3;
}

async run(opts: CommandOptions<Options>) {
return super.run(opts);
}
}
19 changes: 19 additions & 0 deletions src/cmds/guides/prune.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { CommandOptions } from '../../lib/baseCommand';
import type { Options } from '../docs/prune';

import DocsPruneCommand from '../docs/prune';

export default class GuidesPruneCommand extends DocsPruneCommand {
constructor() {
super();

this.command = 'guides:prune';
this.usage = 'guides:prune <folder> [options]';
this.description = 'Alias for `rdme docs:prune`.';
this.position = 4;
}

async run(opts: CommandOptions<Options>) {
return super.run(opts);
}
}
4 changes: 4 additions & 0 deletions src/cmds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import CustomPagesCommand from './custompages';
import DocsCommand from './docs';
import DocsEditCommand from './docs/edit';
import DocsPruneCommand from './docs/prune';
import GuidesCommand from './guides';
import GuidesPruneCommand from './guides/prune';
import LoginCommand from './login';
import LogoutCommand from './logout';
import OASCommand from './oas';
Expand All @@ -30,6 +32,8 @@ const commands = {
docs: DocsCommand,
'docs:prune': DocsPruneCommand,
'docs:edit': DocsEditCommand,
guides: GuidesCommand,
'guides:prune': GuidesPruneCommand,

versions: VersionsCommand,
'versions:create': CreateVersionCommand,
Expand Down
12 changes: 6 additions & 6 deletions src/lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export function getCategories(): Record<
> {
return {
apis: {
description: 'Upload OpenAPI/Swagger definitions',
description: 'OpenAPI / Swagger',
commands: [],
},
docs: {
description: 'Documentation',
description: 'Docs (a.k.a. Guides)',
commands: [],
},
changelogs: {
Expand All @@ -31,14 +31,14 @@ export function getCategories(): Record<
description: 'Custom Pages',
commands: [],
},
categories: {
description: 'Categories',
commands: [],
},
versions: {
description: 'Versions',
commands: [],
},
categories: {
description: 'Categories',
commands: [],
},
admin: {
description: 'Administration',
commands: [],
Expand Down

0 comments on commit d412a04

Please sign in to comment.