mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-25 03:33:33 +01:00
⚡ fast build script
This commit is contained in:
parent
7db9086dd0
commit
a78baa048d
37
bundle/scripts/build.js
Normal file
37
bundle/scripts/build.js
Normal file
@ -0,0 +1,37 @@
|
||||
const { spawn } = require("child_process");
|
||||
const path = require("path");
|
||||
const { performance } = require("perf_hooks");
|
||||
|
||||
let parts = "util,api,cdn,gateway,bundle".split(",");
|
||||
|
||||
// because npm run is slow we directly get the build script of the package.json script
|
||||
|
||||
function buildPackage(dir) {
|
||||
const element = path.basename(dir);
|
||||
const swcBin = path.join(dir, "node_modules", "@swc", "cli", "lib", "swc", "index.js");
|
||||
|
||||
const child = spawn("node", `${swcBin} src --out-dir dist --sync`.split(" "), {
|
||||
cwd: dir,
|
||||
env: process.env,
|
||||
shell: true,
|
||||
});
|
||||
function log(data) {
|
||||
console.log(`[${element}]`.padEnd(10, " ") + data.toString().slice(0, -1));
|
||||
}
|
||||
child.stdout.on("data", log);
|
||||
child.stderr.on("data", log);
|
||||
child.on("error", (err) => console.error(element, err));
|
||||
return child;
|
||||
}
|
||||
|
||||
// util needs to be compiled first as the others require it
|
||||
|
||||
const start = performance.now();
|
||||
|
||||
for (const part of parts) {
|
||||
buildPackage(path.join(__dirname, "..", "..", part));
|
||||
}
|
||||
|
||||
process.on("exit", () => {
|
||||
console.log("[Build] took " + Math.round(performance.now() - start) + "ms");
|
||||
});
|
@ -1,18 +0,0 @@
|
||||
const { exec, spawn } = require("child_process");
|
||||
const { exitCode } = require("process");
|
||||
|
||||
let parts = "api,cdn,gateway,util,bundle".split(",");
|
||||
parts.forEach(element => {
|
||||
// exec(`npm --prefix ../${element} run build`, (error, stdout, stderr) => {
|
||||
// if (error) {
|
||||
// console.log(`error: ${error.message}`);
|
||||
// return;
|
||||
// }
|
||||
// if (stderr) {
|
||||
// console.log(`stderr: ${stderr}`);
|
||||
// return;
|
||||
// }
|
||||
// console.log(`stdout: ${stdout}`);
|
||||
// });
|
||||
spawn("npm", ["run", "build"], {cwd: `../${element}`});
|
||||
});
|
Loading…
Reference in New Issue
Block a user