summary refs log tree commit diff
path: root/scripts/build.js
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 18:24:21 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 23:35:18 +1000
commitf44f5d7ac2d24ff836c2e1d4b2fa58da04b13052 (patch)
treea6655c41bb3db79c30fd876b06ee60fe9cf70c9b /scripts/build.js
parentAllow edited_timestamp to passthrough in handleMessage (diff)
downloadserver-f44f5d7ac2d24ff836c2e1d4b2fa58da04b13052.tar.xz
Refactor to mono-repo + upgrade packages
Diffstat (limited to 'scripts/build.js')
-rw-r--r--scripts/build.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/build.js b/scripts/build.js
new file mode 100644
index 00000000..dfe7dfa1
--- /dev/null
+++ b/scripts/build.js
@@ -0,0 +1,72 @@
+const { execSync } = require("child_process");
+const path = require("path");
+const fs = require("fs");
+const { getSystemErrorMap } = require("util");
+const { argv } = require("process");
+
+var steps = 2, i = 0;
+if (argv.includes("clean")) steps++;
+if (argv.includes("copyonly")) steps--;
+const dirs = ["api", "util", "cdn", "gateway", "bundle"];
+const verbose = argv.includes("verbose") || argv.includes("v");
+
+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...`);
+	dirs.forEach((a) => {
+		var d = "../" + a + "/dist";
+		if (fs.existsSync(d)) {
+			fs.rmSync(d, { recursive: true });
+			if (verbose) console.log(`Deleted ${d}!`);
+		}
+	});
+}
+
+console.log(`[${++i}/${steps}] Copying src files...`);
+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) => {
+	copyRecursiveSync("../" + a + "/src", "dist/" + a + "/src");
+	if (verbose) console.log(`Copied ${"../" + a + "/dist"} -> ${"dist/" + a + "/src"}!`);
+});
+
+if (!argv.includes("copyonly")) {
+	console.log(`[${++i}/${steps}] Compiling src files ...`);
+
+	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"
+			}
+		)
+	);
+}
+