npm-consider
Version:
Check npm package dependencies, stats and impact on your package before installing it
36 lines (33 loc) • 885 B
JavaScript
/**
* @file get install command considering package manager and arguments
*/
const testYarn = require('./testYarn');
const program = require('commander');
const isProduction = require('./isProduction');
/**
* @return {Promise.<{command: string, args: string[]}>}
*/
module.exports = function getInstallCommand() {
return testYarn().then((isYarn) => {
const command = isYarn ? `yarn` : `npm`;
const args = [];
if (command === 'npm') {
args.push(...process.argv.slice(2));
} else {
// yarn
const [nameVersion, options] = program.args;
if (nameVersion) {
args.push('add', nameVersion);
if (options.saveDev) {
args.push('--dev');
}
} else {
args.push('install');
if (isProduction()) {
args.push('--production');
}
}
}
return { command, args };
});
};