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

feat(core): cdk init --generate-only #4826

Merged
merged 13 commits into from
Nov 8, 2019
6 changes: 4 additions & 2 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -225,10 +226,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);
Expand Down
13 changes: 8 additions & 5 deletions packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export class Settings {
versionReporting: argv.versionReporting,
staging: argv.staging,
output: argv.output,
generateOnly: argv.generateOnly,
});
}

Expand Down