cli/new: define params type
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
selectTemplateInteractively,
|
||||
} from './preparation';
|
||||
import { executePortableTemplate } from './execution';
|
||||
import { PortableTemplateParams } from './types';
|
||||
|
||||
export type CreateNewPackageOptions = {
|
||||
preselectedTemplateId?: string;
|
||||
@@ -31,7 +32,7 @@ export type CreateNewPackageOptions = {
|
||||
license?: string;
|
||||
baseVersion?: string;
|
||||
};
|
||||
prefilledParams: Record<string, string>;
|
||||
prefilledParams: PortableTemplateParams;
|
||||
};
|
||||
|
||||
export async function createNewPackage(options: CreateNewPackageOptions) {
|
||||
|
||||
@@ -27,13 +27,13 @@ import { createDirName, resolvePackageName } from './utils';
|
||||
import { runAdditionalActions } from './additionalActions';
|
||||
import { executePluginPackageTemplate } from './executePluginPackageTemplate';
|
||||
import { TemporaryDirectoryManager } from './TemporaryDirectoryManager';
|
||||
import { PortableTemplateConfig } from '../types';
|
||||
import { PortableTemplateConfig, PortableTemplateParams } from '../types';
|
||||
import { PortableTemplate } from '../types';
|
||||
|
||||
type ExecuteNewTemplateOptions = {
|
||||
config: PortableTemplateConfig;
|
||||
template: PortableTemplate;
|
||||
params: Record<string, string | number | boolean>;
|
||||
params: PortableTemplateParams;
|
||||
};
|
||||
|
||||
export async function executePortableTemplate(
|
||||
|
||||
@@ -19,6 +19,7 @@ import { getCodeownersFilePath, parseOwnerIds } from '../../codeowners';
|
||||
import { paths } from '../../paths';
|
||||
import {
|
||||
PortableTemplateConfig,
|
||||
PortableTemplateParams,
|
||||
PortableTemplatePrompt,
|
||||
PortableTemplateRole,
|
||||
} from '../types';
|
||||
@@ -27,12 +28,12 @@ import { PortableTemplate } from '../types';
|
||||
type CollectTemplateParamsOptions = {
|
||||
config: PortableTemplateConfig;
|
||||
template: PortableTemplate;
|
||||
prefilledParams: Record<string, string | number | boolean>;
|
||||
prefilledParams: PortableTemplateParams;
|
||||
};
|
||||
|
||||
export async function collectPortableTemplateParams(
|
||||
options: CollectTemplateParamsOptions,
|
||||
): Promise<Record<string, string | number | boolean>> {
|
||||
): Promise<PortableTemplateParams> {
|
||||
const { config, template, prefilledParams } = options;
|
||||
|
||||
const codeOwnersFilePath = await getCodeownersFilePath(paths.targetRoot);
|
||||
@@ -47,7 +48,7 @@ export async function collectPortableTemplateParams(
|
||||
}
|
||||
|
||||
const needsAnswer = [];
|
||||
const prefilledAnswers = {} as Record<string, string | number | boolean>;
|
||||
const prefilledAnswers = {} as PortableTemplateParams;
|
||||
for (const prompt of prompts) {
|
||||
if (prompt.name && prefilledParams[prompt.name] !== undefined) {
|
||||
prefilledAnswers[prompt.name] = prefilledParams[prompt.name];
|
||||
@@ -56,9 +57,9 @@ export async function collectPortableTemplateParams(
|
||||
}
|
||||
}
|
||||
|
||||
const promptAnswers = await inquirer.prompt<
|
||||
Record<string, string | number | boolean>
|
||||
>(needsAnswer);
|
||||
const promptAnswers = await inquirer.prompt<PortableTemplateParams>(
|
||||
needsAnswer,
|
||||
);
|
||||
|
||||
return {
|
||||
...config.globals,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import fs from 'fs-extra';
|
||||
import { paths } from '../../paths';
|
||||
import { defaultTemplates } from '../defaultTemplates';
|
||||
import { PortableTemplateConfig } from '../types';
|
||||
import { PortableTemplateConfig, PortableTemplateParams } from '../types';
|
||||
import { z } from 'zod';
|
||||
import { fromZodError } from 'zod-validation-error';
|
||||
import { ForwardedError } from '@backstage/errors';
|
||||
@@ -55,7 +55,7 @@ const pkgJsonWithNewConfigSchema = z.object({
|
||||
|
||||
type LoadConfigOptions = {
|
||||
packagePath?: string;
|
||||
globalOverrides?: Record<string, string | number | boolean>;
|
||||
globalOverrides?: PortableTemplateParams;
|
||||
};
|
||||
|
||||
export async function loadPortableTemplateConfig(
|
||||
|
||||
@@ -60,7 +60,7 @@ export const TEMPLATE_ROLES = [
|
||||
|
||||
export type PortableTemplateRole = (typeof TEMPLATE_ROLES)[number];
|
||||
|
||||
export interface PortableTemplate {
|
||||
export type PortableTemplate = {
|
||||
id: string;
|
||||
description?: string;
|
||||
templatePath: string;
|
||||
@@ -68,4 +68,8 @@ export interface PortableTemplate {
|
||||
role: PortableTemplateRole;
|
||||
prompts?: PortableTemplatePrompt[];
|
||||
additionalActions?: string[];
|
||||
}
|
||||
};
|
||||
|
||||
export type PortableTemplateParams = {
|
||||
[KName in string]?: string | number | boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user