-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunpack.js
113 lines (98 loc) · 4.09 KB
/
runpack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var packageInfo = require('./package.json');
var commander = require('commander');
var winston = require('winston');
var updateNotifier = require('update-notifier');
var notifier = updateNotifier({
pkg: packageInfo,
updateCheckInterval: 1000 * 60 * 60
});
notifier.notify();
var commandCalled = false;
var logger = winston.createLogger({
format: winston.format.cli(),
transports: [
new winston.transports.Console()
]
});
function commandWrapper(commandName) {
return function (params) {
var command = require('./lib/commands/' + commandName);
commandCalled = true;
if (commander.verbose) {
process.env.RUNPACK_VERBOSE = 'TRUE';
logger.transports[0].level = 'verbose';
}
logger.verbose('Verbose mode enabled');
if (params.env) {
logger.verbose('Environment:', params.env);
}
logger.verbose('Running command:', commandName);
return command.apply(this, [params].concat(logger));
};
}
commander
.version(packageInfo.version)
.option('-v, --verbose', 'Enable verbose mode');
var proxyRoots = [];
function proxyRootList(proxyRoot) {
proxyRoots.push(proxyRoot);
return proxyRoots;
}
commander
.command('server')
.alias('s')
.description('Run development server')
.option('-p, --port <port>', 'Port for development server')
.option('-i, --input <entry>', 'Path to entrypoint, index.js or main.js by default')
.option('--ssl', 'Enable HTTPS')
.option('-e --env <environment>', 'Specify environment, dev or prod', /^(dev|prod)$/i, 'dev')
.option('--proxy <url>', 'Proxy all unresolved requests to the given url')
.option('--proxy-root <url>', 'Base url for proxied requests (mandatory for html history API)', proxyRootList)
.option('-t --test', 'Run tests in watch mode alongside the server')
.option('--favicon <path>', 'Path to favicon')
.option('--cheap-sourcemap', 'Enable cheap sourcemaps, faster builds but less precise sourcemaps')
.option('--hot', 'Enable basic support for hot module replacement')
.option('--hot-react', 'Enable hot module replacement with react support')
.option('-a, --analyze', 'Analyze the bundle and write result in report.html')
.option('--disable-host-check', 'Disable webpack dev server host check to access your site from another host')
.action(commandWrapper('server'));
commander
.command('build')
.alias('b')
.description('Create production files')
.option('-i, --input <entry>', 'Path to entrypoint, index.js or main.js by default')
.option('-o, --output <dir>', 'Directory where to output production files (default is dist)')
.option('-e --env <environment>', 'Specify environment, dev or prod', /^(dev|prod)$/i, 'prod')
.option('--favicon <path>', 'Path to favicon')
.option('-a, --analyze', 'Analyze the bundle and write result in report.html')
.action(commandWrapper('build'));
commander
.command('package')
.alias('p')
.description('Create production package')
.option('-i, --input <entry>', 'Path to entrypoint, index.js or main.js by default')
.option('-t --type [type]', 'Create an archive (zip or tgz), defaults to zip', /^(zip|tgz)$/i, 'zip')
.option('-e --env <environment>', 'Specify environment, dev or prod', /^(dev|prod)$/i, 'prod')
.option('--favicon <path>', 'Path to favicon')
.action(commandWrapper('package'));
commander
.command('test')
.alias('t')
.description('Run unit tests')
.option('-c --coverage', 'Enable coverage')
.option('-r --test-report', 'Output a test result report')
.option('-w --watch', 'Watch for changes and rerun tests')
.action(commandWrapper('test'));
commander
.command('clean')
.description('Remove build files')
.action(commandWrapper('clean'));
commander
.command('eject')
.description('Write configuration files in your project')
.option('--skip-npm-install', 'Do not install npm dependencies')
.action(commandWrapper('eject'));
commander.parse(process.argv);
if (!process.argv.slice(2).length || !commandCalled) {
commander.outputHelp();
}