Skip to content

Commit

Permalink
fix: when selecting the package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Oct 1, 2022
1 parent 2e6bd76 commit cacca97
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions actions/new.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class NewAction extends AbstractAction {
const dryRunOption = options.find((option) => option.name === 'dry-run');
const isDryRunEnabled = dryRunOption && dryRunOption.value;

await askForMissingInformation(inputs);
await askForMissingInformation(inputs, options);
await generateApplicationFiles(inputs, options).catch(exit);

const shouldSkipInstall = options.some(
Expand Down Expand Up @@ -68,6 +68,9 @@ export class NewAction extends AbstractAction {
const getApplicationNameInput = (inputs: Input[]) =>
inputs.find((input) => input.name === 'name');

const getPackageManagerInput = (inputs: Input[]) =>
inputs.find((options) => options.name === 'packageManager');

const getProjectDirectory = (
applicationName: Input,
directoryOption?: Input,
Expand All @@ -78,18 +81,25 @@ const getProjectDirectory = (
);
};

const askForMissingInformation = async (inputs: Input[]) => {
const askForMissingInformation = async (inputs: Input[], options: Input[]) => {
console.info(MESSAGES.PROJECT_INFORMATION_START);
console.info();

const prompt: inquirer.PromptModule = inquirer.createPromptModule();

const nameInput = getApplicationNameInput(inputs);
if (!nameInput!.value) {
const message = 'What name would you like to use for the new project?';
const questions = [generateInput('name', message)('nest-app')];
const answers: Answers = await prompt(questions as ReadonlyArray<Question>);
replaceInputMissingInformation(inputs, answers);
}

const packageManagerInput = getPackageManagerInput(options);
if (!packageManagerInput!.value) {
const answers = await askForPackageManager();
replaceInputMissingInformation(options, answers);
}
};

const replaceInputMissingInformation = (
Expand Down

0 comments on commit cacca97

Please sign in to comment.