diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 97864cd79f503..23ebee1d93265 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -70,7 +70,8 @@ async function parseCommandLineArguments() { .command('metadata [STACK]', 'Returns all metadata associated with this stack') .command('init [TEMPLATE]', 'Create a new, empty CDK project from a template. Invoked without TEMPLATE, the app template will be used.', yargs => 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: initTemplateLanuages }) - .option('list', { type: 'boolean', desc: 'List the available templates' })) + .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'})) .commandDir('../lib/commands', { exclude: /^_.*/ }) .version(version.DISPLAY_VERSION) .demandCommand(1, '') // just print help @@ -100,6 +101,7 @@ async function initCommandLine() { proxyAddress: argv.proxy, ec2creds: argv.ec2creds, }); + const configuration = new Configuration(argv); await configuration.load(); @@ -225,10 +227,11 @@ async function initCommandLine() { case 'init': const language = configuration.settings.get(['language']); + const generateOnly = configuration.settings.get(['generate-only']); if (args.list) { return await printAvailableTemplates(language); } else { - return await cliInit(args.TEMPLATE, language); + return await cliInit(args.TEMPLATE, language, undefined, generateOnly); } case 'version': return print(version.DISPLAY_VERSION); diff --git a/packages/aws-cdk/lib/init.ts b/packages/aws-cdk/lib/init.ts index 23d0df997bca2..55fbbec4d140f 100644 --- a/packages/aws-cdk/lib/init.ts +++ b/packages/aws-cdk/lib/init.ts @@ -18,7 +18,7 @@ const CDK_HOME = process.env.CDK_HOME ? path.resolve(process.env.CDK_HOME) : pat /** * Initialize a CDK package in the current directory */ -export async function cliInit(type?: string, language?: string, canUseNetwork?: boolean) { +export async function cliInit(type?: string, language?: string, canUseNetwork = true, generateOnly = false) { if (!type && !language) { await printAvailableTemplates(); return; @@ -39,7 +39,8 @@ export async function cliInit(type?: string, language?: string, canUseNetwork?: print(`Available languages for ${colors.green(type)}: ${template.languages.map(l => colors.blue(l)).join(', ')}`); throw new Error('No language was selected'); } - await initializeProject(template, language, canUseNetwork !== undefined ? canUseNetwork : true); + + await initializeProject(template, language, canUseNetwork, generateOnly); } /** @@ -211,12 +212,14 @@ export async function printAvailableTemplates(language?: string) { } } -async function initializeProject(template: InitTemplate, language: string, canUseNetwork: boolean) { +async function initializeProject(template: InitTemplate, language: string, canUseNetwork: boolean, generateOnly: boolean) { await assertIsEmptyDirectory(); print(`Applying project template ${colors.green(template.name)} for ${colors.blue(language)}`); await template.install(language, process.cwd()); - await initializeGitRepository(); - await postInstall(language, canUseNetwork); + if (!generateOnly) { + await initializeGitRepository(); + await postInstall(language, canUseNetwork); + } if (await fs.pathExists('README.md')) { print(colors.green(await fs.readFile('README.md', { encoding: 'utf-8' }))); } else { diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 13bb5b83a9b7c..a6cf22d2b2e15 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -233,6 +233,7 @@ export class Settings { versionReporting: argv.versionReporting, staging: argv.staging, output: argv.output, + generateOnly: argv.generateOnly, }); }