From a8ad62c02ab83017af20e4b348ca301ead9aa0d4 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:23:44 -0500 Subject: [PATCH] chore(cli): rename cli-args-gen into user-input-gen (#32821) This PR does not change CLI functionality because we are not using `CliArguments` yet. This PR includes the following related changes: - `CliArguments` are renamed `UserInput` to reflect what the schema represents -- they are options available to be specified via CLI options or `cdk.json`. - the tool previously known as `cli-arg-gen` is now named `user-input-gen` to reflect this change. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- aws-cdk.code-workspace | 2 +- lerna.json | 2 +- package.json | 2 +- packages/aws-cdk/CONTRIBUTING.md | 8 ++-- packages/aws-cdk/jest.config.js | 4 +- packages/aws-cdk/lib/config.ts | 9 +++-- ...o-cli-args.ts => convert-to-user-input.ts} | 14 +++---- .../lib/{cli-arguments.ts => user-input.ts} | 4 +- packages/aws-cdk/package.json | 6 +-- packages/aws-cdk/scripts/cli-args-gen | 2 - packages/aws-cdk/scripts/cli-args-gen.ts | 15 -------- packages/aws-cdk/scripts/user-input-gen | 2 + packages/aws-cdk/scripts/user-input-gen.ts | 16 ++++++++ packages/aws-cdk/test/cli-arguments.test.ts | 10 ++--- tools/@aws-cdk/cli-args-gen/lib/index.ts | 4 -- .../.eslintrc.js | 0 .../.gitignore | 0 .../.npmignore | 0 .../{cli-args-gen => user-input-gen}/LICENSE | 0 .../{cli-args-gen => user-input-gen}/NOTICE | 0 .../README.md | 8 ++-- .../jest.config.js | 0 .../lib/convert-to-user-input-gen.ts} | 37 +++++++++---------- tools/@aws-cdk/user-input-gen/lib/index.ts | 4 ++ .../lib/user-input-gen.ts} | 14 +++---- .../lib/util.ts | 0 .../lib/yargs-gen.ts | 0 .../lib/yargs-types.ts | 0 .../package.json | 6 +-- .../test/convert-to-user-input-gen.test.ts} | 18 ++++----- .../test/user-input-gen.test.ts} | 22 +++++------ .../test/yargs-gen.test.ts | 0 .../tsconfig.json | 0 33 files changed, 106 insertions(+), 103 deletions(-) rename packages/aws-cdk/lib/{convert-to-cli-args.ts => convert-to-user-input.ts} (97%) rename packages/aws-cdk/lib/{cli-arguments.ts => user-input.ts} (99%) delete mode 100755 packages/aws-cdk/scripts/cli-args-gen delete mode 100644 packages/aws-cdk/scripts/cli-args-gen.ts create mode 100755 packages/aws-cdk/scripts/user-input-gen create mode 100644 packages/aws-cdk/scripts/user-input-gen.ts delete mode 100644 tools/@aws-cdk/cli-args-gen/lib/index.ts rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/.eslintrc.js (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/.gitignore (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/.npmignore (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/LICENSE (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/NOTICE (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/README.md (76%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/jest.config.js (100%) rename tools/@aws-cdk/{cli-args-gen/lib/cli-args-function-gen.ts => user-input-gen/lib/convert-to-user-input-gen.ts} (85%) create mode 100644 tools/@aws-cdk/user-input-gen/lib/index.ts rename tools/@aws-cdk/{cli-args-gen/lib/cli-args-gen.ts => user-input-gen/lib/user-input-gen.ts} (93%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/lib/util.ts (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/lib/yargs-gen.ts (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/lib/yargs-types.ts (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/package.json (90%) rename tools/@aws-cdk/{cli-args-gen/test/cli-args-function-gen.test.ts => user-input-gen/test/convert-to-user-input-gen.test.ts} (83%) rename tools/@aws-cdk/{cli-args-gen/test/cli-args-gen.test.ts => user-input-gen/test/user-input-gen.test.ts} (89%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/test/yargs-gen.test.ts (100%) rename tools/@aws-cdk/{cli-args-gen => user-input-gen}/tsconfig.json (100%) diff --git a/aws-cdk.code-workspace b/aws-cdk.code-workspace index a7ebb6636469f..406bc32a95401 100644 --- a/aws-cdk.code-workspace +++ b/aws-cdk.code-workspace @@ -31,7 +31,7 @@ "name": "aws-custom-resource-sdk-adapter", "rootPath": "packages/@aws-cdk/aws-custom-resource-sdk-adapter" }, - { "name": "cli-args-gen", "rootPath": "tools/@aws-cdk/cli-args-gen" } + { "name": "user-input-gen", "rootPath": "tools/@aws-cdk/user-input-gen" } ] }, "extensions": { diff --git a/lerna.json b/lerna.json index c10809593a0e4..05a0f3ac14fb5 100644 --- a/lerna.json +++ b/lerna.json @@ -10,7 +10,7 @@ "packages/@aws-cdk-testing/*", "packages/@aws-cdk/*/lambda-packages/*", "tools/@aws-cdk/cdk-build-tools", - "tools/@aws-cdk/cli-args-gen", + "tools/@aws-cdk/user-input-gen", "tools/@aws-cdk/cdk-release", "tools/@aws-cdk/node-bundle", "tools/@aws-cdk/pkglint", diff --git a/package.json b/package.json index 0f3eb7971f811..a75d010d3c217 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "packages/@aws-cdk-testing/*", "packages/@aws-cdk/*/lambda-packages/*", "tools/@aws-cdk/cdk-build-tools", - "tools/@aws-cdk/cli-args-gen", + "tools/@aws-cdk/user-input-gen", "tools/@aws-cdk/cdk-release", "tools/@aws-cdk/node-bundle", "tools/@aws-cdk/pkglint", diff --git a/packages/aws-cdk/CONTRIBUTING.md b/packages/aws-cdk/CONTRIBUTING.md index 7619772294894..f3c967f03c9e4 100644 --- a/packages/aws-cdk/CONTRIBUTING.md +++ b/packages/aws-cdk/CONTRIBUTING.md @@ -1,21 +1,21 @@ ## CLI Commands All CDK CLI Commands are defined in `lib/config.ts`. This file is translated -into a valid `yargs` configuration by `bin/cli-args-gen`, which is generated by `@aws-cdk/cli-args-gen`. +into a valid `yargs` configuration by `bin/user-input-gen`, which is generated by `@aws-cdk/user-input-gen`. The `yargs` configuration is generated into the function `parseCommandLineArguments()`, in `lib/parse-command-line-arguments.ts`, and is checked into git for readability and inspectability; do not edit this file by hand, as every subsequent `yarn build` will overwrite any manual edits. If you need to leverage a `yargs` feature not used by -the CLI, you must add support for it to `@aws-cdk/cli-args-gen`. +the CLI, you must add support for it to `@aws-cdk/user-input-gen`. -Note that `bin/cli-args-gen` is executed by `ts-node`, which allows `config.ts` to +Note that `bin/user-input-gen` is executed by `ts-node`, which allows `config.ts` to reference functions and other identifiers defined in the CLI before the CLI is built. ### Dynamic Values Some values, such as the user's platform, cannot be computed at build time. -Some commands depend on these values, and thus `cli-args-gen` must generate the +Some commands depend on these values, and thus `user-input-gen` must generate the code to compute these values at build time. The only way to do this today is to reference a parameter with `DynamicValue.fromParameter`. diff --git a/packages/aws-cdk/jest.config.js b/packages/aws-cdk/jest.config.js index f82ca932d08a3..23f1a71b38590 100644 --- a/packages/aws-cdk/jest.config.js +++ b/packages/aws-cdk/jest.config.js @@ -19,8 +19,8 @@ const config = { "/lib/api/aws-auth/sdk.ts", // Files generated by cli-args-gen "/lib/parse-command-line-arguments.ts", - "/lib/cli-arguments.ts", - "/lib/convert-to-cli-args.ts", + "/lib/user-input.ts", + "/lib/convert-to-user-input.ts", ], // We have many tests here that commonly time out diff --git a/packages/aws-cdk/lib/config.ts b/packages/aws-cdk/lib/config.ts index 5e881733a3606..13898df29fa7a 100644 --- a/packages/aws-cdk/lib/config.ts +++ b/packages/aws-cdk/lib/config.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-extraneous-dependencies -import { CliHelpers, type CliConfig } from '@aws-cdk/cli-args-gen'; +import { CliHelpers, type CliConfig } from '@aws-cdk/user-input-gen'; import { StackActivityProgress } from './api/util/cloudformation/stack-activity-monitor'; import { MIGRATE_SUPPORTED_LANGUAGES } from './commands/migrate'; import { RequireApproval } from './diff'; @@ -8,8 +8,11 @@ import { availableInitLanguages } from './init'; export const YARGS_HELPERS = new CliHelpers('./util/yargs-helpers'); /** - * Source of truth for all CDK CLI commands. `cli-args-gen` translates this into the `yargs` definition - * in `lib/parse-command-line-arguments.ts`. + * Source of truth for all CDK CLI commands. `user-input-gen` translates this into: + * + * - the `yargs` definition in `lib/parse-command-line-arguments.ts`. + * - the `UserInput` type in `lib/user-input.ts`. + * - the `convertXxxToUserInput` functions in `lib/convert-to-user-input.ts`. */ export async function makeConfig(): Promise { return { diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-user-input.ts similarity index 97% rename from packages/aws-cdk/lib/convert-to-cli-args.ts rename to packages/aws-cdk/lib/convert-to-user-input.ts index 9b742c8b0f303..de07f9b3c0eef 100644 --- a/packages/aws-cdk/lib/convert-to-cli-args.ts +++ b/packages/aws-cdk/lib/convert-to-user-input.ts @@ -3,11 +3,11 @@ // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ -import { CliArguments, GlobalOptions } from './cli-arguments'; import { Command } from './settings'; +import { UserInput, GlobalOptions } from './user-input'; // @ts-ignore TS6133 -export function convertYargsToCliArgs(args: any): CliArguments { +export function convertYargsToUserInput(args: any): UserInput { const globalOptions: GlobalOptions = { app: args.app, build: args.build, @@ -250,17 +250,17 @@ export function convertYargsToCliArgs(args: any): CliArguments { commandOptions = {}; break; } - const cliArguments: CliArguments = { + const userInput: UserInput = { _: args._[0], globalOptions, [args._[0]]: commandOptions, }; - return cliArguments; + return userInput; } // @ts-ignore TS6133 -export function convertConfigToCliArgs(config: any): CliArguments { +export function convertConfigToUserInput(config: any): UserInput { const globalOptions: GlobalOptions = { app: config.app, build: config.build, @@ -428,7 +428,7 @@ export function convertConfigToCliArgs(config: any): CliArguments { browser: config.docs?.browser, }; const doctorOptions = {}; - const cliArguments: CliArguments = { + const userInput: UserInput = { globalOptions, list: listOptions, synthesize: synthesizeOptions, @@ -450,5 +450,5 @@ export function convertConfigToCliArgs(config: any): CliArguments { doctor: doctorOptions, }; - return cliArguments; + return userInput; } diff --git a/packages/aws-cdk/lib/cli-arguments.ts b/packages/aws-cdk/lib/user-input.ts similarity index 99% rename from packages/aws-cdk/lib/cli-arguments.ts rename to packages/aws-cdk/lib/user-input.ts index f67451c73176a..13ae60938f6ff 100644 --- a/packages/aws-cdk/lib/cli-arguments.ts +++ b/packages/aws-cdk/lib/user-input.ts @@ -6,11 +6,11 @@ import { Command } from './settings'; /** - * The structure of the CLI configuration, generated from packages/aws-cdk/lib/config.ts + * The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts * * @struct */ -export interface CliArguments { +export interface UserInput { /** * The CLI command name */ diff --git a/packages/aws-cdk/package.json b/packages/aws-cdk/package.json index 609be4d5af8fa..e77fbb90d7ea2 100644 --- a/packages/aws-cdk/package.json +++ b/packages/aws-cdk/package.json @@ -7,7 +7,7 @@ }, "scripts": { "build": "cdk-build", - "cli-args-gen": "ts-node --preferTsExts scripts/cli-args-gen.ts", + "user-input-gen": "ts-node --preferTsExts scripts/user-input-gen.ts", "watch": "cdk-watch", "lint": "cdk-lint", "pkglint": "pkglint -f", @@ -29,7 +29,7 @@ }, "cdk-build": { "pre": [ - "yarn cli-args-gen" + "yarn user-input-gen" ], "post": [ "cp ../../node_modules/cdk-from-cfn/index_bg.wasm ./lib/", @@ -70,7 +70,7 @@ "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/cli-plugin-contract": "0.0.0", "@aws-cdk/pkglint": "0.0.0", - "@aws-cdk/cli-args-gen": "0.0.0", + "@aws-cdk/user-input-gen": "0.0.0", "@octokit/rest": "^18.12.0", "@types/archiver": "^5.3.4", "@types/fs-extra": "^9.0.13", diff --git a/packages/aws-cdk/scripts/cli-args-gen b/packages/aws-cdk/scripts/cli-args-gen deleted file mode 100755 index 29484fb39cf9f..0000000000000 --- a/packages/aws-cdk/scripts/cli-args-gen +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -require('./cli-args-gen.js'); diff --git a/packages/aws-cdk/scripts/cli-args-gen.ts b/packages/aws-cdk/scripts/cli-args-gen.ts deleted file mode 100644 index 68d53eeff0597..0000000000000 --- a/packages/aws-cdk/scripts/cli-args-gen.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as fs from 'fs'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { renderYargs, renderCliArgsType, renderCliArgsFunc } from '@aws-cdk/cli-args-gen'; -import { makeConfig, YARGS_HELPERS } from '../lib/config'; - -async function main() { - fs.writeFileSync('./lib/parse-command-line-arguments.ts', await renderYargs(await makeConfig(), YARGS_HELPERS)); - fs.writeFileSync('./lib/cli-arguments.ts', await renderCliArgsType(await makeConfig())); - fs.writeFileSync('./lib/convert-to-cli-args.ts', await renderCliArgsFunc(await makeConfig())); -} - -main().then(() => { -}).catch((e) => { - throw e; -}); diff --git a/packages/aws-cdk/scripts/user-input-gen b/packages/aws-cdk/scripts/user-input-gen new file mode 100755 index 0000000000000..8e9fe2a7c9bfc --- /dev/null +++ b/packages/aws-cdk/scripts/user-input-gen @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('./user-input-gen.js'); diff --git a/packages/aws-cdk/scripts/user-input-gen.ts b/packages/aws-cdk/scripts/user-input-gen.ts new file mode 100644 index 0000000000000..3ef7e03204165 --- /dev/null +++ b/packages/aws-cdk/scripts/user-input-gen.ts @@ -0,0 +1,16 @@ +import * as fs from 'fs'; +// eslint-disable-next-line import/no-extraneous-dependencies +import { renderYargs, renderUserInputType, renderUserInputFuncs } from '@aws-cdk/user-input-gen'; +import { makeConfig, YARGS_HELPERS } from '../lib/config'; + +async function main() { + const config = await makeConfig(); + fs.writeFileSync('./lib/parse-command-line-arguments.ts', await renderYargs(config, YARGS_HELPERS)); + fs.writeFileSync('./lib/user-input.ts', await renderUserInputType(config)); + fs.writeFileSync('./lib/convert-to-user-input.ts', await renderUserInputFuncs(config)); +} + +main().then(() => { +}).catch((e) => { + throw e; +}); diff --git a/packages/aws-cdk/test/cli-arguments.test.ts b/packages/aws-cdk/test/cli-arguments.test.ts index ddcf9d02b6fb3..32ad80da77e84 100644 --- a/packages/aws-cdk/test/cli-arguments.test.ts +++ b/packages/aws-cdk/test/cli-arguments.test.ts @@ -1,11 +1,11 @@ -import { convertConfigToCliArgs, convertYargsToCliArgs } from '../lib/convert-to-cli-args'; +import { convertConfigToUserInput, convertYargsToUserInput } from '../lib/convert-to-user-input'; import { parseCommandLineArguments } from '../lib/parse-command-line-arguments'; describe('yargs', () => { test('yargs object can be converted to cli arguments', async () => { const input = await parseCommandLineArguments(['deploy', '-R', '-v', '--ci']); - const result = convertYargsToCliArgs(input); + const result = convertYargsToUserInput(input); expect(result).toEqual({ _: 'deploy', @@ -70,7 +70,7 @@ describe('yargs', () => { test('positional argument is correctly passed through -- variadic', async () => { const input = await parseCommandLineArguments(['deploy', 'stack1', 'stack2', '-R', '-v', '--ci']); - const result = convertYargsToCliArgs(input); + const result = convertYargsToUserInput(input); expect(result).toEqual({ _: 'deploy', @@ -84,7 +84,7 @@ describe('yargs', () => { test('positional argument is correctly passed through -- single', async () => { const input = await parseCommandLineArguments(['acknowledge', 'id1', '-v', '--ci']); - const result = convertYargsToCliArgs(input); + const result = convertYargsToUserInput(input); expect(result).toEqual({ _: 'acknowledge', @@ -109,7 +109,7 @@ describe('config', () => { }, }; - const result = convertConfigToCliArgs(input); + const result = convertConfigToUserInput(input); expect(result).toEqual({ globalOptions: expect.objectContaining({ diff --git a/tools/@aws-cdk/cli-args-gen/lib/index.ts b/tools/@aws-cdk/cli-args-gen/lib/index.ts deleted file mode 100644 index 6dfee4beeac38..0000000000000 --- a/tools/@aws-cdk/cli-args-gen/lib/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './yargs-gen'; -export * from './yargs-types'; -export * from './cli-args-gen'; -export * from './cli-args-function-gen'; diff --git a/tools/@aws-cdk/cli-args-gen/.eslintrc.js b/tools/@aws-cdk/user-input-gen/.eslintrc.js similarity index 100% rename from tools/@aws-cdk/cli-args-gen/.eslintrc.js rename to tools/@aws-cdk/user-input-gen/.eslintrc.js diff --git a/tools/@aws-cdk/cli-args-gen/.gitignore b/tools/@aws-cdk/user-input-gen/.gitignore similarity index 100% rename from tools/@aws-cdk/cli-args-gen/.gitignore rename to tools/@aws-cdk/user-input-gen/.gitignore diff --git a/tools/@aws-cdk/cli-args-gen/.npmignore b/tools/@aws-cdk/user-input-gen/.npmignore similarity index 100% rename from tools/@aws-cdk/cli-args-gen/.npmignore rename to tools/@aws-cdk/user-input-gen/.npmignore diff --git a/tools/@aws-cdk/cli-args-gen/LICENSE b/tools/@aws-cdk/user-input-gen/LICENSE similarity index 100% rename from tools/@aws-cdk/cli-args-gen/LICENSE rename to tools/@aws-cdk/user-input-gen/LICENSE diff --git a/tools/@aws-cdk/cli-args-gen/NOTICE b/tools/@aws-cdk/user-input-gen/NOTICE similarity index 100% rename from tools/@aws-cdk/cli-args-gen/NOTICE rename to tools/@aws-cdk/user-input-gen/NOTICE diff --git a/tools/@aws-cdk/cli-args-gen/README.md b/tools/@aws-cdk/user-input-gen/README.md similarity index 76% rename from tools/@aws-cdk/cli-args-gen/README.md rename to tools/@aws-cdk/user-input-gen/README.md index 8915e8d8de23b..1bf6701f61e4d 100644 --- a/tools/@aws-cdk/cli-args-gen/README.md +++ b/tools/@aws-cdk/user-input-gen/README.md @@ -1,16 +1,16 @@ -# cli-args-gen +# user-input-gen Generates CDK CLI configurations from the source of truth in `packages/aws-cdk/lib/config.ts`. Currently generates the following files: - `packages/aws-cdk/lib/parse-command-line-arguments.ts`: `yargs` config. -- `packages/aws-cdk-lib/cli-arguments.ts`: strongly typed `CliArguments` interface. -- `packages/aws-cdk-lib/convert-to-cli-args.ts`: converts the `any` returned by `yargs` to `CliArguments`. +- `packages/aws-cdk/lib/user-input.ts`: strongly typed `UserInput` interface. +- `packages/aws-cdk/lib/convert-to-user-inpu.ts`: converts input from the CLI or `cdk.json` into `UserInput`. ## Usage ```ts -import { renderYargs } from '@aws-cdk/cli-args-gen'; +import { renderYargs } from '@aws-cdk/user-input-gen'; declare const config: CliConfig; diff --git a/tools/@aws-cdk/cli-args-gen/jest.config.js b/tools/@aws-cdk/user-input-gen/jest.config.js similarity index 100% rename from tools/@aws-cdk/cli-args-gen/jest.config.js rename to tools/@aws-cdk/user-input-gen/jest.config.js diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts b/tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts similarity index 85% rename from tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts rename to tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts index ffe1d947abed4..1ea751e15afeb 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts +++ b/tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts @@ -7,7 +7,7 @@ import { CliAction, CliConfig } from './yargs-types'; const CLI_ARG_NAME = 'args'; const CONFIG_ARG_NAME = 'config'; -export async function renderCliArgsFunc(config: CliConfig): Promise { +export async function renderUserInputFuncs(config: CliConfig): Promise { const scope = new Module('aws-cdk'); scope.documentation.push( '-------------------------------------------------------------------------------------------'); @@ -15,25 +15,24 @@ export async function renderCliArgsFunc(config: CliConfig): Promise { scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); - scope.addImport(new SelectiveModuleImport(scope, './cli-arguments', ['CliArguments', 'GlobalOptions'])); - const cliArgType = Type.fromName(scope, 'CliArguments'); - scope.addImport(new SelectiveModuleImport(scope, './settings', ['Command'])); + scope.addImport(new SelectiveModuleImport(scope, './user-input', ['UserInput', 'GlobalOptions'])); + const userInputType = Type.fromName(scope, 'UserInput'); - const createCliArguments = new FreeFunction(scope, { - name: 'convertYargsToCliArgs', + const convertYargsToUserInput = new FreeFunction(scope, { + name: 'convertYargsToUserInput', export: true, - returnType: cliArgType, + returnType: userInputType, parameters: [ { name: 'args', type: Type.ANY }, ], }); - createCliArguments.addBody(code.expr.directCode(buildCliArgsFunction(config))); + convertYargsToUserInput.addBody(code.expr.directCode(buildYargsToUserInputFunction(config))); const createConfigArguments = new FreeFunction(scope, { - name: 'convertConfigToCliArgs', + name: 'convertConfigToUserInput', export: true, - returnType: cliArgType, + returnType: userInputType, parameters: [ { name: 'config', type: Type.ANY }, ], @@ -52,14 +51,14 @@ export async function renderCliArgsFunc(config: CliConfig): Promise { }); } -function buildCliArgsFunction(config: CliConfig): string { +function buildYargsToUserInputFunction(config: CliConfig): string { const globalOptions = buildGlobalOptions(config, CLI_ARG_NAME); const commandSwitch = buildCommandSwitch(config, CLI_ARG_NAME); - const cliArgs = buildCliArgs(CLI_ARG_NAME); + const userInput = buildUserInput(CLI_ARG_NAME); return [ globalOptions, commandSwitch, - cliArgs, + userInput, ].join('\n'); } @@ -85,7 +84,7 @@ function buildGlobalOptions(config: CliConfig, argName: string): string { } function buildCommandsList(config: CliConfig, argName: string): string { - const commandOptions = []; + const commandOptions: string[] = []; // Note: we are intentionally not including aliases for the default options that can be // specified via `cdk.json`. These options must be specified by the command name // i.e. acknowledge rather than ack. @@ -140,27 +139,27 @@ function buildPositionalArguments(arg: { name: string; variadic: boolean }, argN return `${arg.name}: ${argName}.${arg.name}`; } -function buildCliArgs(argName: string): string { +function buildUserInput(argName: string): string { return [ - 'const cliArguments: CliArguments = {', + 'const userInput: UserInput = {', `_: ${argName}._[0],`, 'globalOptions,', `[${argName}._[0]]: commandOptions`, '}', '', - 'return cliArguments', + 'return userInput', ].join('\n'); } function buildConfigArgs(config: CliConfig): string { return [ - 'const cliArguments: CliArguments = {', + 'const userInput: UserInput = {', 'globalOptions,', ...(Object.keys(config.commands).map((commandName) => { return `'${commandName}': ${kebabToCamelCase(commandName)}Options,`; })), '}', '', - 'return cliArguments', + 'return userInput', ].join('\n'); } diff --git a/tools/@aws-cdk/user-input-gen/lib/index.ts b/tools/@aws-cdk/user-input-gen/lib/index.ts new file mode 100644 index 0000000000000..be47e3278f75e --- /dev/null +++ b/tools/@aws-cdk/user-input-gen/lib/index.ts @@ -0,0 +1,4 @@ +export * from './yargs-gen'; +export * from './yargs-types'; +export * from './user-input-gen'; +export * from './convert-to-user-input-gen'; diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts b/tools/@aws-cdk/user-input-gen/lib/user-input-gen.ts similarity index 93% rename from tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts rename to tools/@aws-cdk/user-input-gen/lib/user-input-gen.ts index b8be1e8a636a6..1d39585fb0692 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts +++ b/tools/@aws-cdk/user-input-gen/lib/user-input-gen.ts @@ -4,7 +4,7 @@ import * as prettier from 'prettier'; import { generateDefault, kebabToCamelCase, kebabToPascal } from './util'; import { CliConfig } from './yargs-types'; -export async function renderCliArgsType(config: CliConfig): Promise { +export async function renderUserInputType(config: CliConfig): Promise { const scope = new Module('aws-cdk'); scope.documentation.push( '-------------------------------------------------------------------------------------------'); @@ -12,11 +12,11 @@ export async function renderCliArgsType(config: CliConfig): Promise { scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); - const cliArgType = new StructType(scope, { + const userInputType = new StructType(scope, { export: true, - name: 'CliArguments', + name: 'UserInput', docs: { - summary: 'The structure of the CLI configuration, generated from packages/aws-cdk/lib/config.ts', + summary: 'The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts', }, }); @@ -24,7 +24,7 @@ export async function renderCliArgsType(config: CliConfig): Promise { scope.addImport(new SelectiveModuleImport(scope, './settings', ['Command'])); const commandEnum = Type.fromName(scope, 'Command'); - cliArgType.addProperty({ + userInputType.addProperty({ name: '_', type: commandEnum, docs: { @@ -54,7 +54,7 @@ export async function renderCliArgsType(config: CliConfig): Promise { }); } - cliArgType.addProperty({ + userInputType.addProperty({ name: 'globalOptions', type: Type.fromName(scope, globalOptionType.name), docs: { @@ -102,7 +102,7 @@ export async function renderCliArgsType(config: CliConfig): Promise { }); } - cliArgType.addProperty({ + userInputType.addProperty({ name: kebabToCamelCase(commandName), type: Type.fromName(scope, commandType.name), docs: { diff --git a/tools/@aws-cdk/cli-args-gen/lib/util.ts b/tools/@aws-cdk/user-input-gen/lib/util.ts similarity index 100% rename from tools/@aws-cdk/cli-args-gen/lib/util.ts rename to tools/@aws-cdk/user-input-gen/lib/util.ts diff --git a/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts b/tools/@aws-cdk/user-input-gen/lib/yargs-gen.ts similarity index 100% rename from tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts rename to tools/@aws-cdk/user-input-gen/lib/yargs-gen.ts diff --git a/tools/@aws-cdk/cli-args-gen/lib/yargs-types.ts b/tools/@aws-cdk/user-input-gen/lib/yargs-types.ts similarity index 100% rename from tools/@aws-cdk/cli-args-gen/lib/yargs-types.ts rename to tools/@aws-cdk/user-input-gen/lib/yargs-types.ts diff --git a/tools/@aws-cdk/cli-args-gen/package.json b/tools/@aws-cdk/user-input-gen/package.json similarity index 90% rename from tools/@aws-cdk/cli-args-gen/package.json rename to tools/@aws-cdk/user-input-gen/package.json index 29a15729acc0c..53444e58fbfac 100644 --- a/tools/@aws-cdk/cli-args-gen/package.json +++ b/tools/@aws-cdk/user-input-gen/package.json @@ -1,12 +1,12 @@ { - "name": "@aws-cdk/cli-args-gen", + "name": "@aws-cdk/user-input-gen", "private": true, "version": "0.0.0", - "description": "Generate CLI arguments", + "description": "Generate User Inputs", "repository": { "type": "git", "url": "https://github.com/aws/aws-cdk.git", - "directory": "tools/@aws-cdk/cli-args-gen" + "directory": "tools/@aws-cdk/user-input-gen" }, "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts b/tools/@aws-cdk/user-input-gen/test/convert-to-user-input-gen.test.ts similarity index 83% rename from tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts rename to tools/@aws-cdk/user-input-gen/test/convert-to-user-input-gen.test.ts index 0ea58ff8fde91..427213e09f37d 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts +++ b/tools/@aws-cdk/user-input-gen/test/convert-to-user-input-gen.test.ts @@ -1,4 +1,4 @@ -import { CliConfig, renderCliArgsFunc } from '../lib'; +import { CliConfig, renderUserInputFuncs } from '../lib'; describe('render', () => { test('can generate conversion function', async () => { @@ -43,17 +43,17 @@ describe('render', () => { }, }; - expect(await renderCliArgsFunc(config)).toMatchInlineSnapshot(` + expect(await renderUserInputFuncs(config)).toMatchInlineSnapshot(` "// ------------------------------------------------------------------------------------------- // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ - import { CliArguments, GlobalOptions } from './cli-arguments'; import { Command } from './settings'; + import { UserInput, GlobalOptions } from './user-input'; // @ts-ignore TS6133 - export function convertYargsToCliArgs(args: any): CliArguments { + export function convertYargsToUserInput(args: any): UserInput { const globalOptions: GlobalOptions = { app: args.app, debug: args.debug, @@ -70,17 +70,17 @@ describe('render', () => { }; break; } - const cliArguments: CliArguments = { + const userInput: UserInput = { _: args._[0], globalOptions, [args._[0]]: commandOptions, }; - return cliArguments; + return userInput; } // @ts-ignore TS6133 - export function convertConfigToCliArgs(config: any): CliArguments { + export function convertConfigToUserInput(config: any): UserInput { const globalOptions: GlobalOptions = { app: config.app, debug: config.debug, @@ -90,12 +90,12 @@ describe('render', () => { const deployOptions = { all: config.deploy?.all, }; - const cliArguments: CliArguments = { + const userInput: UserInput = { globalOptions, deploy: deployOptions, }; - return cliArguments; + return userInput; } " `); diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts b/tools/@aws-cdk/user-input-gen/test/user-input-gen.test.ts similarity index 89% rename from tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts rename to tools/@aws-cdk/user-input-gen/test/user-input-gen.test.ts index 3e1fa8e69305a..0fa06bc261492 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts +++ b/tools/@aws-cdk/user-input-gen/test/user-input-gen.test.ts @@ -1,7 +1,7 @@ -import { CliConfig, renderCliArgsType } from '../lib'; +import { CliConfig, renderUserInputType } from '../lib'; describe('render', () => { - test('can generate CliArguments type', async () => { + test('can generate UserInput type', async () => { const config: CliConfig = { globalOptions: { app: { @@ -43,7 +43,7 @@ describe('render', () => { }, }; - expect(await renderCliArgsType(config)).toMatchInlineSnapshot(` + expect(await renderUserInputType(config)).toMatchInlineSnapshot(` "// ------------------------------------------------------------------------------------------- // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. @@ -52,11 +52,11 @@ describe('render', () => { import { Command } from './settings'; /** - * The structure of the CLI configuration, generated from packages/aws-cdk/lib/config.ts + * The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts * * @struct */ - export interface CliArguments { + export interface UserInput { /** * The CLI command name */ @@ -152,7 +152,7 @@ describe('render', () => { globalOptions: {}, }; - expect(await renderCliArgsType(config)).toMatchInlineSnapshot(` + expect(await renderUserInputType(config)).toMatchInlineSnapshot(` "// ------------------------------------------------------------------------------------------- // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. @@ -161,11 +161,11 @@ describe('render', () => { import { Command } from './settings'; /** - * The structure of the CLI configuration, generated from packages/aws-cdk/lib/config.ts + * The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts * * @struct */ - export interface CliArguments { + export interface UserInput { /** * The CLI command name */ @@ -234,7 +234,7 @@ describe('render', () => { globalOptions: {}, }; - expect(await renderCliArgsType(config)).toMatchInlineSnapshot(` + expect(await renderUserInputType(config)).toMatchInlineSnapshot(` "// ------------------------------------------------------------------------------------------- // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. @@ -243,11 +243,11 @@ describe('render', () => { import { Command } from './settings'; /** - * The structure of the CLI configuration, generated from packages/aws-cdk/lib/config.ts + * The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts * * @struct */ - export interface CliArguments { + export interface UserInput { /** * The CLI command name */ diff --git a/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts b/tools/@aws-cdk/user-input-gen/test/yargs-gen.test.ts similarity index 100% rename from tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts rename to tools/@aws-cdk/user-input-gen/test/yargs-gen.test.ts diff --git a/tools/@aws-cdk/cli-args-gen/tsconfig.json b/tools/@aws-cdk/user-input-gen/tsconfig.json similarity index 100% rename from tools/@aws-cdk/cli-args-gen/tsconfig.json rename to tools/@aws-cdk/user-input-gen/tsconfig.json