mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Add --config CLI option that accepts name of js / json file that contains all config instead of passing everything in CLI
This commit is contained in:
@@ -71,11 +71,25 @@ export class JavaScriptObfuscatorCLI {
|
||||
* @returns {TInputOptions}
|
||||
*/
|
||||
private buildOptions (): TInputOptions {
|
||||
const inputOptions: TInputOptions = {};
|
||||
const inputOptions: TInputOptions = this.sanitizeOptions(this.commands);
|
||||
const configFileLocation: string = this.commands.config ?
|
||||
path.resolve(this.commands.config, '.') : '';
|
||||
const configFileOptions: TInputOptions = configFileLocation ?
|
||||
this.sanitizeOptions(require(configFileLocation)) : {};
|
||||
|
||||
return {
|
||||
...DEFAULT_PRESET,
|
||||
...configFileOptions,
|
||||
...inputOptions
|
||||
};
|
||||
}
|
||||
|
||||
private sanitizeOptions (options: any): TInputOptions {
|
||||
const filteredOptions: TInputOptions = {};
|
||||
const availableOptions: string[] = Object.keys(DEFAULT_PRESET);
|
||||
|
||||
for (const option in this.commands) {
|
||||
if (!this.commands.hasOwnProperty(option)) {
|
||||
for (const option in options) {
|
||||
if (!options.hasOwnProperty(option)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -83,13 +97,9 @@ export class JavaScriptObfuscatorCLI {
|
||||
continue;
|
||||
}
|
||||
|
||||
(<any>inputOptions)[option] = (<any>this.commands)[option];
|
||||
(<any>filteredOptions)[option] = (<any>options)[option];
|
||||
}
|
||||
|
||||
return {
|
||||
...DEFAULT_PRESET,
|
||||
...inputOptions
|
||||
};
|
||||
return filteredOptions;
|
||||
}
|
||||
|
||||
private configureCommands (): void {
|
||||
@@ -105,6 +115,10 @@ export class JavaScriptObfuscatorCLI {
|
||||
'Disable one line output code compacting',
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--config <boolean>',
|
||||
'Name of js / json config file'
|
||||
)
|
||||
.option(
|
||||
'--controlFlowFlattening <boolean>',
|
||||
'Enables control flow flattening',
|
||||
|
||||
Reference in New Issue
Block a user