-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
86 lines (78 loc) · 2.98 KB
/
script.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
let spawn = require('child_process').spawn;
let rimraf = require("rimraf");
let fs = require("fs");
//command will be the first argument
let command = process.argv[2];
//args will be the array of arguments after the commands
let args = process.argv.slice(3).map(s => s.substr(2) === "--" ? s.substr(1) : s).filter(s => s !== '-w' && s !== '-watch');
//This is a boolean as to whether --watch or -w been in the commands
let watch = process.argv.map(s => s.substr(2) === "--" ? s.substr(1) : s).filter(s => s === '-w' || s === "-watch").length > 0;
Execute(command, args, watch).then();
//The decision on what command to execute base on the arguments and whether watch exists
async function Execute(command, args, watch) {
let full = args.filter(s => s === "--full").length > 0;
switch (command) {
case "wp":
let wp = `webpack --config ./config/webpack.${args[0]}.ts`;
if (watch) wp += " --watch";
await run(wp);
break;
case "deploy":
await run("node script e2e");
await run("node script wp dist");
break;
case "e2e":
await run("node script wp e2e");
let headless = [
"chrome:headless",
"firefox:headless",
"chrome-canary:headless"
].map(s => `testcafe ${s} ./test/e2e/**/*.test.ts`);
let real = [
"chrome",
"firefox",
"ie",
"opera",
"chrome-canary",
"edge"
].map(s => `testcafe ${s} ./test/e2e/**/*.test.ts`);
let test = headless;
if (full) test = test.concat(real);
await run(test.join(" && "));
break;
case "publish":
await run(`npm run deploy`);
await run(`git add .`);
await run(`git commit -m "Preparing for next ${args[0]} version`);
await run(`npm version ${args[0]}`);
await run(`npm publish`);
break;
default:
console.log("Unknown command!");
process.exit(1);
}
}
//Executes the function as if its on the CMD. Exits the script if the external command crashes.
async function run(command) {
if (!Array.isArray(command) && typeof command === "string") command = command.split(' ');
else throw new Error("command is either a string or a string array");
let c = command.shift();
let v = command;
let env = process.env;
env.BROWSERSLIST_CONFIG= "./config/.browserslistrc";
return new Promise((resolve) => spawn(c, v,
{
stdio: "inherit",
shell: true,
env: env
})
.on("exit", (code, signal) => {
if (fs.existsSync("./.nyc_output")) rimraf.sync("./.nyc_output");
if (code === 0) resolve();
else {
console.log("ExternalError:", signal);
process.exit(1);
}
})
);
}