Skip to content
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

cdk: add option to specify projectName to cdk init #31992

Open
1 of 2 tasks
ren-yamanashi opened this issue Nov 2, 2024 · 3 comments
Open
1 of 2 tasks

cdk: add option to specify projectName to cdk init #31992

ren-yamanashi opened this issue Nov 2, 2024 · 3 comments
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@ren-yamanashi
Copy link
Contributor

ren-yamanashi commented Nov 2, 2024

Describe the feature

When running cdk init, I want to pass projectName as a command option.

Use Case

I'm always frustrated when I have to manually change the stack name and file names generated by cdk init.
This could be resolved by making a projectName option available.

Proposed Solution

I think the steps for possible implementation are as follows

  1. Add name option

For example, add name to the command options.
(see: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/cli.ts#L304-L308)

    .command('init [TEMPLATE]', 'Create a new, empty CDK project from a template.', (yargs: Argv) => yargs
      .option('language', { type: 'string', alias: 'l', desc: 'The language to be used for the new project (default can be configured in ~/.cdk.json)', choices: initTemplateLanguages })
+    .option('name', { type: 'string', alias: 'n', desc: 'The name of new project' })
      .option('list', { type: 'boolean', desc: 'List the available templates' })
      .option('generate-only', { type: 'boolean', default: false, desc: 'If true, only generates project files, without executing additional operations such as setting up a git repo, installing dependencies or compiling the project' }),
    )
  1. Modify the implementation of packages/aws-cdk/lib/init.ts

Add the name property to CliInitOptions and modify the install method as follows
(see: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/init.ts)

-  public async install(language: string, targetDirectory: string, stackName?: string) {
+  public async install(language: string, targetDirectory: string, name?:string, stackName?: string) {
  // ... some implementations
    const projectInfo: ProjectInfo = {
-     name: decamelize(path.basename(path.resolve(targetDirectory))),
+     name: decamelize(name ?? path.basename(path.resolve(targetDirectory))),
      stackName,
    };
  // ... some implementations
  }

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.146.0

Environment details (OS name and version, etc.)

macOS Sonoma v14.0

@ren-yamanashi ren-yamanashi added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 2, 2024
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Nov 2, 2024
@ren-yamanashi ren-yamanashi changed the title cdk: add option to specify templateName to cdk init cdk: add option to specify projectName to cdk init Nov 2, 2024
@tmokmss
Copy link
Contributor

tmokmss commented Nov 4, 2024

related: #29695

@ashishdhingra ashishdhingra self-assigned this Nov 4, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 4, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Nov 4, 2024

Findings:

@ashishdhingra ashishdhingra added effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 4, 2024
@ashishdhingra ashishdhingra removed their assignment Nov 4, 2024
@megarach0
Copy link

Findings:

The comment for #29695 mentioned above was made in April. Any update on how we should deal with this issue going forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

4 participants