|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -import yargs from 'yargs'; |
| 3 | +import sade from 'sade'; |
4 | 4 | import microbundle from '.'; |
5 | 5 |
|
6 | | -yargs |
7 | | - .option('entry', { |
8 | | - type: 'string', |
9 | | - alias: ['i', 'e', 'entries'], |
10 | | - description: 'Entry module(s)', |
11 | | - defaultDescription: '<package.module>' |
12 | | - }) |
13 | | - .option('output', { |
14 | | - type: 'string', |
15 | | - alias: ['o', 'd'], |
16 | | - description: 'Directory to place build files into', |
17 | | - defaultDescription: '<dirname(package.main), build/>' |
18 | | - }) |
19 | | - .option('cwd', { |
20 | | - type: 'string', |
21 | | - description: 'Use an alternative working directory', |
22 | | - defaultDescription: '.' |
23 | | - }) |
24 | | - .option('format', { |
25 | | - type: 'string', |
26 | | - alias: 'f', |
27 | | - description: 'Only build specified formats', |
28 | | - defaultDescription: 'es,cjs,umd' |
29 | | - }) |
30 | | - .option('compress', { |
31 | | - type: 'boolean', |
32 | | - description: 'Compress output using UglifyJS', |
33 | | - default: true |
34 | | - }) |
35 | | - .option('strict', { |
36 | | - description: 'Enforce undefined global context and add "use strict"', |
37 | | - default: false |
38 | | - }) |
39 | | - .option('name', { |
40 | | - description: 'Specify name exposed in UMD builds', |
41 | | - default: false |
42 | | - }) |
43 | | - .command( |
44 | | - ['build [entries..]', '$0 [entries..]'], |
45 | | - 'Build once and exit', |
46 | | - () => {}, |
47 | | - argv => run(argv, false) |
48 | | - ) |
49 | | - .command( |
50 | | - 'watch [entries..]', |
51 | | - 'Rebuilds on any change', |
52 | | - () => {}, |
53 | | - argv => run(argv, true) |
54 | | - ) |
55 | | - .help() |
56 | | - .argv; |
| 6 | +let { version } = require('../package'); |
| 7 | +let prog = sade('microbundle'); |
| 8 | + |
| 9 | +prog |
| 10 | + .version(version) |
| 11 | + .option('--cwd', 'Use an alternative working directory', '.') |
| 12 | + .option('--entry, -i', 'Entry module(s)') |
| 13 | + .option('--output, -o', 'Directory to place build files into') |
| 14 | + .option('--format, -f', 'Only build specified formats', 'es,cjs,umd') |
| 15 | + .option('--external', `Specify external dependencies, or 'all'`) |
| 16 | + .option('--compress', 'Compress output using UglifyJS', true) |
| 17 | + .option('--strict', 'Enforce undefined global context and add "use strict"') |
| 18 | + .option('--name', 'Specify name exposed in UMD builds'); |
| 19 | + |
| 20 | +prog |
| 21 | + .command('build [entries]', '', { default: true }) |
| 22 | + .describe('Build once and exit') |
| 23 | + .action(run); |
| 24 | + |
| 25 | +prog |
| 26 | + .command('watch [entries]') |
| 27 | + .describe('Rebuilds on any change') |
| 28 | + .action(opts => run(opts, true)); |
| 29 | + |
| 30 | +prog.parse(process.argv); |
57 | 31 |
|
58 | 32 | function run(options, watch) { |
| 33 | + options.entries = options._; |
59 | 34 | options.watch = watch===true; |
60 | 35 | microbundle(options) |
61 | 36 | .then( output => { |
|
0 commit comments