From 208b6efca875c1804259ae2dd98196398771e589 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Fri, 19 Jan 2024 02:11:44 +0100 Subject: [PATCH] feat: provide sensible default title/dashedName (#53269) --- .../helpers/new-challenge-prompts.ts | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/tools/challenge-helper-scripts/helpers/new-challenge-prompts.ts b/tools/challenge-helper-scripts/helpers/new-challenge-prompts.ts index c595c69c379..265cb475d8d 100644 --- a/tools/challenge-helper-scripts/helpers/new-challenge-prompts.ts +++ b/tools/challenge-helper-scripts/helpers/new-challenge-prompts.ts @@ -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 {