Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.config_from_path = function(file_path) {
const config_path = path.join(process.cwd(), file_path);
let isConfigDirectory = false;
try {
let config = null;
isConfigDirectory = fs.lstatSync(config_path).isDirectory();
if (isConfigDirectory) {
config = cosmiconfigSync("linthtml", { stopDir: config_path, packageProp: "linthtmlConfig" }).search(config_path);
} else {
config = explorer.load(config_path);
}
if (config === null) {
throw new Error();
}
return config;
} catch (error) {
if (isConfigDirectory) {
throw new CustomError("CLI-01", { config_path });
// console.log(`{red Error:} Cannot read config file in directory: {underline ${config_path}}`);
}
throw new CustomError("CLI-02", { config_path });
}
};
function getConfigExporer() {
return (_configExplorer =
_configExplorer ||
// Lazy load cosmiconfig since it is a relatively large bundle
require('cosmiconfig').cosmiconfigSync('babel-plugin-macros', {
searchPlaces: [
'package.json',
'.babel-plugin-macrosrc',
'.babel-plugin-macrosrc.json',
'.babel-plugin-macrosrc.yaml',
'.babel-plugin-macrosrc.yml',
'.babel-plugin-macrosrc.js',
'babel-plugin-macros.config.js',
],
packageProp: 'babelMacros',
}))
}
function getConfigExporer() {
return (_configExplorer =
_configExplorer || // Lazy load cosmiconfig since it is a relatively large bundle
require('cosmiconfig').cosmiconfigSync('babel-plugin-macros', {
searchPlaces: [
'package.json',
'.babel-plugin-macrosrc',
'.babel-plugin-macrosrc.json',
'.babel-plugin-macrosrc.yaml',
'.babel-plugin-macrosrc.yml',
'.babel-plugin-macrosrc.js',
'babel-plugin-macros.config.js'
],
packageProp: 'babelMacros'
}))
}
search(stopDir) {
const { search } = cosmiconfig(this.namespace, { stopDir });
return search(stopDir);
}
loadPreset(context, preset) {
private loadConfig() {
const result = cosmiconfigSync('escapin').search(this.basePath);
if (result === null) {
throw new Error('config file not found.');
}
result.config.output_dir = Path.join(this.basePath, result.config.output_dir || OUTPUT_DIR);
if (fs.existsSync(result.config.output_dir)) {
rimraf(result.config.output_dir);
}
mkdirp(result.config.output_dir);
result.config.platform = result.config.platform || PLATFORM;
result.config.default_storage = result.config.default_storage || DEFAULT_STORAGE;
this.config = result.config as IConfig;
}