cli/new: cleanup custom options and prompt type in collection
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -18,9 +18,8 @@ import inquirer from 'inquirer';
|
||||
import { getCodeownersFilePath } from '../../codeowners';
|
||||
import { paths } from '../../paths';
|
||||
import { NewConfig } from '../types';
|
||||
import { buildCustomPrompt, getPromptsForRole, ownerPrompt } from './prompts';
|
||||
import { customPrompt, getPromptsForRole, ownerPrompt } from './prompts';
|
||||
import { NewTemplate } from '../types';
|
||||
import { Options } from '../execution/utils';
|
||||
|
||||
type CollectTemplateParamsOptions = {
|
||||
config: NewConfig;
|
||||
@@ -30,7 +29,7 @@ type CollectTemplateParamsOptions = {
|
||||
|
||||
export async function collectTemplateParams(
|
||||
options: CollectTemplateParamsOptions,
|
||||
): Promise<Options> {
|
||||
): Promise<Record<string, string | number | boolean>> {
|
||||
const { config, template, prefilledParams } = options;
|
||||
|
||||
const codeOwnersFilePath = await getCodeownersFilePath(paths.targetRoot);
|
||||
@@ -41,13 +40,13 @@ export async function collectTemplateParams(
|
||||
prompts.push(ownerPrompt());
|
||||
}
|
||||
if (template.prompts) {
|
||||
prompts.push(...template.prompts.map(buildCustomPrompt));
|
||||
prompts.push(...template.prompts.map(customPrompt));
|
||||
}
|
||||
|
||||
const needsAnswer = [];
|
||||
const prefilledAnswers = {} as Record<string, string | number | boolean>;
|
||||
for (const prompt of prompts) {
|
||||
if (prefilledParams[prompt.name] !== undefined) {
|
||||
if (prompt.name && prefilledParams[prompt.name] !== undefined) {
|
||||
prefilledAnswers[prompt.name] = prefilledParams[prompt.name];
|
||||
} else {
|
||||
needsAnswer.push(prompt);
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Answers, DistinctQuestion } from 'inquirer';
|
||||
import { DistinctQuestion } from 'inquirer';
|
||||
import { NewTemplatePrompt, TemplateRole } from '../types';
|
||||
import { parseOwnerIds } from '../../codeowners';
|
||||
|
||||
export type Prompt<TOptions extends Answers> = DistinctQuestion<TOptions>;
|
||||
export function namePrompt(): Prompt<{ name: string }> {
|
||||
export function namePrompt(): DistinctQuestion {
|
||||
return {
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
@@ -35,7 +34,7 @@ export function namePrompt(): Prompt<{ name: string }> {
|
||||
};
|
||||
}
|
||||
|
||||
export function pluginIdPrompt(): Prompt<{ pluginId: string }> {
|
||||
export function pluginIdPrompt(): DistinctQuestion {
|
||||
return {
|
||||
type: 'input',
|
||||
name: 'pluginId',
|
||||
@@ -51,7 +50,7 @@ export function pluginIdPrompt(): Prompt<{ pluginId: string }> {
|
||||
};
|
||||
}
|
||||
|
||||
export function moduleIdIdPrompt(): Prompt<{ moduleId: string }> {
|
||||
export function moduleIdIdPrompt(): DistinctQuestion {
|
||||
return {
|
||||
type: 'input',
|
||||
name: 'moduleId',
|
||||
@@ -67,7 +66,7 @@ export function moduleIdIdPrompt(): Prompt<{ moduleId: string }> {
|
||||
};
|
||||
}
|
||||
|
||||
export function getPromptsForRole(role: TemplateRole) {
|
||||
export function getPromptsForRole(role: TemplateRole): Array<DistinctQuestion> {
|
||||
switch (role) {
|
||||
case 'web-library':
|
||||
case 'node-library':
|
||||
@@ -87,7 +86,7 @@ export function getPromptsForRole(role: TemplateRole) {
|
||||
}
|
||||
}
|
||||
|
||||
export function ownerPrompt(): Prompt<{ owner?: string }> {
|
||||
export function ownerPrompt(): DistinctQuestion {
|
||||
return {
|
||||
type: 'input',
|
||||
name: 'owner',
|
||||
@@ -107,9 +106,7 @@ export function ownerPrompt(): Prompt<{ owner?: string }> {
|
||||
};
|
||||
}
|
||||
|
||||
export function buildCustomPrompt(
|
||||
prompt: NewTemplatePrompt,
|
||||
): Prompt<{ [key: string]: string }> {
|
||||
export function customPrompt(prompt: NewTemplatePrompt): DistinctQuestion {
|
||||
return {
|
||||
type: 'input',
|
||||
name: prompt.id,
|
||||
|
||||
@@ -29,12 +29,11 @@ import { executePluginPackageTemplate } from './executePluginPackageTemplate';
|
||||
import { TemporaryDirectoryManager } from './TemporaryDirectoryManager';
|
||||
import { NewConfig } from '../types';
|
||||
import { NewTemplate } from '../types';
|
||||
import { Options } from './utils';
|
||||
|
||||
type ExecuteNewTemplateOptions = {
|
||||
config: NewConfig;
|
||||
template: NewTemplate;
|
||||
params: Options;
|
||||
params: Record<string, string | number | boolean>;
|
||||
};
|
||||
|
||||
export async function executeNewTemplate(options: ExecuteNewTemplateOptions) {
|
||||
|
||||
@@ -15,15 +15,6 @@
|
||||
*/
|
||||
import { NewTemplate } from '../types';
|
||||
|
||||
export interface Options extends Record<string, string | boolean> {
|
||||
private: boolean;
|
||||
baseVersion: string;
|
||||
license: string;
|
||||
targetPath: string;
|
||||
owner: string;
|
||||
scope: string;
|
||||
}
|
||||
|
||||
export const resolvePackageName = (options: {
|
||||
baseName: string;
|
||||
scope?: string;
|
||||
|
||||
Reference in New Issue
Block a user