This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
forked from folio-org/stripes-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stripes.js
executable file
·67 lines (58 loc) · 1.93 KB
/
stripes.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
#!/usr/bin/env node
/* eslint-disable no-console */
const commander = require('commander');
const path = require('path');
const stripes = require('./webpack/stripes-node-api');
const packageJSON = require('./package.json');
commander.version(packageJSON.version);
// Display error to the console and exit
function processError(err) {
if (err) {
console.error(err);
}
process.exit(1);
}
// Display webpack output to the console
function processStats(stats) {
console.log(stats.toString({
chunks: false,
colors: true,
}));
// Check for webpack compile errors and exit
if (stats.hasErrors()) {
processError();
}
}
commander
.command('dev')
.option('--port [port]', 'Port')
.option('--host [host]', 'Host')
.option('--cache', 'Use HardSourceWebpackPlugin cache')
.option('--devtool [devtool]', 'Use another value for devtool instead of "inline-source-map"')
.arguments('<config>')
.description('Launch a webpack-dev-server')
.action((stripesConfigFile, options) => {
// eslint-disable-next-line global-require,import/no-dynamic-require
const stripesConfig = require(path.resolve(stripesConfigFile));
stripes.serve(stripesConfig, options);
});
commander
.command('build')
.option('--publicPath [publicPath]', 'publicPath')
.option('--sourcemap', 'include sourcemaps in build')
.option('--no-minify', 'do not minify JavaScript')
.arguments('<config> <output>')
.description('Build a tenant bundle')
.action((stripesConfigFile, outputPath, options) => {
// eslint-disable-next-line global-require,import/no-dynamic-require
const stripesConfig = require(path.resolve(stripesConfigFile));
options.outputPath = outputPath;
stripes.build(stripesConfig, options)
.then(stats => processStats(stats))
.catch(err => processError(err));
});
commander.parse(process.argv);
// output help if no command specified
if (!process.argv.slice(2).length) {
commander.outputHelp();
}