1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | var tslib_1 = require("tslib");
|
5 | var commander_1 = tslib_1.__importDefault(require("commander"));
|
6 | var debug_1 = tslib_1.__importDefault(require("debug"));
|
7 | var jsox_1 = tslib_1.__importDefault(require("jsox"));
|
8 | var pick_1 = tslib_1.__importDefault(require("lodash/pick"));
|
9 | var rollup_1 = require("rollup");
|
10 | var config_1 = tslib_1.__importDefault(require("./config"));
|
11 | var info = debug_1.default('r:info');
|
12 | var parseArrayArgs = function (curr, prev) {
|
13 | var next = curr.split(',');
|
14 | return prev ? prev.concat(next) : next;
|
15 | };
|
16 | commander_1.default
|
17 |
|
18 | .version(require('../package.json').version)
|
19 | .option('-i, --input <filename>', 'input entry file path')
|
20 | .option('--exclude <path>', 'exclude package(s) for monorepo', parseArrayArgs)
|
21 | .option('-o, --output-dir [output]', 'output destination directory')
|
22 | .option('-f, --formats <format>', 'Type of output (amd, cjs, esm, iife, umd, and es versions like es2015)', parseArrayArgs)
|
23 | .option('-m, --monorepo <false | glob | paths>', 'whether try to resolve the project as a monorepo automatically, or custom the packages path', jsox_1.default.parse)
|
24 | .option('-e, --exports <mode>', 'Specify export mode (auto, default, named, none)')
|
25 | .option('-x, --externals <package>', 'extra external packages, peerDependencies, and dependencies for node by default', parseArrayArgs)
|
26 | .option('-g, --globals <JSOX>', 'JSON string to be parsed as umd globals map', jsox_1.default.parse)
|
27 | .option('-a, --aliases <JSOX>', 'entries setting for rollup-plugin-alias, could be array or object', jsox_1.default.parse)
|
28 | .option('-c, --copies <JSOX>', 'targets setting or whole CopyOptions for rollup-plugin-copy, could be array or object', jsox_1.default.parse)
|
29 | .option('-s, --source-map <boolean>', 'whether or not to enable sourceMap generation for CommonJS modules, which may cause performance issue', false)
|
30 | .option('-w, --watch [boolean]', 'whether to enable watch mode for development')
|
31 |
|
32 | .option('-t, --typescript <JSOX>', 'Overrides the TypeScript compiler options for `rollup-plugin-typescript`', jsox_1.default.parse)
|
33 | .option('--postcss <JSOX>', 'options for `rollup-plugin-postcss`', jsox_1.default.parse)
|
34 | .option('-d, --define [boolean | JSOX]', 'options for `rollup-plugin-replace`, enable `__DEV__` and `__PROD__` by default', jsox_1.default.parse, true)
|
35 | .option('-p, --prod [boolean]', 'whether to enable production(.min.js) bundle together at the same time')
|
36 | .parse(process.argv);
|
37 | var options = pick_1.default(commander_1.default, 'input', 'exclude', 'outputDir', 'formats', 'monorepo', 'exports', 'externals', 'globals', 'aliases', 'sourceMap', 'typescript', 'postcss', 'prod');
|
38 | info('options: %O', options);
|
39 | var startWatcher = function (configs) {
|
40 | var watcher = rollup_1.watch(configs);
|
41 | watcher.on('event', function (event) {
|
42 | switch (event.code) {
|
43 | case 'START':
|
44 | info('🚀 (re)starting...');
|
45 | break;
|
46 | case 'END':
|
47 | info('🎉 bundled successfully.');
|
48 | break;
|
49 | case 'ERROR':
|
50 | console.error(event);
|
51 | break;
|
52 | case 'FATAL':
|
53 | console.error(event);
|
54 | watcher.close();
|
55 | break;
|
56 | }
|
57 | });
|
58 | };
|
59 | var configs = config_1.default(options);
|
60 | if (commander_1.default.watch) {
|
61 | startWatcher(configs);
|
62 | }
|
63 | else {
|
64 | Promise.all(configs.map(function (opts) {
|
65 | return rollup_1.rollup(opts).then(function (bundle) { return bundle.write(opts); });
|
66 | })).catch(function (e) {
|
67 | console.error(e);
|
68 | process.exitCode = 1;
|
69 | });
|
70 | }
|
71 |
|
\ | No newline at end of file |