Skip to content

Commit

Permalink
feat: add Amplify CLI command reference (aws-amplify#4950)
Browse files Browse the repository at this point in the history
* 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+
  • Loading branch information
josefaidt authored Mar 30, 2023
1 parent 26f95d9 commit ef42cc9
Show file tree
Hide file tree
Showing 16 changed files with 1,360 additions and 88 deletions.
18 changes: 11 additions & 7 deletions next.config.js → next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { createRequire } from 'node:module';
import dotenv from 'dotenv';
import _withMDX from '@next/mdx';
import { directory } from './src/directory/directory.mjs';
const require = createRequire(import.meta.url);

dotenv.config({ path: './.env.custom' });

// eslint-disable-next-line @typescript-eslint/no-var-requires
const withTM = require('next-transpile-modules')([
'@algolia/autocomplete-shared'
]); // pass the modules you would like to see transpiled
Expand All @@ -7,12 +16,7 @@ const mdxRenderer = `
`;

// eslint-disable-next-line @typescript-eslint/no-var-requires
const directory = require('./src/directory/directory.js');

require('dotenv').config({ path: './.env.custom' });

module.exports = async (phase, { defaultConfig }) => {
export default async (phase, { defaultConfig }) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const headingLinkPlugin = await require('./src/plugins/headings.tsx');
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -26,7 +30,7 @@ module.exports = async (phase, { defaultConfig }) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const frontmatterPlugin = await require('./src/plugins/frontmatter.tsx');

const withMDX = require('@next/mdx')({
const withMDX = _withMDX({
extension: /\.mdx$/,
options: {
remarkPlugins: [
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@algolia/autocomplete-shared": "^1.5.6",
"@algolia/autocomplete-theme-classic": "^1.6.1",
"@algolia/client-search": "^4.13.0",
"@aws-amplify/amplify-cli-core": "^4.0.1",
"@aws-amplify/ui-components": "latest",
"@aws-amplify/ui-react": "^4.4.3",
"@emotion/react": "^11.1.5",
Expand Down Expand Up @@ -98,11 +99,12 @@
"decode-uri-component": "0.2.1"
},
"jest": {
"preset": "ts-jest",
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.(ts|tsx|js)$": [
"^.+\\.(ts|tsx|js|mjs)$": [
"babel-jest",
{
"presets": [
Expand All @@ -123,12 +125,11 @@
"scripts": {
"clean": "rm -rf node_modules yarn.lock",
"refresh": "yarn clean && yarn",
"task": "ts-node tasks",
"test": "jest",
"dev": "next dev",
"spellcheck": "cspell \"src/**/*.mdx\"",
"spellcheck-diff": "git diff --name-only --cached | awk \"/src.*\\.mdx/{print}\" | npx cspell --no-must-find-files --file-list stdin",
"build": "yarn task generate-sitemap && next build && next export -o client/www/next-build",
"build": "node tasks/generate-sitemap.mjs && next build && next export -o client/www/next-build",
"next-build": "next build",
"next-start": "next start",
"amplify:submissionsLambda": "cd amplify/backend/function/submissionsLambda/src && yarn install && yarn build && yarn test",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/Directory/__tests__/Directory.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import Directory from '../index';
import directory from '../../../../directory/directory';
import directory from '../../../../directory/directory.mjs';

describe('Directory', () => {
const directoryKeys = Object.keys(directory);
Expand Down
19 changes: 4 additions & 15 deletions src/components/Menu/Directory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,7 @@ import {
DirectoryLinksStyle,
ProductRootLinkStyle
} from './styles';

export type DirectoryItem = {
/**
* Title used for sidenav link, page title, and page heading
*/
title: string;
/**
* Control whether the title should be displayed as inline code
* @default false
*/
isCodeTitle: boolean;
route: string;
filters: string[];
};
import type { DirectoryItem } from '../../../directory/directory';

export type DirectoryGroupProps = {
title: string;
Expand Down Expand Up @@ -100,7 +87,9 @@ class DirectoryGroup extends React.Component<
>
<InternalLink href={`${item.route}`}>
{item.isCodeTitle ? (
<code>{item.title}</code>
<a>
<code>{item.title}</code>
</a>
) : (
item.title
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/VersionSwitcher/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from "next/link";
import {ActiveSwitchStyle, SwitchStyle} from "./styles";
import directory from "../../../directory/directory";
import directory from "../../../directory/directory.mjs";

const ui = directory["ui"].items;
const uiLegacy = directory["ui-legacy"].items;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/__tests__/Menu.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import Menu from '../index';
import directory from '../../../directory/directory';
import directory from '../../../directory/directory.mjs';

jest.mock('../RepoActions', () => () => <div>Repo Actions</div>);
Object.defineProperty(window, 'matchMedia', {
Expand Down
14 changes: 14 additions & 0 deletions src/data/cli-commands.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type CliCommandFlag = {
short: string;
long: string;
description: string;
};

export type CliCommand = {
name: string;
description: string;
usage: string;
learnMoreLink?: string;
flags: CliCommandFlag[] | [];
subCommands?: CliCommand[];
};
49 changes: 49 additions & 0 deletions src/data/cli-commands.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { commandsInfo } from 'amplify-cli-core/lib/help/commands-info.js';

/**
* Get and transform command data
* @returns {import('./cli-commands').CliCommand[]} Array of commands
*/
export function getCliCommands() {
const result = [];
for (const command of commandsInfo) {
const { subCommands } = command;
result.push({
name: command.command,
description: command.commandDescription,
usage: command.commandUsage,
flags: command.commandFlags.length
? command.commandFlags.map((flag) => ({
short: flag.short,
long: flag.long,
description: flag.flagDescription
}))
: [],
subCommands: subCommands.length
? subCommands
.map((subCommand) => ({
name: subCommand.subCommand,
description: subCommand.subCommandDescription,
usage: subCommand.subCommandUsage,
flags: subCommand.subCommandFlags.length
? subCommand.subCommandFlags.map((flag) => ({
short: flag.short,
long: flag.long,
description: flag.flagDescription
}))
: []
}))
.reduce((acc, subCommand) => {
/** @todo remove this .reduce() after duplicates are removed from the data set */
if (!acc.find((cmd) => cmd.name === subCommand.name)) {
acc.push(subCommand);
}
return acc;
}, [])
: []
});
}
return result;
}

export const commands = getCliCommands();
29 changes: 29 additions & 0 deletions src/directory/directory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export type DirectoryItem = {
/**
* Title used for sidenav link, page title, and page heading
*/
title: string;
filters?: string[];
/**
* Control whether the title should be displayed as inline code
* @default false
*/
isCodeTitle?: boolean;
route: string;
};

export type Directory = {
productRoot: {
title: string;
route: string;
};
items: Record<
string,
{
title: string;
items: DirectoryItem[];
route?: string;
filters?: string[];
}
>;
};
19 changes: 17 additions & 2 deletions src/directory/directory.js → src/directory/directory.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const directory = {
import { commands } from '../data/cli-commands.mjs';

/**
* @type {Record<string, import('./directory').Directory>}
*/
export const directory = {
contribute: {
productRoot: {
title: 'Contribute',
Expand Down Expand Up @@ -1674,6 +1679,16 @@ const directory = {
}
]
},
commands: {
title: 'Commands',
items: commands
.sort((a, b) => ((a.name > b.name ? 1 : -1)))
.map(({ name }) => ({
isCodeTitle: true,
title: name,
route: `/cli/commands/${name}`
}))
},
graphql: {
title: 'API (GraphQL)',
items: [
Expand Down Expand Up @@ -2666,4 +2681,4 @@ const directory = {
}
};

module.exports = directory;
export default directory;
Loading

0 comments on commit ef42cc9

Please sign in to comment.