1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
6 |
|
7 | require('v8-compile-cache');
|
8 |
|
9 | const chalk = require('chalk');
|
10 |
|
11 | const program = require('commander');
|
12 |
|
13 | const version = require('../package.json').version;
|
14 |
|
15 | program.version(version);
|
16 | program.command('serve [input...]').description('starts a development server').option('-p, --port <port>', 'set the port to serve on. defaults to 1234', parseInt).option('--host <host>', 'set the host to listen on, defaults to listening on all interfaces').option('--hmr-port <port>', 'set the port to serve HMR websockets, defaults to random', parseInt).option('--hmr-hostname <hostname>', 'set the hostname of HMR websockets, defaults to location.hostname of current window').option('--https', 'serves files over HTTPS').option('--cert <path>', 'path to certificate to use with HTTPS').option('--key <path>', 'path to private key to use with HTTPS').option('--open [browser]', 'automatically open in specified browser, defaults to default browser').option('-d, --out-dir <path>', 'set the output directory. defaults to "dist"').option('-o, --out-file <filename>', 'set the output filename for the application entry point.').option('--public-url <url>', 'set the public URL to serve on. defaults to "/"').option('--global <variable>', 'expose your module through a global variable').option('--no-hmr', 'disable hot module replacement').option('--no-cache', 'disable the filesystem cache').option('--no-source-maps', 'disable sourcemaps').option('--no-autoinstall', 'disable autoinstall').option('-t, --target [target]', 'set the runtime environment, either "node", "browser" or "electron". defaults to "browser"', /^(node|browser|electron)$/).option('--bundle-node-modules', 'force bundling node modules, even on node/electron target').option('-V, --version', 'output the version number').option('--log-level <level>', 'set the log level, either "0" (no output), "1" (errors), "2" (warnings), "3" (info), "4" (verbose) or "5" (debug, creates a log file).', /^([0-5])$/).option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"').action(bundle);
|
17 | program.command('watch [input...]').description('starts the bundler in watch mode').option('-d, --out-dir <path>', 'set the output directory. defaults to "dist"').option('-o, --out-file <filename>', 'set the output filename for the application entry point.').option('--public-url <url>', 'set the public URL to serve on. defaults to "/"').option('--global <variable>', 'expose your module through a global variable').option('--hmr-port <port>', 'set the port to serve HMR websockets, defaults to random', parseInt).option('--hmr-hostname <hostname>', 'set the hostname of HMR websockets, defaults to location.hostname of current window').option('--https', 'listen on HTTPS for HMR connections').option('--cert <path>', 'path to certificate to use with HTTPS').option('--key <path>', 'path to private key to use with HTTPS').option('--no-hmr', 'disable hot module replacement').option('--no-cache', 'disable the filesystem cache').option('--no-source-maps', 'disable sourcemaps').option('--no-autoinstall', 'disable autoinstall').option('-t, --target [target]', 'set the runtime environment, either "node", "browser" or "electron". defaults to "browser"', /^(node|browser|electron)$/).option('--bundle-node-modules', 'force bundling node modules, even on node/electron target').option('--log-level <level>', 'set the log level, either "0" (no output), "1" (errors), "2" (warnings), "3" (info), "4" (verbose) or "5" (debug, creates a log file).', /^([0-5])$/).option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"').action(bundle);
|
18 | program.command('build [input...]').description('bundles for production').option('-d, --out-dir <path>', 'set the output directory. defaults to "dist"').option('-o, --out-file <filename>', 'set the output filename for the application entry point.').option('--public-url <url>', 'set the public URL to serve on. defaults to "/"').option('--global <variable>', 'expose your module through a global variable').option('--no-minify', 'disable minification').option('--no-cache', 'disable the filesystem cache').option('--no-source-maps', 'disable sourcemaps').option('--no-autoinstall', 'disable autoinstall').option('--no-content-hash', 'disable content hashing').option('--experimental-scope-hoisting', 'enable experimental scope hoisting/tree shaking support').option('-t, --target <target>', 'set the runtime environment, either "node", "browser" or "electron". defaults to "browser"', /^(node|browser|electron)$/).option('--bundle-node-modules', 'force bundling node modules, even on node/electron target').option('--detailed-report [depth]', 'print a detailed build report after a completed build. If enabled, defaults to depth "10"', /^([0-9]+|all)$/).option('--log-level <level>', 'set the log level, either "0" (no output), "1" (errors), "2" (warnings), "3" (info), "4" (verbose) or "5" (debug, creates a log file).', /^([0-5])$/).option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"').action(bundle);
|
19 | program.command('help [command]').description('display help information for a command').action(function (command) {
|
20 | let cmd = program.commands.find(c => c.name() === command) || program;
|
21 | cmd.help();
|
22 | });
|
23 | program.on('--help', function () {
|
24 | console.log('');
|
25 | console.log(' Run `' + chalk.bold('parcel help <command>') + '` for more information on specific commands');
|
26 | console.log('');
|
27 | });
|
28 |
|
29 | var args = process.argv;
|
30 | if (args[2] === '--help' || args[2] === '-h') args[2] = 'help';
|
31 |
|
32 | if (!args[2] || !program.commands.some(c => c.name() === args[2])) {
|
33 | args.splice(2, 0, 'serve');
|
34 | }
|
35 |
|
36 | program.parse(args);
|
37 |
|
38 | function bundle(_x, _x2) {
|
39 | return _bundle.apply(this, arguments);
|
40 | }
|
41 |
|
42 | function _bundle() {
|
43 | _bundle = (0, _asyncToGenerator2.default)(function* (main, command) {
|
44 |
|
45 | const Bundler = require('../');
|
46 |
|
47 | if (command.name() === 'watch') {
|
48 | command.watch = true;
|
49 | }
|
50 |
|
51 | if (command.name() === 'build') {
|
52 | command.production = true;
|
53 | process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
54 | } else {
|
55 | process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
56 | }
|
57 |
|
58 | if (command.cert && command.key) {
|
59 | command.https = {
|
60 | cert: command.cert,
|
61 | key: command.key
|
62 | };
|
63 | }
|
64 |
|
65 | command.throwErrors = false;
|
66 | command.scopeHoist = command.experimentalScopeHoisting || false;
|
67 | const bundler = new Bundler(main, command);
|
68 | command.target = command.target || 'browser';
|
69 |
|
70 | if (command.name() === 'serve' && command.target === 'browser') {
|
71 | const port = command.port || process.env.PORT || 1234;
|
72 | const server = yield bundler.serve(port, command.https, command.host);
|
73 |
|
74 | if (server && command.open) {
|
75 | yield require('./utils/openInBrowser')(`${command.https ? 'https' : 'http'}://${command.host || 'localhost'}:${server.address().port}`, command.open);
|
76 | }
|
77 | } else {
|
78 | bundler.bundle();
|
79 | }
|
80 | });
|
81 | return _bundle.apply(this, arguments);
|
82 | } |
\ | No newline at end of file |