feat: provide sensible default title/dashedName (#53269)
parent
80ed98b73b
commit
208b6efca8
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue