mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge branch 'master' into master
This commit is contained in:
@@ -143,7 +143,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
}
|
||||
|
||||
public initialize (): void {
|
||||
this.inputPath = this.arguments[0] || '';
|
||||
this.inputPath = path.normalize(this.arguments[0] || '');
|
||||
this.commands = <commander.CommanderStatic>(new commander.Command());
|
||||
|
||||
this.configureCommands();
|
||||
@@ -331,13 +331,19 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
* @param {TSourceCodeData} sourceCodeData
|
||||
*/
|
||||
private processSourceCodeData (sourceCodeData: TSourceCodeData): void {
|
||||
const outputPath: string = this.inputCLIOptions.output
|
||||
? path.normalize(this.inputCLIOptions.output)
|
||||
: '';
|
||||
|
||||
if (!Array.isArray(sourceCodeData)) {
|
||||
const outputCodePath: string = this.inputCLIOptions.output || CLIUtils.getOutputCodePath(this.inputPath);
|
||||
const outputCodePath: string = outputPath || CLIUtils.getOutputCodePath(this.inputPath);
|
||||
|
||||
this.processSourceCode(sourceCodeData, outputCodePath);
|
||||
} else {
|
||||
sourceCodeData.forEach(({ filePath, content }: IFileData) => {
|
||||
const outputCodePath: string = CLIUtils.getOutputCodePath(filePath);
|
||||
const outputCodePath: string = outputPath
|
||||
? path.join(outputPath, filePath)
|
||||
: CLIUtils.getOutputCodePath(filePath);
|
||||
|
||||
this.processSourceCode(content, outputCodePath);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,8 @@ export class CLIUtils {
|
||||
* @returns {string}
|
||||
*/
|
||||
public static getOutputCodePath (inputPath: string): string {
|
||||
return inputPath
|
||||
return path
|
||||
.normalize(inputPath)
|
||||
.split('.')
|
||||
.map((value: string, index: number) => {
|
||||
return index === 0 ? `${value}${JavaScriptObfuscatorCLI.obfuscatedFilePrefix}` : value;
|
||||
|
||||
@@ -18,7 +18,7 @@ export class SourceCodeReader {
|
||||
}
|
||||
|
||||
if (SourceCodeReader.isDirectoryPath(inputPath)) {
|
||||
return SourceCodeReader.readDirectory(inputPath);
|
||||
return SourceCodeReader.readDirectoryRecursive(inputPath);
|
||||
}
|
||||
|
||||
throw new ReferenceError(`Given input path must be a valid source code file or directory path`);
|
||||
@@ -50,17 +50,26 @@ export class SourceCodeReader {
|
||||
|
||||
/**
|
||||
* @param {string} directoryPath
|
||||
* @param {IFileData[]} fileData
|
||||
* @returns {IFileData[]}
|
||||
*/
|
||||
private static readDirectory (directoryPath: string): IFileData[] {
|
||||
return fs.readdirSync(directoryPath, JavaScriptObfuscatorCLI.encoding)
|
||||
.filter(SourceCodeReader.isValidFile)
|
||||
.map((fileName: string) => {
|
||||
private static readDirectoryRecursive (directoryPath: string, fileData: IFileData[] = []): IFileData[] {
|
||||
fs.readdirSync(directoryPath, JavaScriptObfuscatorCLI.encoding)
|
||||
.forEach((fileName: string) => {
|
||||
const filePath: string = `${directoryPath}/${fileName}`;
|
||||
const content: string = fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding);
|
||||
|
||||
return { filePath, content };
|
||||
if (SourceCodeReader.isDirectoryPath(filePath)) {
|
||||
fileData.push(
|
||||
...SourceCodeReader.readDirectoryRecursive(filePath)
|
||||
);
|
||||
} else if (SourceCodeReader.isFilePath(filePath) && SourceCodeReader.isValidFile(fileName)) {
|
||||
const content: string = fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding);
|
||||
|
||||
fileData.push({ filePath, content });
|
||||
}
|
||||
});
|
||||
|
||||
return fileData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user