Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function resolvePlugin(...paths: string[]) {
const callerPath = filesystem.path(
process.cwd(),
nodeModulesPath,
...paths,
);
if (fsExists(callerPath)) {
const realPath = fs.realpathSync(callerPath);
return filesystem.path(realPath, distPath);
}
const scriptPath = filesystem.path(
__dirname,
"../../../../../", // Back out of @pixeloven/cli/dist/lib
...paths,
);
if (fsExists(scriptPath)) {
const realPath = fs.realpathSync(scriptPath);
return filesystem.path(realPath, distPath);
}
return false;
}
* @param plugins
*/
function addPlugins(plugins: string[]) {
plugins.forEach(plugin => {
if (plugin.includes("cli-addon")) {
builder.plugin(
filesystem.path(fs.realpathSync(plugin), "./dist/lib"),
);
}
});
}
/**
* Get plugins in the callers path
*/
const callingPath = filesystem.path(
process.cwd(),
"./node_modules",
"@pixeloven",
);
const callingPathPlugins = filesystem.subdirectories(callingPath);
addPlugins(callingPathPlugins);
/**
* Get plugins in the script path
*/
const scriptPath = filesystem.path(
__dirname,
"../../../", // Back out of cli/dist/lib
);
const scriptPathPlugins = filesystem.subdirectories(scriptPath);
addPlugins(scriptPathPlugins);
function getConfigPath(fileName: string, strict: boolean = false) {
const configPath = filesystem.path(fileName);
if (filesystem.exists(configPath)) {
print.info(`Configuration file found ${configPath}`);
return configPath;
}
if (strict) {
throw new FileNotFoundException(`File not found ${configPath}`);
} else {
print.warning(
`Unable to find "${fileName}" reverting to default configuration`,
);
}
return false;
}