This repository was archived by the owner on May 25, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
114 lines (103 loc) · 2.01 KB
/
Copy pathbuild.js
File metadata and controls
114 lines (103 loc) · 2.01 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
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
114
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
// List of commands to run
const commands = [];
// Parse command line
const compile = {
lib: true,
bundle: true,
style: true,
docs: true,
assets: true,
};
const params = [];
process.argv.slice(2).forEach((cmd) => {
if (cmd.slice(0, 2) !== '--') {
return;
}
const parts = cmd.slice(2).split('-');
if (parts.length === 2) {
// Parse 2 part commands like --with-lib
const key = parts.pop();
if (compile[key] === void 0) {
params.push(cmd);
return;
}
switch (parts.shift()) {
case 'with':
// enable module
compile[key] = true;
break;
case 'without':
// disable module
compile[key] = false;
break;
case 'only':
// disable other modules
Object.keys(compile).forEach((key2) => {
compile[key2] = key2 === key;
});
break;
}
} else {
params.push(cmd);
}
});
// Check file exists
const fileExists = (file) => {
try {
fs.statSync(file);
} catch (e) {
return false;
}
return true;
};
// Run build scripts
Object.keys(compile).forEach((key) => {
if (compile[key]) {
if (fileExists('build-' + key + '.js')) {
// Run build-*
commands.push({
cmd: 'node',
args: ['build-' + key].concat(params),
});
} else {
commands.push({
cmd: 'npm',
args: ['run', 'build:' + key],
});
}
}
});
// Done
const done = () => {
if (params.indexOf('--live') === -1) {
console.log(
'\nDo not commit changes! Documents were generated in development mode.\nTo build production version that should be published, run "npm run build-live"\n'
);
}
};
/**
* Run next command
*/
const next = () => {
const item = commands.shift();
if (item === void 0) {
done();
return;
}
if (item.cwd === void 0) {
item.cwd = __dirname;
}
const result = child_process.spawnSync(item.cmd, item.args, {
cwd: item.cwd,
stdio: 'inherit',
});
if (result.status === 0) {
process.nextTick(next);
} else {
process.exit(result.status);
}
};
next();