summaryrefslogtreecommitdiff
path: root/kartik/typescript/builder.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-05-18 18:50:12 +0200
committerMinteck <contact@minteck.org>2022-05-18 18:50:12 +0200
commit0bd45cb2cae3af05adaad3f38d129bb67c3e0ec0 (patch)
tree97a7e15187fe7fcb5b8775e03a62f62ac8fc5c61 /kartik/typescript/builder.js
parentd4805039b8ea7b30f5e78cf53caf8fd3f267256a (diff)
downloadarcade-trunk.tar.gz
arcade-trunk.tar.bz2
arcade-trunk.zip
Add KartikHEADtrunk
Diffstat (limited to 'kartik/typescript/builder.js')
-rwxr-xr-xkartik/typescript/builder.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/kartik/typescript/builder.js b/kartik/typescript/builder.js
new file mode 100755
index 0000000..1e9bf16
--- /dev/null
+++ b/kartik/typescript/builder.js
@@ -0,0 +1,50 @@
+const os = require('os');
+const fs = require('fs');
+const { dialog } = require('electron');
+
+if (os.platform() === "win32") {
+ cmd = "typescript\\engine-win32.exe";
+} else {
+ cmd = "./typescript/engine-" + os.platform();
+}
+
+fs.copyFileSync("./typescript/interface.ts", homedir + "/.kartik/build/kartik.ts");
+
+cp = require('child_process').spawnSync(cmd, [ "./node_modules/typescript/bin/tsc", "--skipLibCheck", "--removeComments", "--sourceMap", "-m", "commonjs", "--target", "es6", homedir + "/.kartik/build/kartik.ts" ], { cwd: KartikRoot });
+if (cp.status !== 0) {
+ try { console.error(cp.stdout.toString()); } catch (e) {}
+ throw new Error("Subprocess exited with code " + cp.status);
+}
+
+fs.unlinkSync(homedir + "/.kartik/build/kartik.ts");
+
+module.exports = (source, destination) => {
+ if (os.platform() === "win32") {
+ source = source.replaceAll("/", "\\");
+ destination = destination.replaceAll("/", "\\");
+ }
+
+ console.log(destination.substr(0, destination.length - 3));
+ fs.copyFileSync(source, destination.substr(0, destination.length - 3));
+ fs.writeFileSync(destination.substr(0, destination.length - 3), fs.readFileSync(destination.substr(0, destination.length - 3)).toString().replaceAll("$KARTIK:", homedir.replaceAll("\\", "\\\\") + "/.kartik/build/kartik.js"))
+ cp = require('child_process').spawnSync(cmd, [ "./node_modules/typescript/bin/tsc", "--skipLibCheck", "--removeComments", "--sourceMap", "-m", "commonjs", "--target", "es5", destination.substr(0, destination.length - 3) ], { cwd: KartikRoot });
+ if (cp.status !== 0) {
+ if (cp.stdout !== undefined) {
+ dialog.showMessageBoxSync(
+ {
+ type: "error",
+ title: "KMP Mod Loader",
+ message: "On package " + item + ": KMP-API building " + source + ":\n\n" + cp.stdout.toString().trim() + "\n\nEXITING."
+ }
+ )
+ process.exit(2);
+ } else {
+ throw new Error("Subprocess exited with code " + cp.status);
+ }
+ }
+ compiledTypeScriptFiles.push(destination.substr(0, destination.length - 6) + ".js");
+
+ lines = fs.readFileSync(destination.substr(0, destination.length - 6) + ".js").toString().split("\n");
+ lines[1] = "";
+ fs.writeFileSync(destination.substr(0, destination.length - 6) + ".js", lines.join("\n"));
+}