Skip to content

Commit

Permalink
feat(core): cdk init --generate-only (#4826)
Browse files Browse the repository at this point in the history
* feat(core): yarn global detection

* feat(core): package-manager option

* feat: generate-only, revert previous work

* chore: cleaner canUseNetwork default value

* fix: missing refactor

* chore: update generate-only description

* fix: do not run postInstall if generateOnly

* fix: do not run initializeGitRepository if generateOnly

* fix: add generateOnly to settings list

* trigger a build

* remove trailing whitespace
  • Loading branch information
nmussy authored and mergify[bot] committed Nov 8, 2019
1 parent 652a8f5 commit 9cc1e52
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 5 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 @@ -100,6 +101,7 @@ async function initCommandLine() {
proxyAddress: argv.proxy,
ec2creds: argv.ec2creds,
});

const configuration = new Configuration(argv);
await configuration.load();

Expand Down Expand Up @@ -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);
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

0 comments on commit 9cc1e52

Please sign in to comment.