Skip to content

Commit

Permalink
refactor: remove dead code on new action packages installation
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Oct 1, 2022
1 parent cacca97 commit 11d551b
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions actions/new.action.ts
Expand Up @@ -144,9 +144,7 @@ const installPackages = async (
dryRunMode: boolean,
installDirectory: string,
) => {
const inputPackageManager: string = options.find(
(option) => option.name === 'packageManager',
)!.value as string;
const inputPackageManager = getPackageManagerInput(options)!.value as string;

let packageManager: AbstractPackageManager;
if (dryRunMode) {
Expand All @@ -155,29 +153,16 @@ const installPackages = async (
console.info();
return;
}
if (inputPackageManager !== undefined) {
try {
packageManager = PackageManagerFactory.create(inputPackageManager);
await packageManager.install(installDirectory, inputPackageManager);
} catch (error) {
if (error && error.message) {
console.error(chalk.red(error.message));
}
try {
packageManager = PackageManagerFactory.create(inputPackageManager);
await packageManager.install(installDirectory, inputPackageManager);
} catch (error) {
if (error && error.message) {
console.error(chalk.red(error.message));
}
} else {
packageManager = await selectPackageManager();
await packageManager.install(
installDirectory,
packageManager.name.toLowerCase(),
);
}
};

const selectPackageManager = async (): Promise<AbstractPackageManager> => {
const answers: Answers = await askForPackageManager();
return PackageManagerFactory.create(answers['packageManager']);
};

const askForPackageManager = async (): Promise<Answers> => {
const questions: Question[] = [
generateSelect('packageManager')(MESSAGES.PACKAGE_MANAGER_QUESTION)([
Expand Down

0 comments on commit 11d551b

Please sign in to comment.