Selaa lähdekoodia

Merge branch 'dev'

sanex3339 7 vuotta sitten
vanhempi
commit
1649f4233f
4 muutettua tiedostoa jossa 32 lisäystä ja 24 poistoa
  1. 1 0
      CHANGELOG.md
  2. 1 1
      README.md
  3. 0 0
      dist/index.js
  4. 30 23
      src/cli/JavaScriptObfuscatorCLI.ts

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@ v0.10.0
 * **New option:** `deadCodeInjection`. With this option random blocks of dead code will add to the obfuscated code.
 * **New option:** `deadCodeInjectionThreshold` allows to set percentage of nodes that will affected by `deadCodeInjection`.
 * **New option:** `mangle` enables mangling of variable names.
+* **New CLI option:** `--config` allows to set config file with obfuscator options.
 * **Breaking change:** `disableConsoleOutput` option now disabled by default.
 * **Breaking change:** `escapeUnicodeSequence` option now disabled by default.
 * `controlFlowFlattening` now affects string literal nodes.

+ 1 - 1
README.md

@@ -269,7 +269,7 @@ Compact code output on one line.
 ### `config`
 Type: `string` Default: ``
 
-Name of JS/JSON config file which contains options mentioned above. These will be overridden by options passed directly to CLI
+Name of JS/JSON config file which contains obfuscator options. These will be overridden by options passed directly to CLI
 
 ### `controlFlowFlattening`
 Type: `boolean` Default: `false`

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
dist/index.js


+ 30 - 23
src/cli/JavaScriptObfuscatorCLI.ts

@@ -50,6 +50,29 @@ export class JavaScriptObfuscatorCLI {
         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 {
         this.configureCommands();
         this.configureHelp();
@@ -71,11 +94,13 @@ export class JavaScriptObfuscatorCLI {
      * @returns {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 {
             ...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 {
         this.commands
             .version(CLIUtils.getPackageConfig().version, '-v, --version')

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä