Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function initKnex(env, opts) {
checkLocalModule(env);
if (process.cwd() !== env.cwd) {
process.chdir(env.cwd);
console.log(
'Working directory changed to',
color.magenta(tildify(env.cwd))
);
}
if (!opts.knexfile) {
const configurationPath = resolveKnexFilePath();
const configuration = configurationPath
? require(configurationPath.path)
: undefined;
env.configuration = configuration || mkConfigObj(opts);
if (!env.configuration.ext && configurationPath) {
env.configuration.ext = configurationPath.extension;
}
}
// If knexfile is specified
else {
_getCommands() {
const commandTable = this._getSimpleTable();
this._program._commands
// don't include default command
.filter((c) => c.name() !== '' && c.visible())
.forEach(cmd => {
commandTable.push(
[c.magenta(cmd.getSynopsis()), cmd.description()]
);
});
commandTable.push([c.magenta('help '), 'Display help for a specific command']);
return c.bold('COMMANDS') + "\n\n" + colorize(commandTable.toString());
}
function resolveEnvironmentConfig(opts, allConfigs) {
const environment = opts.env || process.env.NODE_ENV || 'development';
const result = allConfigs[environment] || allConfigs;
if (allConfigs[environment]) {
console.log('Using environment:', color.magenta(environment));
}
if (!result) {
console.log(color.red('Warning: unable to read knexfile config'));
process.exit(1);
}
if (argv.debug !== undefined) {
result.debug = argv.debug;
}
return result;
}
function checkLocalModule(env) {
if (!env.modulePath) {
console.log(
color.red('No local knex install found in:'),
color.magenta(tildify(env.cwd))
);
exit('Try running: npm install knex');
}
}
cli.on('require', function(name) {
console.log('Requiring external module', color.magenta(name));
});
}).replace(//gi, (match) => {
return c.magenta(match);
}).replace(/\[([^[\]]+)\]/gi, (match) => {
return c.yellow(match);