core: change build script to plain javascript

This commit is contained in:
undefined committed 2021-04-16 22:06:07 +08:00
1 parent 6c5532e298
commit b0df7024e6
8 files changed
+27 -59

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */
const globby = require('globby');
const spawn = require('cross-spawn');
const cwd = process.cwd();
function getWorkspaces() {
return globby(require('../package').workspaces, {
cwd,
deep: 0,
onlyDirectories: true,
expandDirectories: false,
});
}
function spawnSync(command: string, silent?: boolean) {
if (!silent) console.log(`$ ${command}`);
const args = command.split(/\s+/);
const result = spawn.sync(args[0], [...args.slice(1), '--color'], { cwd, encoding: 'utf8' });
if (result.status) {
throw new Error(result.stderr);
} else {
if (!silent) console.log(result.stdout);
return result.stdout.trim();
}
}
function spawnAsync(command: string) {
const args = command.split(/\s+/);
const child = spawn(args[0], args.slice(1), { stdio: 'inherit' });
return new Promise((resolve, reject) => {
child.on('close', resolve);
child.on('error', reject);
});
}
module.exports = {
cwd, spawnSync, spawnAsync, getWorkspaces,
};