From 7b1d53520f0aa35e48b72d61d2f1a85ffdfdfec8 Mon Sep 17 00:00:00 2001 From: qxb3 Date: Sat, 14 May 2022 12:12:44 +0800 Subject: [PATCH] feat(skip): option to skip package manager selection (#20) * feat: ability to skip package manager selection * fix: add option to skip too when you dont have both pm * fix: both work on npm/yarn on skip part * fix(init): fix typo Co-authored-by: Evo <85353424+EvolutionX-10@users.noreply.github.com> --- src/commands/init.js | 6 +++++- src/prompts/init.js | 12 ++++++++++++ src/utilities/install.js | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/commands/init.js b/src/commands/init.js index aeb4b9b..d860319 100644 --- a/src/commands/init.js +++ b/src/commands/init.js @@ -9,6 +9,7 @@ import { main_dir, gitInit, which_manager, + skip_install_dep, name, } from '../prompts/init.js'; import { npm } from '../utilities/npm.js'; @@ -61,7 +62,10 @@ export async function init({ flags }) { if (pm === 'both') { const chosen = await prompt([which_manager]); choice = chosen.manager; - } else choice = pm; + } else { + const chosen = await prompt([skip_install_dep]); + choice = chosen.skip_install_dep ? pm : 'skip'; + } await installDeps(choice, data.name); await editMain(data.name); diff --git a/src/prompts/init.js b/src/prompts/init.js index 824f10c..8e38e70 100644 --- a/src/prompts/init.js +++ b/src/prompts/init.js @@ -76,9 +76,21 @@ export const which_manager = { description: 'Yarn Package Manager', value: 'yarn', }, + { + title: 'Skip', + description: 'Skip selection', + value: 'skip', + }, ], }; +export const skip_install_dep = { + name: 'skip_install_dep', + type: 'confirm', + message: `Do you want ${blueBright('me')} to install dependencies?`, + initial: false, +}; + /** * @type {import('prompts').PromptObject} */ diff --git a/src/utilities/install.js b/src/utilities/install.js index 8b1c120..0880b8b 100644 --- a/src/utilities/install.js +++ b/src/utilities/install.js @@ -26,6 +26,10 @@ export async function installDeps(choice, name) { const deps = output.dependencies; if (!deps) throw new Error("Can't find dependencies."); + if (choice === 'skip') { + return console.log('Skipped.'); + } + const spin = ora({ text: `Installing dependencies...`, spinner: 'aesthetic',