2023-04-11 22:15:52 -04:00
|
|
|
/* eslint-disable no-console */
|
2023-04-10 23:32:04 -04:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
|
|
/* eslint-disable no-undef */
|
|
|
|
const { exec } = require("child_process");
|
2023-06-28 21:57:34 -04:00
|
|
|
const { readdirSync, existsSync } = require("fs");
|
2023-04-10 23:32:04 -04:00
|
|
|
|
|
|
|
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) {
|
2024-08-15 20:48:56 -04:00
|
|
|
return new Promise((resolve, reject) => {
|
2023-04-10 23:32:04 -04:00
|
|
|
exec(cmd, (error, stdout, stderr) => {
|
|
|
|
if (error) {
|
2024-08-15 20:48:56 -04:00
|
|
|
reject(error);
|
|
|
|
} else {
|
|
|
|
resolve(stdout ? stdout : stderr);
|
2023-04-10 23:32:04 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
),
|
2023-06-28 21:57:34 -04:00
|
|
|
...d.map(async (plugin) => {
|
|
|
|
const hasServer = existsSync(`./plugins/${plugin}/server`);
|
|
|
|
|
|
|
|
if (hasServer) {
|
|
|
|
await execAsync(
|
|
|
|
`yarn babel --extensions .ts,.tsx --quiet -d "./build/plugins/${plugin}/server" "./plugins/${plugin}/server"`
|
|
|
|
);
|
|
|
|
}
|
2024-02-29 11:41:03 +05:30
|
|
|
|
|
|
|
const hasShared = existsSync(`./plugins/${plugin}/shared`);
|
|
|
|
|
|
|
|
if (hasShared) {
|
|
|
|
await execAsync(
|
|
|
|
`yarn babel --extensions .ts,.tsx --quiet -d "./build/plugins/${plugin}/shared" "./plugins/${plugin}/shared"`
|
|
|
|
);
|
|
|
|
}
|
2023-06-28 21:57:34 -04:00
|
|
|
}),
|
2023-04-10 23:32:04 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
// 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(
|
2024-03-08 21:32:05 -07:00
|
|
|
`mkdir -p ./build/plugins/${plugin} && cp ./plugins/${plugin}/plugin.json ./build/plugins/${plugin}/plugin.json 2>/dev/null || :`
|
2023-04-10 23:32:04 -04:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
|
|
|
|
console.log("Done!");
|
|
|
|
}
|
|
|
|
|
2023-06-28 21:57:34 -04:00
|
|
|
void build();
|