diff --git a/packages/cli/src/lib/new/collection/collectPortableTemplateParams.ts b/packages/cli/src/lib/new/collection/collectPortableTemplateParams.ts deleted file mode 100644 index 1048ad39f2..0000000000 --- a/packages/cli/src/lib/new/collection/collectPortableTemplateParams.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2025 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import inquirer from 'inquirer'; -import { getCodeownersFilePath } from '../../codeowners'; -import { paths } from '../../paths'; -import { PortableTemplateConfig } from '../types'; -import { customPrompt, getPromptsForRole, ownerPrompt } from './prompts'; -import { PortableTemplate } from '../types'; - -type CollectTemplateParamsOptions = { - config: PortableTemplateConfig; - template: PortableTemplate; - prefilledParams: Record; -}; - -export async function collectPortableTemplateParams( - options: CollectTemplateParamsOptions, -): Promise> { - const { config, template, prefilledParams } = options; - - const codeOwnersFilePath = await getCodeownersFilePath(paths.targetRoot); - - const prompts = getPromptsForRole(template.role); - - if (codeOwnersFilePath) { - prompts.push(ownerPrompt()); - } - if (template.prompts) { - prompts.push(...template.prompts.map(customPrompt)); - } - - const needsAnswer = []; - const prefilledAnswers = {} as Record; - for (const prompt of prompts) { - if (prompt.name && prefilledParams[prompt.name] !== undefined) { - prefilledAnswers[prompt.name] = prefilledParams[prompt.name]; - } else { - needsAnswer.push(prompt); - } - } - - const promptAnswers = await inquirer.prompt< - Record - >(needsAnswer); - - return { - ...config.globals, - ...prefilledAnswers, - ...promptAnswers, - targetPath: template.targetPath, - }; -} diff --git a/packages/cli/src/lib/new/createNewPackage.ts b/packages/cli/src/lib/new/createNewPackage.ts index 200ee475b0..9a4ea6a6e3 100644 --- a/packages/cli/src/lib/new/createNewPackage.ts +++ b/packages/cli/src/lib/new/createNewPackage.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { collectPortableTemplateParams } from './collection/collectPortableTemplateParams'; +import { collectPortableTemplateParams } from './preparation/collectPortableTemplateParams'; import { loadPortableTemplateConfig } from './preparation/loadPortableTemplateConfig'; import { executePortableTemplate } from './execution/executePortableTemplate'; import { selectTemplateInteractively } from './preparation/selectTemplateInteractively'; diff --git a/packages/cli/src/lib/new/collection/collectPortableTemplateParams.test.ts b/packages/cli/src/lib/new/preparation/collectPortableTemplateParams.test.ts similarity index 100% rename from packages/cli/src/lib/new/collection/collectPortableTemplateParams.test.ts rename to packages/cli/src/lib/new/preparation/collectPortableTemplateParams.test.ts diff --git a/packages/cli/src/lib/new/collection/prompts.ts b/packages/cli/src/lib/new/preparation/collectPortableTemplateParams.ts similarity index 71% rename from packages/cli/src/lib/new/collection/prompts.ts rename to packages/cli/src/lib/new/preparation/collectPortableTemplateParams.ts index 12c9965ea4..865266f8ec 100644 --- a/packages/cli/src/lib/new/collection/prompts.ts +++ b/packages/cli/src/lib/new/preparation/collectPortableTemplateParams.ts @@ -1,5 +1,5 @@ /* - * Copyright 2021 The Backstage Authors + * Copyright 2025 The Backstage Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,59 @@ * limitations under the License. */ -import { DistinctQuestion } from 'inquirer'; -import { PortableTemplatePrompt, PortableTemplateRole } from '../types'; -import { parseOwnerIds } from '../../codeowners'; +import inquirer, { DistinctQuestion } from 'inquirer'; +import { getCodeownersFilePath, parseOwnerIds } from '../../codeowners'; +import { paths } from '../../paths'; +import { + PortableTemplateConfig, + PortableTemplatePrompt, + PortableTemplateRole, +} from '../types'; +import { PortableTemplate } from '../types'; + +type CollectTemplateParamsOptions = { + config: PortableTemplateConfig; + template: PortableTemplate; + prefilledParams: Record; +}; + +export async function collectPortableTemplateParams( + options: CollectTemplateParamsOptions, +): Promise> { + const { config, template, prefilledParams } = options; + + const codeOwnersFilePath = await getCodeownersFilePath(paths.targetRoot); + + const prompts = getPromptsForRole(template.role); + + if (codeOwnersFilePath) { + prompts.push(ownerPrompt()); + } + if (template.prompts) { + prompts.push(...template.prompts.map(customPrompt)); + } + + const needsAnswer = []; + const prefilledAnswers = {} as Record; + for (const prompt of prompts) { + if (prompt.name && prefilledParams[prompt.name] !== undefined) { + prefilledAnswers[prompt.name] = prefilledParams[prompt.name]; + } else { + needsAnswer.push(prompt); + } + } + + const promptAnswers = await inquirer.prompt< + Record + >(needsAnswer); + + return { + ...config.globals, + ...prefilledAnswers, + ...promptAnswers, + targetPath: template.targetPath, + }; +} export function namePrompt(): DistinctQuestion { return {