소스 검색

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

Cli config reading improvements
Timofey Kachalov 7 년 전
부모
커밋
1657eb21b0
8개의 변경된 파일48개의 추가작업 그리고 20개의 파일을 삭제
  1. 1 1
      CHANGELOG.md
  2. 1 1
      README.md
  3. 0 0
      dist/index.js
  4. 1 1
      scripts/test-compile
  5. 1 1
      src/cli/JavaScriptObfuscatorCLI.ts
  6. 1 1
      src/cli/utils/CLIUtils.ts
  7. 5 0
      test/fixtures/config.json
  8. 38 15
      test/unit-tests/cli/utils/CLIUtils.spec.ts

+ 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.
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 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);
+                });
             });
         });
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.