Skip to content

Commit eb9b8e2

Browse files
authored
feat(cli): add --build option (#19663)
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 #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*
1 parent 75a6fa7 commit eb9b8e2

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

packages/aws-cdk/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ Some of the interesting keys that can be used in the JSON configuration files:
643643
```json5
644644
{
645645
"app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js')
646-
"build": "mvn package", // Specify pre-synth build (no command line option)
646+
"build": "mvn package", // Specify pre-synth build (--build='mvn package')
647647
"context": { // Context entries (--context=key=value)
648648
"key": "value"
649649
},

packages/aws-cdk/lib/cli.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ async function parseCommandLineArguments() {
5656
.env('CDK')
5757
.usage('Usage: cdk -a <cdk-app> COMMAND')
5858
.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 })
59+
.option('build', { type: 'string', desc: 'Command-line for a pre-synth build' })
5960
.option('context', { type: 'array', alias: 'c', desc: 'Add contextual string parameter (KEY=VALUE)', nargs: 1, requiresArg: true })
6061
.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 })
6162
.option('trace', { type: 'boolean', desc: 'Print trace for stack warnings' })

packages/aws-cdk/lib/settings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export class Settings {
265265
return new Settings({
266266
app: argv.app,
267267
browser: argv.browser,
268+
build: argv.build,
268269
context,
269270
debug: argv.debug,
270271
tags,

packages/aws-cdk/test/settings.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,14 @@ test('should include outputs-file in settings', () => {
144144
// THEN
145145
expect(settings.get(['outputsFile'])).toEqual('my-outputs-file.json');
146146
});
147+
148+
test('providing a build arg', () => {
149+
// GIVEN
150+
const settings = Settings.fromCommandLineArguments({
151+
_: [Command.SYNTH],
152+
build: 'mvn package',
153+
});
154+
155+
// THEN
156+
expect(settings.get(['build'])).toEqual('mvn package');
157+
});

0 commit comments

Comments
 (0)