Skip to content

Commit cabd4d1

Browse files
committed
refactor/simplify run invoc;
- reorder build command
1 parent 8b75589 commit cabd4d1

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"bin": "dist/cli.js",
88
"scripts": {
99
"build": "npm run -s build:babel && npm run -s build:self",
10-
"build:babel": "babel-node --presets env src/cli.js --external all --format cjs src/*.js",
10+
"build:babel": "babel-node src/cli.js --external all --format cjs src/*.js --presets env",
1111
"build:self": "node dist/cli.js --external all --format cjs src/*.js",
1212
"prepare": "npm run -s build",
1313
"prepare:babel": "babel --presets env src/*.js -d dist && npm t",

src/cli.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ import microbundle from '.';
66
let { version } = require('../package');
77
let prog = sade('microbundle');
88

9+
let toArray = val => Array.isArray(val) ? val : val == null ? [] : [val];
10+
911
prog
1012
.version(version)
11-
.option('--cwd', 'Use an alternative working directory', '.')
1213
.option('--entry, -i', 'Entry module(s)')
1314
.option('--output, -o', 'Directory to place build files into')
1415
.option('--format, -f', 'Only build specified formats', 'es,cjs,umd')
1516
.option('--external', `Specify external dependencies, or 'all'`)
1617
.option('--compress', 'Compress output using UglifyJS', true)
1718
.option('--strict', 'Enforce undefined global context and add "use strict"')
18-
.option('--name', 'Specify name exposed in UMD builds');
19+
.option('--name', 'Specify name exposed in UMD builds')
20+
.option('--cwd', 'Use an alternative working directory', '.');
1921

2022
prog
21-
.command('build [entries]', '', { default: true })
23+
.command('build [...entries]', '', { default:true })
2224
.describe('Build once and exit')
2325
.action(run);
2426

2527
prog
26-
.command('watch [entries]')
28+
.command('watch [...entries]')
2729
.describe('Rebuilds on any change')
28-
.action(opts => run(opts, true));
30+
.action((str, opts) => run(str, opts, true));
2931

3032
// Parse argv; add extra aliases
3133
prog.parse(process.argv, {
@@ -35,15 +37,13 @@ prog.parse(process.argv, {
3537
}
3638
});
3739

38-
function run(options, watch) {
39-
options.entries = options._;
40-
options.watch = watch===true;
41-
microbundle(options)
40+
function run(str, opts, isWatch) {
41+
opts.watch = !!isWatch;
42+
opts.entries = toArray(str || opts.entry).concat(opts._);
43+
microbundle(opts)
4244
.then( output => {
4345
if (output!=null) process.stdout.write(output + '\n');
44-
if (!watch) {
45-
process.exit(0);
46-
}
46+
if (!opts.watch) process.exit(0);
4747
})
4848
.catch(err => {
4949
process.stderr.write(String(err) + '\n');

0 commit comments

Comments
 (0)