import {
Table,
TableCell,
TableBody,
TableHead,
TableRow
} from '@aws-amplify/ui-react';
import Page from '../../../components/Page';
import { commands } from '../../../data/cli-commands.mjs';
import type { CliCommandFlag, CliCommand } from '../../../data/cli-commands';
/**
* Create SEO metadata for a command
* @TODO restructure command data to remove command.command in favor of command.name
* @param command Amplify CLI command JSON
* @returns
*/
const createCommandMeta = (command: CliCommand) => {
const title = command.name;
const description = command.description;
return {
title,
description
};
};
function CommandPageFlagsTable({ flags }: { flags: CliCommandFlag[] }) {
return (
Flag
Description
{flags.map((flag) => (
{/* {display}
*/}
{flag.short && -{flag.short}|}
--{flag.long}
{flag.description}
))}
);
}
/**
* Page for a single Amplify CLI command. It aims to display:
* - Command name
* - Command description
* - Command usage
* - Command flags and their descriptions
* - Command examples
* - Command subcommands (with the same information as listed above: name, description, usage, flags, examples)
*/
function CommandPage({ meta, command }) {
/**
* Heading to mimic MDX page headings
*/
const CommandPageHeading = ({
anchor,
children,
level,
title
}: {
anchor?: string;
children: any;
level?: number;
title?: string;
}) => {
const createAnchorString = (str) => str.toLowerCase().replace(/ /g, '-');
const Heading = `h${level || 2}` as keyof JSX.IntrinsicElements;
const _anchor = anchor || createAnchorString(title || children);
return (
{children}
);
};
const createSubcommandAnchor = (subcommandName) => {
return `${command.name}-${subcommandName}`;
};
/**
* Heading for subcommands where they will be rendered as the full "amplify" command but we need to have more control over the anchor
*/
const CommandPageSubcommandHeading = ({ children }) => {
return (
{`amplify ${command.name} ${children}`}
);
};
return (
{command.description}
Usage
{command.usage}
{command.flags.length > 0 && (
<>
Flags
>
)}
{command.subCommands.length > 0 && (
<>
Subcommands
Subcommand
Description
{command.subCommands.map((subCommand) => (
{subCommand.name}
{subCommand.description}
))}
{command.subCommands.map((subCommand) => (
{subCommand.name}
{subCommand.description}
{/* @todo fix subcommand usage from cli */}
{/*
Usage
{command.usage}
*/}
{command.subCommands.flags?.length > 0 && (
<>
Flags
>
)}
))}
>
)}
);
}
export function getStaticPaths() {
const paths = commands.map(({ name }) => ({
params: { command: name }
}));
return {
paths,
fallback: false
};
}
export function getStaticProps({ params }) {
const command = commands.find((command) => command.name === params.command);
if (!command) {
throw new Error(`Command not found: ${params.command}`);
}
const meta = createCommandMeta(command);
return {
props: {
meta,
command
}
};
}
export default CommandPage;