UNPKG

1.18 kBJavaScriptView Raw
1import yargs from 'yargs'
2import {resolve} from 'path'
3import {sync as pkgDir} from 'pkg-dir'
4import {sync as resolveJS} from 'resolve'
5
6export function parse (input) {
7 const argv = yargs
8 .usage('Usage: $0 [options]')
9
10 .example('$0 -i src/app.js -o dist', 'Transpiles the app and its dependencies into the "dist" directory.')
11
12 .alias('i', 'entry')
13 .describe('entry', 'Starting file for the application. Defaults to package.json "main" field.')
14
15 .alias('o', 'destination')
16 .describe('destination', 'Directory to write output. Defaults to "./public". Nonexistent directories are automatically created.')
17
18 .alias('s', 'silent')
19 .boolean('silent')
20 .default('silent', false)
21 .describe('silent', 'Suppress log messages from output')
22
23 .alias('w', 'watch')
24 .boolean('watch')
25 .default('watch', false)
26 .describe('watch', 'Monitor files and rebuild on changes')
27
28 .alias('h', 'help')
29 .help('help')
30
31 .alias('v', 'version')
32 .version()
33
34 .parse(input)
35
36 if (!argv.entry) {
37 argv.entry = resolveJS(pkgDir())
38 }
39
40 if (!argv.destination) {
41 argv.destination = resolve(process.cwd(), 'public')
42 }
43
44 return argv
45}