Skip to content

Commit 0f5fe9a

Browse files
authored
chore: expose node-bundle options via CLI (#32475)
Add two options that were not being exposed via the CLI: - `minifyWhitespace` - Packing `target` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c208789 commit 0f5fe9a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tools/@aws-cdk/node-bundle/src/cli-main.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path';
22
import * as fs from 'fs-extra';
33
import * as yargs from 'yargs';
4-
import { Bundle, BundleProps, BundleValidateOptions } from './api';
4+
import { Bundle, BundlePackOptions, BundleProps, BundleValidateOptions } from './api';
55

66
function versionNumber(): string {
77
return fs.readJSONSync(path.join(__dirname, '..', 'package.json')).version;
@@ -16,11 +16,14 @@ export async function cliMain(cliArgs: string[]) {
1616
.option('resource', { type: 'array', nargs: 1, default: [], desc: 'List of resources that need to be explicitly copied to the bundle (example: node_modules/proxy-agent/contextify.js:bin/contextify.js)' })
1717
.option('dont-attribute', { type: 'string', desc: 'Dependencies matching this regular expressions wont be added to the notice file' })
1818
.option('test', { type: 'string', desc: 'Validation command to sanity test the bundle after its created' })
19+
.option('minify-whitespace', { type: 'boolean', default: false, desc: 'Minify whitespace' })
1920
.command('validate', 'Validate the package is ready for bundling', args => args
2021
.option('fix', { type: 'boolean', default: false, alias: 'f', desc: 'Fix any fixable violations' }),
2122
)
2223
.command('write', 'Write the bundled version of the project to a temp directory')
23-
.command('pack', 'Write the bundle and create the tarball')
24+
.command('pack', 'Write the bundle and create the tarball', args => args
25+
.option('destination', { type: 'string', desc: 'Directory to write the tarball to', nargs: 1, requiresArg: true })
26+
)
2427
.demandCommand() // require a subcommand
2528
.strict() // require a VALID subcommand, and only supported options
2629
.fail((msg, err) => {
@@ -76,6 +79,7 @@ export async function cliMain(cliArgs: string[]) {
7679
resources: resources,
7780
dontAttribute: argv['dont-attribute'],
7881
test: argv.test,
82+
minifyWhitespace: argv['minify-whitespace'],
7983
};
8084

8185
const bundle = new Bundle(props);
@@ -91,7 +95,10 @@ export async function cliMain(cliArgs: string[]) {
9195
write(bundle);
9296
break;
9397
case 'pack':
94-
pack(bundle);
98+
const target = argv.destination as string | undefined;
99+
pack(bundle, {
100+
target,
101+
});
95102
break;
96103
default:
97104
throw new Error(`Unknown command: ${command}`);
@@ -110,6 +117,6 @@ function validate(bundle: Bundle, options: BundleValidateOptions = {}) {
110117
}
111118
}
112119

113-
function pack(bundle: Bundle) {
114-
bundle.pack();
120+
function pack(bundle: Bundle, options?: BundlePackOptions) {
121+
bundle.pack(options);
115122
}

0 commit comments

Comments
 (0)