-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
executable file
·64 lines (58 loc) · 1.9 KB
/
Copy pathrun.js
File metadata and controls
executable file
·64 lines (58 loc) · 1.9 KB
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
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable no-console */
'use strict';
const figures = require('figures');
const chalk = require('chalk');
const StackUtils = require('stack-utils');
const loadEnv = require('./lib/load-env');
const cli = require('./cli');
const runDev = require('./run-dev');
const runBuild = require('./run-build');
// const runLint = require('./run-lint');
loadEnv(process.env.NODE_ENV);
const catchErrors = (fn) => (...args) => fn(...args).catch((error) => {
const stackUtils = new StackUtils({
cwd: process.cwd(),
internals: StackUtils.nodeInternals()
})
const stack = stackUtils.clean(error.stack)
// Log task specific errors. These are task specific errors like invald params passed or invalid data sent.
// or log generic errors tiggered by 3rd party non task specific code.
if (error.isAppError && error.errorType === 'task') {
console.error(`\n${chalk.red(figures.cross)} ${chalk.bgRedBright(`There was a task error`)}`);
console.error(error);
console.error(`\n${chalk.red(stack)}`);
} else {
console.error(`\n${chalk.red(figures.cross)} ${chalk.bgRedBright(`There was an error`)}`);
console.error(error);
console.error(`\n${chalk.red(stack)}`);
}
// Exit process if we are in `release` mode so that the build pipelie fails hard with a proper exit code.
if (cli.flags.release) {
process.exitCode = 1;
}
});
/**
* CLI commands switchboard
*/
switch (cli.input[0]) {
case 'dev':
catchErrors(runDev)({
isDebug: !cli.flags.release,
nodeInspect: cli.flags.inspect,
logLevel: cli.flags.verbose
});
break;
case 'build':
catchErrors(runBuild)({ isDebug: !cli.flags.release, logLevel: cli.flags.verbose });
break;
case 'lint':
// catchErrors(runLint)();
break;
case 'version':
console.log('{version.number}');
break;
default:
catchErrors(runBuild)({ isDebug: !cli.flags.release, logLevel: cli.flags.verbose });
break;
}