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>
This commit is contained in:
qxb3
2022-05-14 12:12:44 +08:00
committed by GitHub
parent b366cb4af4
commit 7b1d53520f
3 changed files with 21 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import {
main_dir, main_dir,
gitInit, gitInit,
which_manager, which_manager,
skip_install_dep,
name, name,
} from '../prompts/init.js'; } from '../prompts/init.js';
import { npm } from '../utilities/npm.js'; import { npm } from '../utilities/npm.js';
@@ -61,7 +62,10 @@ export async function init({ flags }) {
if (pm === 'both') { if (pm === 'both') {
const chosen = await prompt([which_manager]); const chosen = await prompt([which_manager]);
choice = chosen.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 installDeps(choice, data.name);
await editMain(data.name); await editMain(data.name);

View File

@@ -76,9 +76,21 @@ export const which_manager = {
description: 'Yarn Package Manager', description: 'Yarn Package Manager',
value: 'yarn', 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} * @type {import('prompts').PromptObject}
*/ */

View File

@@ -26,6 +26,10 @@ export async function installDeps(choice, name) {
const deps = output.dependencies; const deps = output.dependencies;
if (!deps) throw new Error("Can't find dependencies."); if (!deps) throw new Error("Can't find dependencies.");
if (choice === 'skip') {
return console.log('Skipped.');
}
const spin = ora({ const spin = ora({
text: `Installing dependencies...`, text: `Installing dependencies...`,
spinner: 'aesthetic', spinner: 'aesthetic',