Skip to content

feat(cli): user-provided cdk init templates #673

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rohang9000
Copy link
Contributor

@rohang9000 rohang9000 commented Jun 30, 2025

Updated functionality allows CDK CLI users to pass in custom templates written in any CDK supported language from local directories, Git repositories, or NPM packages as parameters to the "cdk init" command.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team June 30, 2025 16:28
@github-actions github-actions bot added the p2 label Jun 30, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 3? Let's have descriptive names if we're going to commit these template examples.

return tempDir;
} catch (e) {
// Clean up on error
await fs.remove(tempDir).catch(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why empty catch block here?

init-fixed.ts Outdated

// Auto-detect language if not specified
if (!language && template.languages.length === 1) {
language = template.languages[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember you mentioning we need to specify language, so autodetect can be removed?

3. Validate it contains required `typescript/` directory and `info.json`
4. Use that specific template instead of root directory

### 5. Error Handling
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to specify here. How the error is handled should be evident to the user when they attempt to use the CLI.

@rohang9000 rohang9000 changed the title Initial Code Review from Ian - code still needs to be cleaned before actual PR into main is approved feat(cli): user-provided cdk init templates Jul 2, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this file

`No --language was provided, but '${type}' supports only '${language}', so defaulting to --language=${language}`,
try {
// BRANCH 1: Git Repository Template Source
if (options.gitUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The new options should be gated with the unstable feature protection. For example:

if (!configuration.settings.get(['unstable']).includes('refactor')) {
throw new ToolkitError('Unstable feature use: \'refactor\' is unstable. It must be opted in via \'--unstable\', e.g. \'cdk refactor --unstable=refactor\'');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants