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.sync = (filename, opts) => {
opts = opts || {};
let dir = path.resolve(opts.cwd || '');
const root = path.parse(dir).root;
const filenames = [].concat(filename);
// eslint-disable-next-line no-constant-condition
while (true) {
const file = locatePath.sync(filenames, {cwd: dir});
if (file) {
return path.join(dir, file);
} else if (dir === root) {
return null;
}
dir = path.dirname(dir);
}
};
let configPath;
let config = {};
if (pkgPath) {
/*
* package.json exists, load it and look for a config file.
* Custom config file names can be specified using
* the `fractal.cli.config` property in the package.json
*/
const pkg = require(pkgPath);
const pkgConfig = pkg.fractal;
const fileNames = toArray(get(pkgConfig || {}, 'cli.config', opts.config));
const filePaths = fileNames.map(p => join(process.cwd(), p.replace(/^\.\//, '')));
configPath = locatePath.sync(filePaths);
if (!configPath && pkgConfig) {
configPath = join(process.cwd(), 'package.json');
config = pkgConfig;
debug(`no config file found, using config from package.json`);
} else if (configPath) {
debug(`config file found: %s`, configPath);
config = require(configPath);
debug(`config file read OK`);
} else {
/* istanbul ignore next */
debug(`no config file found, looked for %s`, fileNames.join(', '));
}
}
return {configPath, config};
// Relative to node_modules in cwd (also makes test easier)
path.join(
cwd,
"node_modules/@elasticprojects/abstract-cli/bin/abstract-cli"
),
// macOS App
"/Applications/Abstract.app/Contents/Resources/app.asar.unpacked/node_modules/@elasticprojects/abstract-cli/bin/abstract-cli"
],
apiUrl = "https://api.goabstract.com"
}: Options = {}) {
this.cwd = cwd;
this._optionAccessToken = accessToken;
this.apiUrl = apiUrl;
try {
this.cliPath = path.resolve(cwd, locatePath.sync(cliPath));
} catch (error) {
throw new Error(`Cannot find abstract-cli in "${cliPath.join(":")}"`);
}
}
module.exports.sync = (filename, opts) => {
opts = opts || {};
let dir = path.resolve(opts.cwd || '');
const root = path.parse(dir).root;
const filenames = [].concat(filename);
// eslint-disable-next-line no-constant-condition
while (true) {
const file = locatePath.sync(filenames, {cwd: dir});
if (file) {
return path.join(dir, file);
} else if (dir === root) {
return null;
}
dir = path.dirname(dir);
}
};
const runMatcher = locateOptions => {
if (typeof name !== 'function') {
return locatePath.sync(paths, locateOptions);
}
const foundPath = name(locateOptions.cwd);
if (typeof foundPath === 'string') {
return locatePath.sync([foundPath], locateOptions);
}
return foundPath;
};
const runMatcher = locateOptions => {
if (typeof name !== 'function') {
return locatePath.sync(paths, locateOptions);
}
const foundPath = name(locateOptions.cwd);
if (typeof foundPath === 'string') {
return locatePath.sync([foundPath], locateOptions);
}
return foundPath;
};