|
@@ -1,6 +1,8 @@
|
|
import * as fs from 'fs';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
+import chalk, { Chalk } from 'chalk';
|
|
|
|
+
|
|
import { TSourceCodeData } from '../../types/cli/TSourceCodeData';
|
|
import { TSourceCodeData } from '../../types/cli/TSourceCodeData';
|
|
|
|
|
|
import { IFileData } from '../../interfaces/cli/IFileData';
|
|
import { IFileData } from '../../interfaces/cli/IFileData';
|
|
@@ -8,6 +10,16 @@ import { IFileData } from '../../interfaces/cli/IFileData';
|
|
import { JavaScriptObfuscatorCLI } from '../JavaScriptObfuscatorCLI';
|
|
import { JavaScriptObfuscatorCLI } from '../JavaScriptObfuscatorCLI';
|
|
|
|
|
|
export class SourceCodeReader {
|
|
export class SourceCodeReader {
|
|
|
|
+ /**
|
|
|
|
+ * @type {Chalk}
|
|
|
|
+ */
|
|
|
|
+ private static readonly colorInfo: Chalk = chalk.cyan;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @type {string}
|
|
|
|
+ */
|
|
|
|
+ private static readonly loggingPrefix: string = '[javascript-obfuscator-cli]';
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param {string} inputPath
|
|
* @param {string} inputPath
|
|
* @returns {TSourceCodeData}
|
|
* @returns {TSourceCodeData}
|
|
@@ -63,7 +75,7 @@ export class SourceCodeReader {
|
|
...SourceCodeReader.readDirectoryRecursive(filePath)
|
|
...SourceCodeReader.readDirectoryRecursive(filePath)
|
|
);
|
|
);
|
|
} else if (SourceCodeReader.isFilePath(filePath) && SourceCodeReader.isValidFile(fileName)) {
|
|
} else if (SourceCodeReader.isFilePath(filePath) && SourceCodeReader.isValidFile(fileName)) {
|
|
- const content: string = fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding);
|
|
|
|
|
|
+ const content: string = SourceCodeReader.readFile(filePath);
|
|
|
|
|
|
fileData.push({ filePath, content });
|
|
fileData.push({ filePath, content });
|
|
}
|
|
}
|
|
@@ -81,6 +93,8 @@ export class SourceCodeReader {
|
|
throw new ReferenceError(`Input file must have .js extension`);
|
|
throw new ReferenceError(`Input file must have .js extension`);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ SourceCodeReader.logFilePath(`Obfuscating file: ${filePath}...`);
|
|
|
|
+
|
|
return fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding);
|
|
return fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -92,4 +106,13 @@ export class SourceCodeReader {
|
|
return JavaScriptObfuscatorCLI.availableInputExtensions.includes(path.extname(filePath))
|
|
return JavaScriptObfuscatorCLI.availableInputExtensions.includes(path.extname(filePath))
|
|
&& !filePath.includes(JavaScriptObfuscatorCLI.obfuscatedFilePrefix);
|
|
&& !filePath.includes(JavaScriptObfuscatorCLI.obfuscatedFilePrefix);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param {string} filePath
|
|
|
|
+ */
|
|
|
|
+ private static logFilePath (filePath: string): void {
|
|
|
|
+ const normalizedFilePath: string = path.normalize(filePath);
|
|
|
|
+
|
|
|
|
+ console.log(SourceCodeReader.colorInfo(`\n${SourceCodeReader.loggingPrefix} ${normalizedFilePath}`));
|
|
|
|
+ }
|
|
}
|
|
}
|