feat: provide sensible default title/dashedName (#53269)

pull/53276/head
Oliver Eyton-Williams 2024-01-19 02:11:44 +01:00 committed by GitHub
parent 80ed98b73b
commit 208b6efca8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 11 deletions

View File

@ -1,11 +1,35 @@
import { prompt } from 'inquirer';
import { challengeTypes } from '../../../shared/config/challenge-types';
import { getLastStep } from './get-last-step-file-number';
export const newChallengePrompts = async (): Promise<{
title: string;
dashedName: string;
challengeType: string;
}> => {
const challengeType = await prompt<{ value: string }>({
name: 'value',
message: 'What type of challenge is this?',
type: 'list',
choices: Object.entries(challengeTypes).map(([key, value]) => ({
name: key,
value
}))
});
const lastStep = getLastStep().stepNum;
const challengeTypeNum = parseInt(challengeType.value, 10);
const isTaskStep =
challengeTypeNum === challengeTypes.fillInTheBlank ||
challengeTypeNum === challengeTypes.dialogue;
const defaultTitle = isTaskStep
? `Task ${lastStep + 1}`
: `Step ${lastStep + 1}`;
const defaultDashedName = isTaskStep
? `task-${lastStep + 1}`
: `step-${lastStep + 1}`;
const dashedName = await prompt<{ value: string }>({
name: 'value',
message: 'What is the short name (in kebab-case) for this challenge?',
@ -20,21 +44,13 @@ export const newChallengePrompts = async (): Promise<{
},
filter: (block: string) => {
return block.toLowerCase();
}
},
default: defaultDashedName
});
const title = await prompt<{ value: string }>({
name: 'value',
message: 'What is the title of this challenge?',
default: (title: { value: string }) => title.value
});
const challengeType = await prompt<{ value: string }>({
name: 'value',
message: 'What type of challenge is this?',
type: 'list',
choices: Object.entries(challengeTypes).map(([key, value]) => ({
name: key,
value
}))
default: defaultTitle
});
return {