UNPKG

4.2 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4var tslib_1 = require("tslib");
5var commander_1 = tslib_1.__importDefault(require("commander"));
6var debug_1 = tslib_1.__importDefault(require("debug"));
7var jsox_1 = tslib_1.__importDefault(require("jsox"));
8var pick_1 = tslib_1.__importDefault(require("lodash/pick"));
9var rollup_1 = require("rollup");
10var config_1 = tslib_1.__importDefault(require("./config"));
11var info = debug_1.default('r:info');
12var parseArrayArgs = function (curr, prev) {
13 var next = curr.split(',');
14 return prev ? prev.concat(next) : next;
15};
16commander_1.default
17 // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires
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)', 'auto')
25 .option('-x, --external, --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, --alias-entries <JSOX>', 'entries setting for @rxts/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 // FIXME: should be removed this option and PR to `rollup-plugin-typescript` instead
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('--vue <JSOX>', 'options for `rollup-plugin-vue`', jsox_1.default.parse)
35 // eslint-disable-next-line @typescript-eslint/ban-types
36 .option('-d, --define [boolean | JSOX]', 'options for `rollup-plugin-replace`, enable `__DEV__` and `__PROD__` by default',
37// @ts-ignore
38jsox_1.default.parse, true)
39 .option('--terser <JSOX>', 'options for `rollup-plugin-terser`', jsox_1.default.parse)
40 .option('-p, --prod [boolean]', 'whether to enable production(.min.js) bundle together at the same time')
41 .parse(process.argv);
42var options = pick_1.default(commander_1.default, 'input', 'exclude', 'outputDir', 'formats', 'monorepo', 'exports', 'external', 'externals', 'globals', 'aliasEntries', 'sourceMap', 'typescript', 'postcss', 'vue', 'terser', 'prod');
43info('options: %O', options);
44var startWatcher = function (configs) {
45 var watcher = rollup_1.watch(configs);
46 watcher.on('event', function (event) {
47 switch (event.code) {
48 case 'START':
49 info('🚀 (re)starting...');
50 break;
51 case 'END':
52 info('🎉 bundled successfully.');
53 break;
54 case 'ERROR':
55 console.error(event);
56 break;
57 }
58 });
59};
60var configs = config_1.default(options);
61if (commander_1.default.watch) {
62 startWatcher(configs);
63}
64else {
65 Promise.all(configs.map(function (opts) {
66 return rollup_1.rollup(opts).then(function (bundle) { return bundle.write(opts.output); });
67 })).catch(function (e) {
68 console.error(e);
69 process.exitCode = 1;
70 });
71}
72//# sourceMappingURL=cli.js.map
\No newline at end of file