You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
const { prompt } = require('enquirer');
|
|
const { green } = require('colorette');
|
|
const { runCommand } = require('./run-command');
|
|
const { getPackageManager } = require('./get-package-manager');
|
|
const { packageExists } = require('./package-exists');
|
|
|
|
/**
|
|
*
|
|
* @param packageName
|
|
* @param preMessage Message to show before the question
|
|
*/
|
|
async function promptInstallation(packageName, preMessage) {
|
|
const packageManager = getPackageManager();
|
|
const options = [packageManager === 'yarn' ? 'add' : 'install', '-D', packageName];
|
|
|
|
const commandToBeRun = `${packageManager} ${options.join(' ')}`;
|
|
if (preMessage) {
|
|
preMessage();
|
|
}
|
|
const question = `Would you like to install ${packageName}? (That will run ${green(commandToBeRun)})`;
|
|
const { installConfirm } = await prompt([
|
|
{
|
|
type: 'confirm',
|
|
name: 'installConfirm',
|
|
message: question,
|
|
initial: 'Y',
|
|
},
|
|
]);
|
|
if (installConfirm) {
|
|
await runCommand(commandToBeRun);
|
|
return packageExists(packageName);
|
|
}
|
|
|
|
process.exitCode = 2;
|
|
}
|
|
|
|
module.exports = {
|
|
promptInstallation,
|
|
};
|
|
|