Skip to content

Commit ef42cc9

Browse files
authored
feat: add Amplify CLI command reference (aws-amplify#4950)
* feat: add Amplify CLI command reference * chore: migrate next.config, directory to ESM. enables reading cli command info from npm distribution * chore: add amplify-cli-core as a dependency * fix: inline code block sidenav link * migrate away from 'tasks' cmd, mjs tasks * jest to transform mjs * directory import to use mjs extension, correct expected error message * revert error message correction due to different node versions * update lockfile * fix subcommand descriptions, remove usage subsections * pin amplify-cli-core version * add types, fix usage of table captions * patch duplicate subcommands from dataset * update lockfile from main * use scoped package, update to 4+
1 parent 26f95d9 commit ef42cc9

File tree

16 files changed

+1360
-88
lines changed

16 files changed

+1360
-88
lines changed

next.config.js renamed to next.config.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import { createRequire } from 'node:module';
2+
import dotenv from 'dotenv';
3+
import _withMDX from '@next/mdx';
4+
import { directory } from './src/directory/directory.mjs';
5+
const require = createRequire(import.meta.url);
6+
7+
dotenv.config({ path: './.env.custom' });
8+
9+
// eslint-disable-next-line @typescript-eslint/no-var-requires
110
const withTM = require('next-transpile-modules')([
211
'@algolia/autocomplete-shared'
312
]); // pass the modules you would like to see transpiled
@@ -7,12 +16,7 @@ const mdxRenderer = `
716
817
`;
918

10-
// eslint-disable-next-line @typescript-eslint/no-var-requires
11-
const directory = require('./src/directory/directory.js');
12-
13-
require('dotenv').config({ path: './.env.custom' });
14-
15-
module.exports = async (phase, { defaultConfig }) => {
19+
export default async (phase, { defaultConfig }) => {
1620
// eslint-disable-next-line @typescript-eslint/no-var-requires
1721
const headingLinkPlugin = await require('./src/plugins/headings.tsx');
1822
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -26,7 +30,7 @@ module.exports = async (phase, { defaultConfig }) => {
2630
// eslint-disable-next-line @typescript-eslint/no-var-requires
2731
const frontmatterPlugin = await require('./src/plugins/frontmatter.tsx');
2832

29-
const withMDX = require('@next/mdx')({
33+
const withMDX = _withMDX({
3034
extension: /\.mdx$/,
3135
options: {
3236
remarkPlugins: [

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@algolia/autocomplete-shared": "^1.5.6",
1919
"@algolia/autocomplete-theme-classic": "^1.6.1",
2020
"@algolia/client-search": "^4.13.0",
21+
"@aws-amplify/amplify-cli-core": "^4.0.1",
2122
"@aws-amplify/ui-components": "latest",
2223
"@aws-amplify/ui-react": "^4.4.3",
2324
"@emotion/react": "^11.1.5",
@@ -98,11 +99,12 @@
9899
"decode-uri-component": "0.2.1"
99100
},
100101
"jest": {
102+
"preset": "ts-jest",
101103
"roots": [
102104
"<rootDir>/src"
103105
],
104106
"transform": {
105-
"^.+\\.(ts|tsx|js)$": [
107+
"^.+\\.(ts|tsx|js|mjs)$": [
106108
"babel-jest",
107109
{
108110
"presets": [
@@ -123,12 +125,11 @@
123125
"scripts": {
124126
"clean": "rm -rf node_modules yarn.lock",
125127
"refresh": "yarn clean && yarn",
126-
"task": "ts-node tasks",
127128
"test": "jest",
128129
"dev": "next dev",
129130
"spellcheck": "cspell \"src/**/*.mdx\"",
130131
"spellcheck-diff": "git diff --name-only --cached | awk \"/src.*\\.mdx/{print}\" | npx cspell --no-must-find-files --file-list stdin",
131-
"build": "yarn task generate-sitemap && next build && next export -o client/www/next-build",
132+
"build": "node tasks/generate-sitemap.mjs && next build && next export -o client/www/next-build",
132133
"next-build": "next build",
133134
"next-start": "next start",
134135
"amplify:submissionsLambda": "cd amplify/backend/function/submissionsLambda/src && yarn install && yarn build && yarn test",

src/components/Menu/Directory/__tests__/Directory.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import Directory from '../index';
4-
import directory from '../../../../directory/directory';
4+
import directory from '../../../../directory/directory.mjs';
55

66
describe('Directory', () => {
77
const directoryKeys = Object.keys(directory);

src/components/Menu/Directory/index.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,7 @@ import {
88
DirectoryLinksStyle,
99
ProductRootLinkStyle
1010
} from './styles';
11-
12-
export type DirectoryItem = {
13-
/**
14-
* Title used for sidenav link, page title, and page heading
15-
*/
16-
title: string;
17-
/**
18-
* Control whether the title should be displayed as inline code
19-
* @default false
20-
*/
21-
isCodeTitle: boolean;
22-
route: string;
23-
filters: string[];
24-
};
11+
import type { DirectoryItem } from '../../../directory/directory';
2512

2613
export type DirectoryGroupProps = {
2714
title: string;
@@ -100,7 +87,9 @@ class DirectoryGroup extends React.Component<
10087
>
10188
<InternalLink href={`${item.route}`}>
10289
{item.isCodeTitle ? (
103-
<code>{item.title}</code>
90+
<a>
91+
<code>{item.title}</code>
92+
</a>
10493
) : (
10594
item.title
10695
)}

src/components/Menu/VersionSwitcher/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Link from "next/link";
22
import {ActiveSwitchStyle, SwitchStyle} from "./styles";
3-
import directory from "../../../directory/directory";
3+
import directory from "../../../directory/directory.mjs";
44

55
const ui = directory["ui"].items;
66
const uiLegacy = directory["ui-legacy"].items;

src/components/Menu/__tests__/Menu.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import Menu from '../index';
4-
import directory from '../../../directory/directory';
4+
import directory from '../../../directory/directory.mjs';
55

66
jest.mock('../RepoActions', () => () => <div>Repo Actions</div>);
77
Object.defineProperty(window, 'matchMedia', {

src/data/cli-commands.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type CliCommandFlag = {
2+
short: string;
3+
long: string;
4+
description: string;
5+
};
6+
7+
export type CliCommand = {
8+
name: string;
9+
description: string;
10+
usage: string;
11+
learnMoreLink?: string;
12+
flags: CliCommandFlag[] | [];
13+
subCommands?: CliCommand[];
14+
};

src/data/cli-commands.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { commandsInfo } from 'amplify-cli-core/lib/help/commands-info.js';
2+
3+
/**
4+
* Get and transform command data
5+
* @returns {import('./cli-commands').CliCommand[]} Array of commands
6+
*/
7+
export function getCliCommands() {
8+
const result = [];
9+
for (const command of commandsInfo) {
10+
const { subCommands } = command;
11+
result.push({
12+
name: command.command,
13+
description: command.commandDescription,
14+
usage: command.commandUsage,
15+
flags: command.commandFlags.length
16+
? command.commandFlags.map((flag) => ({
17+
short: flag.short,
18+
long: flag.long,
19+
description: flag.flagDescription
20+
}))
21+
: [],
22+
subCommands: subCommands.length
23+
? subCommands
24+
.map((subCommand) => ({
25+
name: subCommand.subCommand,
26+
description: subCommand.subCommandDescription,
27+
usage: subCommand.subCommandUsage,
28+
flags: subCommand.subCommandFlags.length
29+
? subCommand.subCommandFlags.map((flag) => ({
30+
short: flag.short,
31+
long: flag.long,
32+
description: flag.flagDescription
33+
}))
34+
: []
35+
}))
36+
.reduce((acc, subCommand) => {
37+
/** @todo remove this .reduce() after duplicates are removed from the data set */
38+
if (!acc.find((cmd) => cmd.name === subCommand.name)) {
39+
acc.push(subCommand);
40+
}
41+
return acc;
42+
}, [])
43+
: []
44+
});
45+
}
46+
return result;
47+
}
48+
49+
export const commands = getCliCommands();

src/directory/directory.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export type DirectoryItem = {
2+
/**
3+
* Title used for sidenav link, page title, and page heading
4+
*/
5+
title: string;
6+
filters?: string[];
7+
/**
8+
* Control whether the title should be displayed as inline code
9+
* @default false
10+
*/
11+
isCodeTitle?: boolean;
12+
route: string;
13+
};
14+
15+
export type Directory = {
16+
productRoot: {
17+
title: string;
18+
route: string;
19+
};
20+
items: Record<
21+
string,
22+
{
23+
title: string;
24+
items: DirectoryItem[];
25+
route?: string;
26+
filters?: string[];
27+
}
28+
>;
29+
};

src/directory/directory.js renamed to src/directory/directory.mjs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
const directory = {
1+
import { commands } from '../data/cli-commands.mjs';
2+
3+
/**
4+
* @type {Record<string, import('./directory').Directory>}
5+
*/
6+
export const directory = {
27
contribute: {
38
productRoot: {
49
title: 'Contribute',
@@ -1674,6 +1679,16 @@ const directory = {
16741679
}
16751680
]
16761681
},
1682+
commands: {
1683+
title: 'Commands',
1684+
items: commands
1685+
.sort((a, b) => ((a.name > b.name ? 1 : -1)))
1686+
.map(({ name }) => ({
1687+
isCodeTitle: true,
1688+
title: name,
1689+
route: `/cli/commands/${name}`
1690+
}))
1691+
},
16771692
graphql: {
16781693
title: 'API (GraphQL)',
16791694
items: [
@@ -2666,4 +2681,4 @@ const directory = {
26662681
}
26672682
};
26682683

2669-
module.exports = directory;
2684+
export default directory;

0 commit comments

Comments
 (0)