Skip to content

Commit 903dda3

Browse files
committed
replace yargs with sade
1 parent 93206c3 commit 903dda3

3 files changed

Lines changed: 30 additions & 57 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"rollup-plugin-preserve-shebang": "^0.1.3",
5555
"rollup-plugin-sizes": "^0.4.2",
5656
"rollup-plugin-uglify": "^2.0.1",
57-
"yargs": "^10.0.3"
57+
"sade": "^1.0.0"
5858
},
5959
"devDependencies": {
6060
"babel-cli": "^6.26.0",

src/cli.js

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,36 @@
11
#!/usr/bin/env node
22

3-
import yargs from 'yargs';
3+
import sade from 'sade';
44
import microbundle from '.';
55

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);
5731

5832
function run(options, watch) {
33+
options.entries = options._;
5934
options.watch = watch===true;
6035
microbundle(options)
6136
.then( output => {

src/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ const isDir = name => stat(name).then( stats => stats.isDirectory() ).catch( ()
2424
const isFile = name => stat(name).then( stats => stats.isFile() ).catch( () => false );
2525
const safeVariableName = name => camelCase(name.toLowerCase().replace(/((^[^a-zA-Z]+)|[^\w.-])|([^a-zA-Z0-9]+$)/g, ''));
2626

27-
const FORMATS = ['es', 'cjs', 'umd'];
28-
2927
const WATCH_OPTS = {
3028
exclude: 'node_modules/**'
3129
};
3230

3331
export default async function microbundle(options) {
34-
let cwd = options.cwd = resolve(process.cwd(), options.cwd || '.');
32+
let cwd = options.cwd = resolve(process.cwd(), options.cwd);
3533

3634
try {
3735
options.pkg = JSON.parse(await readFile(resolve(cwd, 'package.json'), 'utf8'));
@@ -71,7 +69,7 @@ export default async function microbundle(options) {
7169

7270
options.multipleEntries = entries.length>1;
7371

74-
let formats = [].concat(options.format || options.formats || FORMATS);
72+
let formats = (options.format || options.formats).split(',');
7573

7674
let steps = [];
7775
for (let i=0; i<entries.length; i++) {

0 commit comments

Comments
 (0)