diff options
author | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
commit | 46e43f4bde4a35785b4997b81e86cd19f046b69b (patch) | |
tree | c53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/build/index.js | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/build/index.js')
-rw-r--r-- | src/build/index.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/build/index.js b/src/build/index.js new file mode 100644 index 0000000..6370574 --- /dev/null +++ b/src/build/index.js @@ -0,0 +1,73 @@ +console.log("LangDetect Compiler v1");
+console.log("Loading, step 1");
+const fs = require('fs');
+console.log("Loading, step 2");
+var JavaScriptObfuscator = require('../node_modules/javascript-obfuscator');
+console.log("Loading, step 3");
+if (fs.existsSync("./keys.bin")) {
+ fs.unlinkSync("./keys.bin");
+}
+
+console.log("Building project...");
+console.log("Getting files list...");
+files = fs.readdirSync("..");
+
+console.log("Compiling " + files.length + " files...");
+total = files.length;
+global.current = 0;
+
+function compile(file) {
+ if (file.endsWith(".js")) {
+ cnt = fs.readFileSync("../" + file).toString();
+ if (file == "../trust.js" || file == "trust.js") {
+ console.log(current + "/" + total + " - " + file + " - Trusted Platform Monitor");
+ cnt = cnt.replaceAll("/*!!obdef!!*/_ob=false;/*!!obdef!!*/", "/*!!obdef!!*/_ob=true;/*!!obdef!!*/")
+ }
+ if (file != "index.js") {
+ console.log(current + "/" + total + " - " + file + " - Security");
+ cnt = "if (require.main === module) { process.exit(255); };" + cnt;
+ }
+ console.log(current + "/" + total + " - " + file + " - Minify");
+ sml = cnt; // TODO: Do REAL minify
+ console.log(current + "/" + total + " - " + file + " - Compile");
+ obf = JavaScriptObfuscator.obfuscate(
+ sml,
+ {
+ compact: true,
+ controlFlowFlattening: true,
+ controlFlowFlatteningThreshold: 1,
+ numbersToExpressions: true,
+ simplify: true,
+ shuffleStringArray: true,
+ splitStrings: true,
+ stringArrayThreshold: 1,
+ selfDefending: true,
+ deadCodeInjection: true,
+ deadCodeInjectionThreshold: 0.25,
+ stringArray: true,
+ target: "node",
+ }
+ );
+ obr = obf.getObfuscatedCode()
+ console.log(current + "/" + total + " - " + file + " - Save");
+ fs.writeFileSync("../../" + file, obr);
+ console.log(current + "/" + total + " - " + file + " - Sign");
+ const trust = require("../../trust.js");
+ trust.add("../../" + file, "LangDetect Continuous Integration (compil86:1.0)", "./" + file);
+ } else {
+ console.log(current + "/" + total + " - " + file + " - Ignore");
+ }
+}
+
+function run() {
+ compile("../trust.js");
+ for (var i = 0; i < total; i++) {
+ file = files[i];
+ compile(file);
+ current++;
+ }
+ console.log("Copying certificate keys...");
+ fs.copyFileSync("./keys.bin", "../../keys.bin");
+}
+
+run();
|