-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.js
executable file
·47 lines (39 loc) · 1021 Bytes
/
cmd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
const fs = require('fs')
const parseArg = require('minimist')
const picker = require('./')
const argv = parseArg(process.argv.slice(2), {
string: 'output',
alias: { output: 'o' }
})
// Usage:
//
// node d3-geo-projection-picker proj1 proj2 proj3 > file.js
// node d3-geo-projection-picker proj1 proj2 proj3 -o file.js
// node d3-geo-projection-picker proj1 proj2 proj3 --output file.js
//
// pass any of
//
// https://github.com/rollup/rollup/wiki/JavaScript-API#bundlegenerate-options-
//
// as e.g.
//
// node d3-geo-projection-picker proj1 proj2 proj3 --format umd --moduleName d3 > file.js
const opts = {
format: 'cjs',
banner: '/* File auto-generated by d3-geo-projection-picker */\n'
}
Object.keys(argv).forEach((k) => {
if (k === '_' || k === 'o') return
opts[k] = argv[k]
})
picker(argv._, opts, (err, code) => {
if (err) throw err
if (argv.o) {
fs.writeFile(argv.o, code, (err) => {
if (err) throw err
})
} else {
process.stdout.write(code)
}
})