|
@@ -50,6 +50,29 @@ export class JavaScriptObfuscatorCLI {
|
|
this.commands = <commander.CommanderStatic>(new commander.Command());
|
|
this.commands = <commander.CommanderStatic>(new commander.Command());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param options
|
|
|
|
+ * @returns {TInputOptions}
|
|
|
|
+ */
|
|
|
|
+ private static sanitizeOptions (options: {[key: string]: any}): TInputOptions {
|
|
|
|
+ const filteredOptions: TInputOptions = {};
|
|
|
|
+ const availableOptions: string[] = Object.keys(DEFAULT_PRESET);
|
|
|
|
+
|
|
|
|
+ for (const option in options) {
|
|
|
|
+ if (!options.hasOwnProperty(option)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!availableOptions.includes(option)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ (<any>filteredOptions)[option] = (<any>options)[option];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return filteredOptions;
|
|
|
|
+ }
|
|
|
|
+
|
|
public run (): void {
|
|
public run (): void {
|
|
this.configureCommands();
|
|
this.configureCommands();
|
|
this.configureHelp();
|
|
this.configureHelp();
|
|
@@ -71,11 +94,13 @@ export class JavaScriptObfuscatorCLI {
|
|
* @returns {TInputOptions}
|
|
* @returns {TInputOptions}
|
|
*/
|
|
*/
|
|
private buildOptions (): TInputOptions {
|
|
private buildOptions (): 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)) : {};
|
|
|
|
|
|
+ const inputOptions: TInputOptions = JavaScriptObfuscatorCLI.sanitizeOptions(this.commands);
|
|
|
|
+ const configFileLocation: string = this.commands.config
|
|
|
|
+ ? path.resolve(this.commands.config, '.')
|
|
|
|
+ : '';
|
|
|
|
+ const configFileOptions: TInputOptions = configFileLocation
|
|
|
|
+ ? JavaScriptObfuscatorCLI.sanitizeOptions(require(configFileLocation))
|
|
|
|
+ : {};
|
|
|
|
|
|
return {
|
|
return {
|
|
...DEFAULT_PRESET,
|
|
...DEFAULT_PRESET,
|
|
@@ -84,24 +109,6 @@ export class JavaScriptObfuscatorCLI {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- private sanitizeOptions (options: any): TInputOptions {
|
|
|
|
- const filteredOptions: TInputOptions = {};
|
|
|
|
- const availableOptions: string[] = Object.keys(DEFAULT_PRESET);
|
|
|
|
-
|
|
|
|
- for (const option in options) {
|
|
|
|
- if (!options.hasOwnProperty(option)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!availableOptions.includes(option)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- (<any>filteredOptions)[option] = (<any>options)[option];
|
|
|
|
- }
|
|
|
|
- return filteredOptions;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private configureCommands (): void {
|
|
private configureCommands (): void {
|
|
this.commands
|
|
this.commands
|
|
.version(CLIUtils.getPackageConfig().version, '-v, --version')
|
|
.version(CLIUtils.getPackageConfig().version, '-v, --version')
|