diff options
author | Minteck <46352972+Minteck@users.noreply.github.com> | 2021-07-20 01:30:23 +0200 |
---|---|---|
committer | Minteck <46352972+Minteck@users.noreply.github.com> | 2021-07-20 01:30:23 +0200 |
commit | 44210691ee8444509ac466a362337af77f2bcd49 (patch) | |
tree | 4dc2f242cf5fd4daa3fc6f9e42516e7d55b73538 /typescript | |
parent | efa5fc926071de7087836d399c42f53e701b4cff (diff) | |
download | kartik-client-44210691ee8444509ac466a362337af77f2bcd49.tar.gz kartik-client-44210691ee8444509ac466a362337af77f2bcd49.tar.bz2 kartik-client-44210691ee8444509ac466a362337af77f2bcd49.zip |
Commit
Diffstat (limited to 'typescript')
-rw-r--r-- | typescript/builder.js | 50 | ||||
-rw-r--r-- | typescript/engine-darwin | bin | 0 -> 76348048 bytes | |||
-rw-r--r-- | typescript/engine-linux | bin | 0 -> 74419096 bytes | |||
-rw-r--r-- | typescript/engine-win32.exe | bin | 0 -> 57060488 bytes | |||
-rw-r--r-- | typescript/interface.ts | 23 | ||||
-rw-r--r-- | typescript/mainloader.js | 10 | ||||
-rw-r--r-- | typescript/preloader.js | 5 |
7 files changed, 88 insertions, 0 deletions
diff --git a/typescript/builder.js b/typescript/builder.js new file mode 100644 index 0000000..e3294a1 --- /dev/null +++ b/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) { + console.error(cp.stdout.toString()); + 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")); +}
\ No newline at end of file diff --git a/typescript/engine-darwin b/typescript/engine-darwin Binary files differnew file mode 100644 index 0000000..a09cf1e --- /dev/null +++ b/typescript/engine-darwin diff --git a/typescript/engine-linux b/typescript/engine-linux Binary files differnew file mode 100644 index 0000000..9a7aa3e --- /dev/null +++ b/typescript/engine-linux diff --git a/typescript/engine-win32.exe b/typescript/engine-win32.exe Binary files differnew file mode 100644 index 0000000..9c32378 --- /dev/null +++ b/typescript/engine-win32.exe diff --git a/typescript/interface.ts b/typescript/interface.ts new file mode 100644 index 0000000..28e8219 --- /dev/null +++ b/typescript/interface.ts @@ -0,0 +1,23 @@ +// @ts-nocheck + +let item = { + context: null, + + dom: { + document: null, + window: null, + }, + +}; + +if (typeof HTML !== "undefined") { + if (typeof HTML.document !== "undefined") { + item.dom.document = HTML.document; + } + + if (typeof window !== "undefined") { + item.dom.window = HTML.window; + } +} + +module.exports = item;
\ No newline at end of file diff --git a/typescript/mainloader.js b/typescript/mainloader.js new file mode 100644 index 0000000..6fee294 --- /dev/null +++ b/typescript/mainloader.js @@ -0,0 +1,10 @@ +window.addEventListener("load", () => { + files = require('@electron/remote').getCurrentWindow().modsfiles; + global.HTML = window; + + for (file of files) { + var script = document.createElement('script'); + script.src = "file://" + file.replaceAll("\\", "/"); + document.head.appendChild(script) + } +})
\ No newline at end of file diff --git a/typescript/preloader.js b/typescript/preloader.js new file mode 100644 index 0000000..fae3caf --- /dev/null +++ b/typescript/preloader.js @@ -0,0 +1,5 @@ +files = compiledTypeScriptFiles; + +for (file of files) { + require(file); +}
\ No newline at end of file |