1 | #!/usr/bin/env node
|
2 | const webpack = require('webpack');
|
3 | const config = require('./webpackConfig');
|
4 | const path = require('path');
|
5 |
|
6 | const defaultName = path.parse(process.cwd()).name + '.js';
|
7 |
|
8 | const argv = require('yargs')
|
9 | .usage('exobot <command> [options]')
|
10 | .example('exobot build', 'uses webpack to build ./src/exobot.js to ./exobot.js')
|
11 | .example('exobot run', 'runs an exobot from ./src/exobot.js')
|
12 | .demand(1)
|
13 | .alias('h', 'help')
|
14 | .help('h')
|
15 | .alias('s', 'source-directory')
|
16 | .nargs('s', 1)
|
17 | .alias('d', 'dest-directory')
|
18 | .nargs('d', 1)
|
19 | .alias('i', 'input')
|
20 | .nargs('i', 1)
|
21 | .alias('o', 'output')
|
22 | .nargs('o', 1)
|
23 | .alias('e', 'extensions')
|
24 | .nargs('e', 1)
|
25 | .alias('c', 'cwd')
|
26 | .nargs('c', 1)
|
27 | .alias('w', 'watch')
|
28 | .nargs('w', 1)
|
29 | .default({
|
30 | 'source-directory': './src',
|
31 | 'dest-directory': './',
|
32 | input: `./src/${defaultName}`,
|
33 | output: defaultName,
|
34 | extensions: '.js,.json',
|
35 | cwd: process.cwd() + '/',
|
36 | watch: false,
|
37 | })
|
38 | .argv;
|
39 |
|
40 | if (argv._[0] === 'build') {
|
41 | const webpackConfig = config(argv);
|
42 |
|
43 | const compiler = webpack(webpackConfig)
|
44 | console.log(`Beginning build from ${argv.cwd}${argv.i}`);
|
45 |
|
46 | compiler.run((err, stats) => {
|
47 | if (err) { return console.error(err); }
|
48 |
|
49 | console.log(`Wrote to ${argv.d}${argv.o}`);
|
50 | process.exit();
|
51 | });
|
52 |
|
53 | }
|