Open ren-yamanashi opened 4 weeks ago
related: #29695
Findings:
stackName
, but this option is not set while invoking cdk init
here.name
and stackName
properties, here.ProjectInfo is used when executing installFiles(). At this code,
name
is used for replacing %name%
placeholder.stackName
is used to replace %stackName%
placeholder.If we look at one of the template files for typescript, it uses %name% placeholder, so related PR https://github.com/aws/aws-cdk/pull/29695 should address this issue (however, also refer https://github.com/aws/aws-cdk/pull/29695#issuecomment-2036299912). So this issue appears to be duplicate of https://github.com/aws/aws-cdk/issues/4865 if PR still holds good.
Findings:
- cdk init uses the execution flow: cliInit() > initializeProject() > InitTemplate.install().
- InitTemplate.install() reads template based on specified language from lib/init-templates directory (list of available templates are read via availableInitTemplates() which is invoked here).
- CliInitOptions supports
stackName
, but this option is not set while invokingcdk init
here.- When InitTemplate.install() is executes, it initializes ProjectInfo which supports
name
andstackName
properties, here.ProjectInfo is used when executing installFiles(). At this code,
name
is used for replacing%name%
placeholder.stackName
is used to replace%stackName%
placeholder.If we look at one of the template files for typescript, it uses %name% placeholder, so related PR feat(cli): --project-name init option #29695 should address this issue (however, also refer feat(cli): --project-name init option #29695 (comment)). So this issue appears to be duplicate of cdk init should have option to produce new project with fixed file and class names #4865 if PR still holds good.
The comment for #29695 mentioned above was made in April. Any update on how we should deal with this issue going forward?
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
name
optionFor example, add
name
to the command options.(see: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/cli.ts#L304-L308)
packages/aws-cdk/lib/init.ts
Add the
name
property toCliInitOptions
and modify theinstall
method as follows (see: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/init.ts)Other Information
No response
Acknowledgements
CDK version used
2.146.0
Environment details (OS name and version, etc.)
macOS Sonoma v14.0