Skip to content

feat: add Amplify CLI command reference #4950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f15c79d
feat: add Amplify CLI command reference
josefaidt Dec 14, 2022
a95cc6d
Merge remote-tracking branch 'upstream/main' into feat/cli-command-re…
josefaidt Dec 23, 2022
b5f2b80
Merge remote-tracking branch 'upstream/main' into feat/cli-command-re…
josefaidt Jan 6, 2023
6124dc1
chore: migrate next.config, directory to ESM. enables reading cli com…
josefaidt Jan 11, 2023
6cd2c21
chore: add amplify-cli-core as a dependency
josefaidt Jan 11, 2023
f65dda3
fix: inline code block sidenav link
josefaidt Jan 11, 2023
82bf2bc
migrate away from 'tasks' cmd, mjs tasks
josefaidt Feb 3, 2023
6301d3d
jest to transform mjs
josefaidt Feb 3, 2023
ef98745
directory import to use mjs extension, correct expected error message
josefaidt Feb 3, 2023
c76303f
revert error message correction due to different node versions
josefaidt Feb 3, 2023
7233f2e
Merge remote-tracking branch 'upstream/main' into feat/cli-command-re…
josefaidt Feb 3, 2023
48e67e4
update lockfile
josefaidt Feb 3, 2023
fabb695
fix subcommand descriptions, remove usage subsections
josefaidt Feb 20, 2023
42bbc15
pin amplify-cli-core version
josefaidt Feb 20, 2023
581cfe7
add types, fix usage of table captions
josefaidt Feb 24, 2023
cf263eb
patch duplicate subcommands from dataset
josefaidt Feb 24, 2023
67c698a
Merge remote-tracking branch 'upstream/main' into feat/cli-command-re…
josefaidt Feb 24, 2023
0c21728
update lockfile from main
josefaidt Feb 24, 2023
54deabd
Merge remote-tracking branch 'upstream/main' into feat/cli-command-re…
josefaidt Mar 27, 2023
d960509
use scoped package, update to 4+
josefaidt Mar 27, 2023
d23cc3b
Merge remote-tracking branch 'upstream/main' into feat/cli-command-re…
josefaidt Mar 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2",
"@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
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will a test fail / build break if this object gets messed up? Or will the docs just silently get messed up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh that's a good question. If this is changed in the CLI the docs site will not build. Ideally if we automate this on updates to amplify-cli-core the PR associated with the version bump and lockfile updates will fail


/**
* 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