2021-09-27 15:47:41 +00:00
|
|
|
/* eslint-disable */
|
2021-07-20 13:50:05 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const child_process = require('child_process');
|
|
|
|
|
|
|
|
// List of commands to run
|
|
|
|
const commands = [];
|
|
|
|
|
|
|
|
// Parse command line
|
|
|
|
const compile = {
|
|
|
|
lib: true,
|
|
|
|
rollup: true,
|
|
|
|
api: true,
|
|
|
|
cleanup: true,
|
|
|
|
};
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check if required modules in same monorepo are available
|
|
|
|
const fileExists = (file) => {
|
|
|
|
try {
|
|
|
|
fs.statSync(file);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-06-29 06:45:30 +00:00
|
|
|
// Compile packages
|
2021-07-20 13:50:05 +00:00
|
|
|
Object.keys(compile).forEach((key) => {
|
2022-06-29 06:45:30 +00:00
|
|
|
if (compile[key]) {
|
2021-07-20 13:50:05 +00:00
|
|
|
commands.push({
|
|
|
|
cmd: 'npm',
|
|
|
|
args: ['run', 'build:' + key],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run next command
|
|
|
|
*/
|
|
|
|
const next = () => {
|
|
|
|
const item = commands.shift();
|
|
|
|
if (item === void 0) {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|