-
-
Notifications
You must be signed in to change notification settings - Fork 634
/
build-all.js
68 lines (58 loc) · 2.03 KB
/
build-all.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
const chalk = require('chalk');
const Table = require('cli-table');
const { existsSync, openSync, readdirSync, statSync } = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const os = require('os');
const fixtureDirs = readdirSync(__dirname).filter((file) => statSync(path.join(__dirname, file)).isDirectory());
const table = new Table({
head: [chalk.gray.yellow('Fixture'), chalk.gray.yellow('Environment'), chalk.gray.yellow('Passed'), chalk.gray.yellow('Message')]
});
function addResult(tool, environment, result) {
table.push([
chalk.white.bold(tool),
chalk.white.bold(environment),
result.passed ? chalk.green.bold('Passed') : chalk.red.bold('Failed'),
result.message === void 0 ? '' : chalk.white(result.message)
]);
}
function buildFixture(tool, environment) {
const isWindows = os.type().includes('Windows');
// Let console know what's going on
console.log(`Running ${tool}:${environment}`);
// setup options
const opts = {
cwd: path.join(__dirname, tool, environment),
stdio: ['pipe', 'pipe', 'inherit']
};
// Run an NPM install
const install_result = spawnSync(isWindows ? 'npm.cmd' : 'npm', ['install'], opts);
if (install_result.status !== 0 || install_result.error || install_result.stderr) {
return {
passed: false,
message: install_result.error || install_result.stderr
};
}
// Run the test
const test_result = spawnSync(isWindows ? 'npm.cmd' : 'npm', ['run', 'build'], opts);
if (test_result.status !== 0 || test_result.error || test_result.stderr) {
return {
passed: false,
message: test_result.error || test_result.stderr
};
}
return {
passed: true
};
}
for (const dir of fixtureDirs) {
const devPath = path.join(__dirname, dir, 'dev');
if (existsSync(devPath)) {
addResult(dir, 'dev', buildFixture(dir, 'dev'));
}
const prodPath = path.join(__dirname, dir, 'prod');
if (existsSync(prodPath)) {
addResult(dir, 'prod', buildFixture(dir, 'prod'));
}
}
console.log(table.toString());