forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLIUtils.ts
More file actions
51 lines (42 loc) · 1.4 KB
/
Copy pathCLIUtils.ts
File metadata and controls
51 lines (42 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as path from 'path';
import { TDictionary } from '../../types/TDictionary';
import { StringSeparator } from '../../enums/StringSeparator';
export class CLIUtils {
/**
* @type {string[]}
*/
public static readonly allowedConfigFileExtensions: string[] = [
'.js',
'.json',
'.cjs'
];
/**
* @param {string} configPath
* @returns {TDictionary}
*/
public static getUserConfig (configPath: string): TDictionary {
let config: TDictionary;
const configFileExtension: string = path.extname(configPath);
const isValidExtension: boolean = CLIUtils.allowedConfigFileExtensions.includes(configFileExtension);
if (!isValidExtension) {
throw new ReferenceError('Given config path must be a valid `.js|.mjs|.cjs` or `.json` file path');
}
try {
config = require(configPath);
} catch {
try {
config = __non_webpack_require__(configPath);
} catch {
throw new ReferenceError(`Cannot open config file with path: ${configPath}`);
}
}
return config;
}
/**
* @param {TDictionary} optionEnum
* @returns {string}
*/
public static stringifyOptionAvailableValues (optionEnum: TDictionary): string {
return Object.values(optionEnum).join(`${StringSeparator.Comma} `);
}
}