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();