Skip to content

Commit

Permalink
feat(cli): add --build option (aws#19663)
Browse files Browse the repository at this point in the history
Adds a `--build` option to the CDK CLI so that customers can specify pre-synth build commands without modifying their cdk.json settings. Customers can use this feature to run special build commands during `cdk watch` that cdk should not run during a `cdk synth`.

Fixes aws#19667

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
misterjoshua authored and Stephen Potter committed Apr 27, 2022
1 parent 7a05bc0 commit be4d40c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ Some of the interesting keys that can be used in the JSON configuration files:
```json5
{
"app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js')
"build": "mvn package", // Specify pre-synth build (no command line option)
"build": "mvn package", // Specify pre-synth build (--build='mvn package')
"context": { // Context entries (--context=key=value)
"key": "value"
},
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async function parseCommandLineArguments() {
.env('CDK')
.usage('Usage: cdk -a <cdk-app> COMMAND')
.option('app', { type: 'string', alias: 'a', desc: 'REQUIRED: command-line for executing your app or a cloud assembly directory (e.g. "node bin/my-app.js")', requiresArg: true })
.option('build', { type: 'string', desc: 'Command-line for a pre-synth build' })
.option('context', { type: 'array', alias: 'c', desc: 'Add contextual string parameter (KEY=VALUE)', nargs: 1, requiresArg: true })
.option('plugin', { type: 'array', alias: 'p', desc: 'Name or path of a node package that extend the CDK features. Can be specified multiple times', nargs: 1 })
.option('trace', { type: 'boolean', desc: 'Print trace for stack warnings' })
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 @@ -265,6 +265,7 @@ export class Settings {
return new Settings({
app: argv.app,
browser: argv.browser,
build: argv.build,
context,
debug: argv.debug,
tags,
Expand Down
11 changes: 11 additions & 0 deletions packages/aws-cdk/test/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,14 @@ test('should include outputs-file in settings', () => {
// THEN
expect(settings.get(['outputsFile'])).toEqual('my-outputs-file.json');
});

test('providing a build arg', () => {
// GIVEN
const settings = Settings.fromCommandLineArguments({
_: [Command.SYNTH],
build: 'mvn package',
});

// THEN
expect(settings.get(['build'])).toEqual('mvn package');
});

0 comments on commit be4d40c

Please sign in to comment.