chore: Parallelize build (#5182
* Parallelize build * Update package.json
This commit is contained in:
77
build.js
Executable file
77
build.js
Executable file
@@ -0,0 +1,77 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
/* eslint-disable no-undef */
|
||||
const { exec } = require("child_process");
|
||||
const { readdirSync } = require("fs");
|
||||
|
||||
const getDirectories = (source) =>
|
||||
readdirSync(source, { withFileTypes: true })
|
||||
.filter((dirent) => dirent.isDirectory())
|
||||
.map((dirent) => dirent.name);
|
||||
|
||||
/**
|
||||
* Executes a shell command and return it as a Promise.
|
||||
* @param cmd {string}
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
function execAsync(cmd) {
|
||||
return new Promise((resolve) => {
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
resolve(stdout ? stdout : stderr);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function build() {
|
||||
// Clean previous build
|
||||
console.log("Clean previous build…");
|
||||
|
||||
await Promise.all([
|
||||
execAsync("rm -rf ./build/server"),
|
||||
execAsync("rm -rf ./build/plugins"),
|
||||
]);
|
||||
|
||||
const d = getDirectories("./plugins");
|
||||
|
||||
// Compile server and shared
|
||||
console.log("Compiling…");
|
||||
await Promise.all([
|
||||
execAsync(
|
||||
"yarn babel --extensions .ts,.tsx --quiet -d ./build/server ./server"
|
||||
),
|
||||
execAsync(
|
||||
"yarn babel --extensions .ts,.tsx --quiet -d ./build/shared ./shared"
|
||||
),
|
||||
...d.map(async (plugin) =>
|
||||
execAsync(
|
||||
`yarn babel --extensions .ts,.tsx --quiet -d "./build/plugins/${plugin}/server" "./plugins/${plugin}/server"`
|
||||
)
|
||||
),
|
||||
]);
|
||||
|
||||
// Copy static files
|
||||
console.log("Copying static files…");
|
||||
await Promise.all([
|
||||
execAsync(
|
||||
"cp ./server/collaboration/Procfile ./build/server/collaboration/Procfile"
|
||||
),
|
||||
execAsync(
|
||||
"cp ./server/static/error.dev.html ./build/server/error.dev.html"
|
||||
),
|
||||
execAsync(
|
||||
"cp ./server/static/error.prod.html ./build/server/error.prod.html"
|
||||
),
|
||||
execAsync("cp package.json ./build"),
|
||||
...d.map(async (plugin) =>
|
||||
execAsync(
|
||||
`cp ./plugins/${plugin}/plugin.json ./build/plugins/${plugin}/plugin.json`
|
||||
)
|
||||
),
|
||||
]);
|
||||
|
||||
console.log("Done!");
|
||||
}
|
||||
|
||||
build();
|
||||
Reference in New Issue
Block a user