1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-14 22:52:41 +01:00
server/bundle/scripts/build.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-10-10 11:02:25 +02:00
const { execSync } = require("child_process");
2021-10-07 18:21:01 +02:00
const path = require("path");
2021-12-21 11:56:33 +01:00
const fs = require("fs");
2021-10-10 17:55:48 +02:00
const { getSystemErrorMap } = require("util");
const { argv } = require("process");
2021-10-07 18:21:01 +02:00
var steps = 2, i = 0;
if (argv.includes("clean")) steps++;
if (argv.includes("copyonly")) steps--;
2021-10-10 17:55:48 +02:00
const dirs = ["api", "util", "cdn", "gateway", "bundle"];
2021-10-07 18:21:01 +02:00
2021-10-10 17:55:48 +02:00
const verbose = argv.includes("verbose") || argv.includes("v");
2021-10-07 18:21:01 +02:00
2021-12-21 11:56:33 +01:00
var copyRecursiveSync = function(src, dest) {
if(verbose) console.log(`cpsync: ${src} -> ${dest}`);
var exists = fs.existsSync(src);
if(!exists){
console.log(src + " doesn't exist, not copying!");
return;
}
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest, {recursive: true});
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
if (argv.includes("clean")) {
console.log(`[${++i}/${steps}] Cleaning...`);
2021-10-22 09:26:01 +02:00
dirs.forEach((a) => {
var d = "../" + a + "/dist";
2021-12-21 11:56:33 +01:00
if (fs.existsSync(d)) {
fs.rmSync(d, { recursive: true });
2021-10-22 09:26:01 +02:00
if (verbose) console.log(`Deleted ${d}!`);
}
});
2021-10-07 18:21:01 +02:00
}
console.log(`[${++i}/${steps}] Copying src files...`);
2021-12-21 11:56:33 +01:00
copyRecursiveSync(path.join(__dirname, "..", "..", "api", "assets"), path.join(__dirname, "..", "dist", "api", "assets"));
copyRecursiveSync(path.join(__dirname, "..", "..", "api", "client_test"), path.join(__dirname, "..", "dist", "api", "client_test"));
copyRecursiveSync(path.join(__dirname, "..", "..", "api", "locales"), path.join(__dirname, "..", "dist", "api", "locales"));
dirs.forEach((a) => {
2021-12-21 11:56:33 +01:00
copyRecursiveSync("../" + a + "/src", "dist/" + a + "/src");
2021-10-22 09:26:01 +02:00
if (verbose) console.log(`Copied ${"../" + a + "/dist"} -> ${"dist/" + a + "/src"}!`);
2021-10-07 18:21:01 +02:00
});
2021-10-08 10:43:43 +02:00
if (!argv.includes("copyonly")) {
console.log(`[${++i}/${steps}] Compiling src files ...`);
2021-10-07 18:21:01 +02:00
2021-10-22 09:26:01 +02:00
console.log(
execSync(
'node "' +
path.join(__dirname, "..", "node_modules", "typescript", "lib", "tsc.js") +
'" -p "' +
path.join(__dirname, "..") +
'"',
{
cwd: path.join(__dirname, ".."),
shell: true,
env: process.env,
encoding: "utf8"
}
)
);
}
2021-12-21 11:56:33 +01:00