diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index b3879fd0..57b0f6b6 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -27,11 +27,11 @@ import { ArraySanitizer } from './sanitizers/ArraySanitizer'; import { BooleanSanitizer } from './sanitizers/BooleanSanitizer'; import { CLIUtils } from './utils/CLIUtils'; -import { IdentifierNamesCacheUtils } from './utils/IdentifierNamesCacheUtils'; +import { IdentifierNamesCacheFileUtils } from './utils/IdentifierNamesCacheFileUtils'; import { JavaScriptObfuscator } from '../JavaScriptObfuscatorFacade'; import { Logger } from '../logger/Logger'; -import { ObfuscatedCodeWriter } from './utils/ObfuscatedCodeWriter'; -import { SourceCodeReader } from './utils/SourceCodeReader'; +import { ObfuscatedCodeFileUtils } from './utils/ObfuscatedCodeFileUtils'; +import { SourceCodeFileUtils } from './utils/SourceCodeFileUtils'; import { Utils } from '../utils/Utils'; export class JavaScriptObfuscatorCLI implements IInitializable { @@ -59,10 +59,10 @@ export class JavaScriptObfuscatorCLI implements IInitializable { private commands!: commander.CommanderStatic; /** - * @type {IdentifierNamesCacheUtils} + * @type {IdentifierNamesCacheFileUtils} */ @initializable() - private identifierNamesCacheUtils!: IdentifierNamesCacheUtils; + private identifierNamesCacheFileUtils!: IdentifierNamesCacheFileUtils; /** * @type {TInputCLIOptions} @@ -77,16 +77,16 @@ export class JavaScriptObfuscatorCLI implements IInitializable { private inputPath!: string; /** - * @type {SourceCodeReader} + * @type {SourceCodeFileUtils} */ @initializable() - private sourceCodeReader!: SourceCodeReader; + private sourceCodeFileUtils!: SourceCodeFileUtils; /** - * @type {ObfuscatedCodeWriter} + * @type {ObfuscatedCodeFileUtils} */ @initializable() - private obfuscatedCodeWriter!: ObfuscatedCodeWriter; + private obfuscatedCodeFileUtils!: ObfuscatedCodeFileUtils; /** * @type {string[]} @@ -151,15 +151,15 @@ export class JavaScriptObfuscatorCLI implements IInitializable { this.inputPath = path.normalize(this.commands.args[0] || ''); this.inputCLIOptions = JavaScriptObfuscatorCLI.buildOptions(this.commands.opts()); - this.sourceCodeReader = new SourceCodeReader( + this.sourceCodeFileUtils = new SourceCodeFileUtils( this.inputPath, this.inputCLIOptions ); - this.obfuscatedCodeWriter = new ObfuscatedCodeWriter( + this.obfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( this.inputPath, this.inputCLIOptions ); - this.identifierNamesCacheUtils = new IdentifierNamesCacheUtils(this.inputCLIOptions.identifierNamesCachePath); + this.identifierNamesCacheFileUtils = new IdentifierNamesCacheFileUtils(this.inputCLIOptions.identifierNamesCachePath); } public run (): void { @@ -171,7 +171,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { return; } - const sourceCodeData: IFileData[] = this.sourceCodeReader.readSourceCode(); + const sourceCodeData: IFileData[] = this.sourceCodeFileUtils.readSourceCode(); this.processSourceCodeData(sourceCodeData); } @@ -442,7 +442,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { */ private processSourceCodeData (sourceCodeData: IFileData[]): void { sourceCodeData.forEach(({ filePath, content }: IFileData, index: number) => { - const outputCodePath: string = this.obfuscatedCodeWriter.getOutputCodePath(filePath); + const outputCodePath: string = this.obfuscatedCodeFileUtils.getOutputCodePath(filePath); try { Logger.log( @@ -478,7 +478,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { ): void { const options: TInputOptions = { ...this.inputCLIOptions, - identifierNamesCache: this.identifierNamesCacheUtils.read(), + identifierNamesCache: this.identifierNamesCacheFileUtils.readFile(), inputFileName: path.basename(inputCodePath), ...sourceCodeIndex !== null && { identifiersPrefix: Utils.getIdentifiersPrefixForMultipleSources( @@ -507,8 +507,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable { ): void { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(sourceCode, options); - this.obfuscatedCodeWriter.writeFile(outputCodePath, obfuscationResult.getObfuscatedCode()); - this.identifierNamesCacheUtils.write(obfuscationResult.getIdentifierNamesCache()); + this.obfuscatedCodeFileUtils.writeFile(outputCodePath, obfuscationResult.getObfuscatedCode()); + this.identifierNamesCacheFileUtils.writeFile(obfuscationResult.getIdentifierNamesCache()); } /** @@ -521,7 +521,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { outputCodePath: string, options: TInputOptions ): void { - const outputSourceMapPath: string = this.obfuscatedCodeWriter.getOutputSourceMapPath( + const outputSourceMapPath: string = this.obfuscatedCodeFileUtils.getOutputSourceMapPath( outputCodePath, options.sourceMapFileName ?? '' ); @@ -533,11 +533,11 @@ export class JavaScriptObfuscatorCLI implements IInitializable { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(sourceCode, options); - this.obfuscatedCodeWriter.writeFile(outputCodePath, obfuscationResult.getObfuscatedCode()); - this.identifierNamesCacheUtils.write(obfuscationResult.getIdentifierNamesCache()); + this.obfuscatedCodeFileUtils.writeFile(outputCodePath, obfuscationResult.getObfuscatedCode()); + this.identifierNamesCacheFileUtils.writeFile(obfuscationResult.getIdentifierNamesCache()); if (options.sourceMapMode === SourceMapMode.Separate && obfuscationResult.getSourceMap()) { - this.obfuscatedCodeWriter.writeFile(outputSourceMapPath, obfuscationResult.getSourceMap()); + this.obfuscatedCodeFileUtils.writeFile(outputSourceMapPath, obfuscationResult.getSourceMap()); } } } diff --git a/src/cli/utils/IdentifierNamesCacheUtils.ts b/src/cli/utils/IdentifierNamesCacheFileUtils.ts similarity index 83% rename from src/cli/utils/IdentifierNamesCacheUtils.ts rename to src/cli/utils/IdentifierNamesCacheFileUtils.ts index 6ef140c5..47a5ac6b 100644 --- a/src/cli/utils/IdentifierNamesCacheUtils.ts +++ b/src/cli/utils/IdentifierNamesCacheFileUtils.ts @@ -10,7 +10,7 @@ import { JavaScriptObfuscatorCLI } from '../JavaScriptObfuscatorCLI'; /** * Utils to work with identifier names cache file */ -export class IdentifierNamesCacheUtils { +export class IdentifierNamesCacheFileUtils { /** * @type {string} */ @@ -35,7 +35,7 @@ export class IdentifierNamesCacheUtils { private static isValidFilePath (filePath: string): boolean { try { return fs.statSync(filePath).isFile() - && path.extname(filePath) === IdentifierNamesCacheUtils.identifierNamesCacheExtension; + && path.extname(filePath) === IdentifierNamesCacheFileUtils.identifierNamesCacheExtension; } catch { return false; } @@ -55,18 +55,18 @@ export class IdentifierNamesCacheUtils { /** * @returns {TIdentifierNamesCache | null} */ - public read (): TIdentifierNamesCache | null { + public readFile (): TIdentifierNamesCache | null { if (!this.identifierNamesCachePath) { return null; } - if (!IdentifierNamesCacheUtils.isValidFilePath(this.identifierNamesCachePath)) { + if (!IdentifierNamesCacheFileUtils.isValidFilePath(this.identifierNamesCachePath)) { throw new ReferenceError(`Given identifier names cache path must be a valid ${ - IdentifierNamesCacheUtils.identifierNamesCacheExtension + IdentifierNamesCacheFileUtils.identifierNamesCacheExtension } file path`); } - const fileData: IFileData = IdentifierNamesCacheUtils.readFile(this.identifierNamesCachePath); + const fileData: IFileData = IdentifierNamesCacheFileUtils.readFile(this.identifierNamesCachePath); if (!fileData.content) { // Initial state of identifier names cache file @@ -87,7 +87,7 @@ export class IdentifierNamesCacheUtils { /** * @param {TIdentifierNamesCache} identifierNamesCache */ - public write (identifierNamesCache: TIdentifierNamesCache): void { + public writeFile (identifierNamesCache: TIdentifierNamesCache): void { if (!this.identifierNamesCachePath) { return; } diff --git a/src/cli/utils/ObfuscatedCodeWriter.ts b/src/cli/utils/ObfuscatedCodeFileUtils.ts similarity index 99% rename from src/cli/utils/ObfuscatedCodeWriter.ts rename to src/cli/utils/ObfuscatedCodeFileUtils.ts index 4b0a1530..3a595db5 100644 --- a/src/cli/utils/ObfuscatedCodeWriter.ts +++ b/src/cli/utils/ObfuscatedCodeFileUtils.ts @@ -8,7 +8,7 @@ import { StringSeparator } from '../../enums/StringSeparator'; import { JavaScriptObfuscatorCLI } from '../JavaScriptObfuscatorCLI'; -export class ObfuscatedCodeWriter { +export class ObfuscatedCodeFileUtils { /** * @type {string} */ diff --git a/src/cli/utils/SourceCodeReader.ts b/src/cli/utils/SourceCodeFileUtils.ts similarity index 82% rename from src/cli/utils/SourceCodeReader.ts rename to src/cli/utils/SourceCodeFileUtils.ts index 4ef0df23..f89610c6 100644 --- a/src/cli/utils/SourceCodeReader.ts +++ b/src/cli/utils/SourceCodeFileUtils.ts @@ -8,7 +8,7 @@ import { IFileData } from '../../interfaces/cli/IFileData'; import { JavaScriptObfuscatorCLI } from '../JavaScriptObfuscatorCLI'; -export class SourceCodeReader { +export class SourceCodeFileUtils { /** * @type {string} */ @@ -80,7 +80,7 @@ export class SourceCodeReader { * @returns {boolean} */ private static isValidDirectory (directoryPath: string, excludePatterns: string[] = []): boolean { - return !SourceCodeReader.isExcludedPath(directoryPath, excludePatterns); + return !SourceCodeFileUtils.isExcludedPath(directoryPath, excludePatterns); } /** @@ -91,7 +91,7 @@ export class SourceCodeReader { private static isValidFile (filePath: string, excludePatterns: string[] = []): boolean { return JavaScriptObfuscatorCLI.availableInputExtensions.includes(path.extname(filePath)) && !filePath.includes(JavaScriptObfuscatorCLI.obfuscatedFilePrefix) - && !SourceCodeReader.isExcludedPath(filePath, excludePatterns); + && !SourceCodeFileUtils.isExcludedPath(filePath, excludePatterns); } /** @@ -110,15 +110,15 @@ export class SourceCodeReader { */ public readSourceCode (): IFileData[] { if ( - SourceCodeReader.isFilePath(this.inputPath) - && SourceCodeReader.isValidFile(this.inputPath, this.options.exclude) + SourceCodeFileUtils.isFilePath(this.inputPath) + && SourceCodeFileUtils.isValidFile(this.inputPath, this.options.exclude) ) { - return [SourceCodeReader.readFile(this.inputPath)]; + return [SourceCodeFileUtils.readFile(this.inputPath)]; } if ( - SourceCodeReader.isDirectoryPath(this.inputPath) - && SourceCodeReader.isValidDirectory(this.inputPath, this.options.exclude) + SourceCodeFileUtils.isDirectoryPath(this.inputPath) + && SourceCodeFileUtils.isValidDirectory(this.inputPath, this.options.exclude) ) { return this.readDirectoryRecursive(this.inputPath); } @@ -142,8 +142,8 @@ export class SourceCodeReader { const filePath: string = path.join(directoryPath, fileName); if ( - SourceCodeReader.isDirectoryPath(filePath) - && SourceCodeReader.isValidDirectory(filePath, this.options.exclude) + SourceCodeFileUtils.isDirectoryPath(filePath) + && SourceCodeFileUtils.isValidDirectory(filePath, this.options.exclude) ) { filesData.push(...this.readDirectoryRecursive(filePath)); @@ -151,10 +151,10 @@ export class SourceCodeReader { } if ( - SourceCodeReader.isFilePath(filePath) - && SourceCodeReader.isValidFile(filePath, this.options.exclude) + SourceCodeFileUtils.isFilePath(filePath) + && SourceCodeFileUtils.isValidFile(filePath, this.options.exclude) ) { - const fileData: IFileData = SourceCodeReader.readFile(filePath); + const fileData: IFileData = SourceCodeFileUtils.readFile(filePath); filesData.push(fileData); diff --git a/test/fixtures/compile-performance.js b/test/fixtures/compile-performance.js index ff5381d6..3645769a 100644 --- a/test/fixtures/compile-performance.js +++ b/test/fixtures/compile-performance.js @@ -33689,7 +33689,7 @@ var _QueryWithRead = (function () { function _QueryWithRead(query, match) { this.query = query; - this.read = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__facade_lang__["a" /* isPresent */])(query.meta.read) ? query.meta.read : match; + this.readFile = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__facade_lang__["a" /* isPresent */])(query.meta.read) ? query.meta.read : match; } return _QueryWithRead; }()); diff --git a/test/index.spec.ts b/test/index.spec.ts index b6e84c20..d191ed70 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -11,8 +11,8 @@ import './unit-tests/analyzers/string-array-storage-analyzer/StringArrayStorageA import './unit-tests/cli/sanitizers/ArraySanitizer.spec'; import './unit-tests/cli/sanitizers/BooleanSanitizer.spec'; import './unit-tests/cli/utils/CLIUtils.spec'; -import './unit-tests/cli/utils/ObfuscatedCodeWriter.spec'; -import './unit-tests/cli/utils/SourceCodeReader.spec'; +import './unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec'; +import './unit-tests/cli/utils/SourceCodeFileUtils.spec'; import './unit-tests/decorators/initializable/Initializable.spec'; import './unit-tests/generators/identifier-names-generators/DictionarylIdentifierNamesGenerator.spec'; import './unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec'; diff --git a/test/unit-tests/cli/utils/ObfuscatedCodeWriter.spec.ts b/test/unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec.ts similarity index 82% rename from test/unit-tests/cli/utils/ObfuscatedCodeWriter.spec.ts rename to test/unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec.ts index c6dc48ad..cd2f8ee0 100644 --- a/test/unit-tests/cli/utils/ObfuscatedCodeWriter.spec.ts +++ b/test/unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec.ts @@ -4,9 +4,9 @@ import * as mkdirp from 'mkdirp'; import * as path from 'path'; import * as rimraf from 'rimraf'; -import { ObfuscatedCodeWriter } from '../../../../src/cli/utils/ObfuscatedCodeWriter'; +import { ObfuscatedCodeFileUtils } from '../../../../src/cli/utils/ObfuscatedCodeFileUtils'; -describe('ObfuscatedCodeWriter', () => { +describe('obfuscatedCodeFileUtils', () => { const tmpDirectoryPath: string = 'test/tmp'; describe('getOutputCodePath', () => { @@ -27,13 +27,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that equals to passed output file path', () => { @@ -50,13 +50,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that equals to passed output directory with file name from actual file path', () => { @@ -72,13 +72,13 @@ describe('ObfuscatedCodeWriter', () => { let testFunc: () => string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - testFunc = () => obfuscatedCodeWriter.getOutputCodePath(inputPath); + testFunc = () => obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should throw an error if output path is a file path', () => { @@ -100,13 +100,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that contains raw output path and actual file input path', () => { @@ -127,13 +127,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that contains raw output path and actual file input path', () => { @@ -155,13 +155,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that contains raw output path and actual file input path', () => { @@ -184,13 +184,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that contains raw output path and actual file input path', () => { @@ -211,13 +211,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that contains raw output path and actual file input path', () => { @@ -238,13 +238,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that contains raw output path and actual file input path', () => { @@ -280,13 +280,13 @@ describe('ObfuscatedCodeWriter', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath); + outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); it('should return output path that contains raw output path and actual file input path', () => { @@ -315,13 +315,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath); }); it('should return output path for source map', () => { @@ -337,13 +337,13 @@ describe('ObfuscatedCodeWriter', () => { let testFunc: () => string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - testFunc = () => obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath); + testFunc = () => obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath); }); it('should throw an error if output code path is a directory path and source map file name is not set', () => { @@ -360,13 +360,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath); }); it('should return output path for source map', () => { @@ -384,13 +384,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -408,13 +408,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -432,13 +432,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -456,13 +456,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -480,13 +480,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -505,13 +505,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -529,13 +529,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -553,13 +553,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -577,13 +577,13 @@ describe('ObfuscatedCodeWriter', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeWriter.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -599,13 +599,13 @@ describe('ObfuscatedCodeWriter', () => { let testFunc: () => string; before(() => { - const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter( + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( rawInputPath, { output: rawOutputPath } ); - testFunc = () => obfuscatedCodeWriter.getOutputSourceMapPath('', ''); + testFunc = () => obfuscatedCodeFileUtils.getOutputSourceMapPath('', ''); }); it('should throw an error if output code path is empty', () => { diff --git a/test/unit-tests/cli/utils/SourceCodeReader.spec.ts b/test/unit-tests/cli/utils/SourceCodeFileUtils.spec.ts similarity index 94% rename from test/unit-tests/cli/utils/SourceCodeReader.spec.ts rename to test/unit-tests/cli/utils/SourceCodeFileUtils.spec.ts index a91f0f37..d69ab1bb 100644 --- a/test/unit-tests/cli/utils/SourceCodeReader.spec.ts +++ b/test/unit-tests/cli/utils/SourceCodeFileUtils.spec.ts @@ -7,9 +7,9 @@ import { assert } from 'chai'; import { IFileData } from '../../../../src/interfaces/cli/IFileData'; -import { SourceCodeReader } from '../../../../src/cli/utils/SourceCodeReader'; +import { SourceCodeFileUtils } from '../../../../src/cli/utils/SourceCodeFileUtils'; -describe('SourceCodeReader', () => { +describe('SourceCodeFileUtils', () => { const expectedError: RegExp = /Given input path must be a valid/; const fileContent: string = 'test'; const tmpDirectoryPath: string = path.join('test', 'tmp'); @@ -32,7 +32,7 @@ describe('SourceCodeReader', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - filesData = new SourceCodeReader(inputPath, {}).readSourceCode(); + filesData = new SourceCodeFileUtils(inputPath, {}).readSourceCode(); }); it('should return valid files data', () => { @@ -51,7 +51,7 @@ describe('SourceCodeReader', () => { let testFunc: () => void; before(() => { - testFunc = () => new SourceCodeReader(inputPath, {}).readSourceCode(); + testFunc = () => new SourceCodeFileUtils(inputPath, {}).readSourceCode(); }); it('should throw an error if `inputPath` is not a valid path', () => { @@ -67,7 +67,7 @@ describe('SourceCodeReader', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - testFunc = () => new SourceCodeReader(inputPath, {}).readSourceCode(); + testFunc = () => new SourceCodeFileUtils(inputPath, {}).readSourceCode(); }); it('should throw an error if `inputPath` has invalid extension', () => { @@ -92,7 +92,7 @@ describe('SourceCodeReader', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - filesData = new SourceCodeReader( + filesData = new SourceCodeFileUtils( inputPath, { exclude: [path.join('**', 'foo.js')] @@ -118,7 +118,7 @@ describe('SourceCodeReader', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - testFunc = () => new SourceCodeReader( + testFunc = () => new SourceCodeFileUtils( inputPath, { exclude: [path.join('**', tmpFileName)] @@ -143,7 +143,7 @@ describe('SourceCodeReader', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - testFunc = () => new SourceCodeReader( + testFunc = () => new SourceCodeFileUtils( inputPath, { exclude: [tmpFileName] @@ -168,7 +168,7 @@ describe('SourceCodeReader', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - testFunc = () => new SourceCodeReader( + testFunc = () => new SourceCodeFileUtils( inputPath, { exclude: [inputPath] @@ -217,7 +217,7 @@ describe('SourceCodeReader', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeReader(tmpDirectoryPath, {}).readSourceCode(); + result = new SourceCodeFileUtils(tmpDirectoryPath, {}).readSourceCode(); }); it('should return files data', () => { @@ -238,7 +238,7 @@ describe('SourceCodeReader', () => { let testFunc: () => void; before(() => { - testFunc = () => new SourceCodeReader(inputPath, {}).readSourceCode(); + testFunc = () => new SourceCodeFileUtils(inputPath, {}).readSourceCode(); }); it('should throw an error if `inputPath` is not a valid path', () => { @@ -288,7 +288,7 @@ describe('SourceCodeReader', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeReader(tmpDirectoryPath, {}).readSourceCode(); + result = new SourceCodeFileUtils(tmpDirectoryPath, {}).readSourceCode(); }); it('should return files data', () => { @@ -334,7 +334,7 @@ describe('SourceCodeReader', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeReader( + result = new SourceCodeFileUtils( tmpDirectoryPath, { exclude: ['**/hawk.js'] @@ -383,7 +383,7 @@ describe('SourceCodeReader', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeReader( + result = new SourceCodeFileUtils( tmpDirectoryPath, { exclude: [ @@ -434,7 +434,7 @@ describe('SourceCodeReader', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeReader( + result = new SourceCodeFileUtils( tmpDirectoryPath, { exclude: [ @@ -485,7 +485,7 @@ describe('SourceCodeReader', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeReader( + result = new SourceCodeFileUtils( tmpDirectoryPath, { exclude: [ @@ -525,7 +525,7 @@ describe('SourceCodeReader', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - testFunc = () => new SourceCodeReader( + testFunc = () => new SourceCodeFileUtils( tmpDirectoryPath, { exclude: [tmpDirectoryPath] @@ -564,7 +564,7 @@ describe('SourceCodeReader', () => { before(() => { mkdirp.sync(tmpDirectoryWithDotPath); fs.writeFileSync(filePath, fileContent); - result = new SourceCodeReader(tmpDirectoryWithDotPath, {}).readSourceCode(); + result = new SourceCodeFileUtils(tmpDirectoryWithDotPath, {}).readSourceCode(); }); it('should return files data', () => {