瀏覽代碼

Merge pull request #199 from javascript-obfuscator/cli-config-reading-improvements

Cli config reading improvements
Timofey Kachalov 7 年之前
父節點
當前提交
1657eb21b0

+ 1 - 1
CHANGELOG.md

@@ -15,7 +15,7 @@ v0.14.1
     
 v0.14.0
 ---
-* **New option:** `identifiersPrefix` sets prefix for all generated identifiers.
+* **New option:** `identifiersPrefix` sets prefix for all global identifiers.
 * **New option:** `transformObjectKeys` enables object keys transformation and obfuscation.
 * **New feature:** `eval` expressions obfuscation.
 * **Breaking change:** Now CLI obfuscating directory recursively. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/157

+ 1 - 1
README.md

@@ -575,7 +575,7 @@ Available values:
 ### `identifiersPrefix`
 Type: `string` Default: `''`
 
-Sets prefix for all global generated identifiers.
+Sets prefix for all global identifiers.
 
 Use this option when you want to obfuscate multiple files. This option helps to avoid conflicts between global identifiers of these files. Prefix should be different for every file.
 

File diff suppressed because it is too large
+ 0 - 0
dist/index.js


+ 1 - 1
scripts/test-compile

@@ -2,4 +2,4 @@
 
 $(yarn bin)/tsc -p tsconfig.test.json &&
 $(yarn bin)/babel test-tmp --out-dir test-tmp --source-maps inline --presets es2015 &&
-rsync -a --prune-empty-dirs --include '*/' --include '*.js' --exclude '*' test/ test-tmp/test/
+rsync -a --prune-empty-dirs --include '*/' --include '*.js' --include '*.json' --exclude '*' test/ test-tmp/test/

+ 1 - 1
src/cli/JavaScriptObfuscatorCLI.ts

@@ -250,7 +250,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
             )
             .option(
                 '--identifiers-prefix <string>',
-                'Sets prefix for all global generated identifiers.'
+                'Sets prefix for all global identifiers.'
             )
             .option(
                 '--log <boolean>', 'Enables logging of the information to the console',

+ 1 - 1
src/cli/utils/CLIUtils.ts

@@ -55,7 +55,7 @@ export class CLIUtils {
             try {
                 config = __non_webpack_require__(configPath);
             } catch (e) {
-                throw new ReferenceError('Given config path must be a valid path of `.js` or `.json` file');
+                throw new ReferenceError('Given config path must be a valid `.js` or `.json` file path');
             }
         }
 

+ 5 - 0
test/fixtures/config.json

@@ -0,0 +1,5 @@
+{
+  "compact": true,
+  "selfDefending": false,
+  "sourceMap": true
+}

+ 38 - 15
test/unit-tests/cli/utils/CLIUtils.spec.ts

@@ -36,23 +36,46 @@ describe('CLIUtils', () => {
 
     describe('getUserConfig (configPath: string): Object', () => {
         describe('variant #1: valid config file path', () => {
-            const configDirName: string = 'test/fixtures';
-            const configFileName: string = 'config.js';
-            const configFilePath: string = `../../../${configDirName}/${configFileName}`;
-            const expectedResult: TInputOptions = {
-                compact: true,
-                selfDefending: false,
-                sourceMap: true
-            };
-
-            let result: Object;
-
-            before(() => {
-                result = CLIUtils.getUserConfig(configFilePath);
+            describe('variant #1: js file with config', () => {
+                const configDirName: string = 'test/fixtures';
+                const configFileName: string = 'config.js';
+                const configFilePath: string = `../../../${configDirName}/${configFileName}`;
+                const expectedResult: TInputOptions = {
+                    compact: true,
+                    selfDefending: false,
+                    sourceMap: true
+                };
+
+                let result: Object;
+
+                before(() => {
+                    result = CLIUtils.getUserConfig(configFilePath);
+                });
+
+                it('should return object with user configuration', () => {
+                    assert.deepEqual(result, expectedResult);
+                });
             });
 
-            it('should return object with user configuration', () => {
-                assert.deepEqual(result, expectedResult);
+            describe('variant #2: json file with config', () => {
+                const configDirName: string = 'test/fixtures';
+                const configFileName: string = 'config.json';
+                const configFilePath: string = `../../../${configDirName}/${configFileName}`;
+                const expectedResult: TInputOptions = {
+                    compact: true,
+                    selfDefending: false,
+                    sourceMap: true
+                };
+
+                let result: Object;
+
+                before(() => {
+                    result = CLIUtils.getUserConfig(configFilePath);
+                });
+
+                it('should return object with user configuration', () => {
+                    assert.deepEqual(result, expectedResult);
+                });
             });
         });
 

Some files were not shown because too many files changed in this diff