@ordino.ai/cli
Version:
ordino.ai global command line interface
50 lines (44 loc) • 1.61 kB
text/typescript
import fs from "fs";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const JavaScriptObfuscator = require("javascript-obfuscator");
export function obfuscateJavaScriptFile(filePath: string): void {
try {
const fileContent = fs.readFileSync(filePath, { encoding: "utf8" });
const obfuscationResult = JavaScriptObfuscator.obfuscate(fileContent, {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: 0,
disableConsoleOutput: false,
identifierNamesGenerator: "hexadecimal",
log: false,
numbersToExpressions: true,
renameGlobals: false,
selfDefending: true,
simplify: true,
splitStrings: true,
splitStringsChunkLength: 10,
stringArray: true,
stringArrayCallsTransform: true,
stringArrayEncoding: ["base64"],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 2,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 4,
stringArrayWrappersType: "function",
stringArrayThreshold: 0.75,
transformObjectKeys: true,
unicodeEscapeSequence: false,
});
const obfuscatedCode = obfuscationResult.getObfuscatedCode();
fs.writeFileSync(filePath, obfuscatedCode, { encoding: "utf8" });
} catch (error) {
console.error(`Error obfuscating file ${filePath}:`, error);
throw error;
}
}