SB-6.1-PRE

This commit is contained in:
ItzEmerald committed 2021-02-02 13:50:53 +00:00
1 parent 690169a409
commit 358a25f522
3760 files changed
+300059 -36

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
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'
];
/**
* @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` 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} `);
}
}