import type { TemplateNormalized } from './config.ts' import type { Arrayable, Awaitable } from '@antfu/utils' import type { DownloadTemplateOptions } from 'giget' export interface ProjectInfo { url: string folderName: string path: string variables: Record git?: { getName: () => Promise getEmail: () => Promise } } export interface Context { project: ProjectInfo template: TemplateNormalized } export interface ConfigGit { /** @default true */ init?: boolean /** @default false */ add?: boolean } export type ConfigReplaceFrom = Arrayable export type ConfigReplaceFromCallback = ( options: { file: string } & Context, ) => ConfigReplaceFrom export type ConfigReplaceTo = Arrayable export type ConfigReplaceToCallback = ( options: { match: string file: string } & Context, ) => string export interface ConfigReplace { include?: Arrayable exclude?: Arrayable from: ConfigReplaceFrom | ConfigReplaceFromCallback to: ConfigReplaceTo | ConfigReplaceToCallback /** @default true */ all?: boolean /** @default false */ ignoreCase?: boolean } export interface Choice { value: string label?: string hint?: string } export type ConfigVariable = { message: string; initial?: string } & ( | { type: 'text' required?: boolean placeholder?: Callbackable } | { type: 'select'; choices: string[] | Choice[] } ) export type Callbackable = Awaitable | ((ctx: Context) => Awaitable) export interface ConfigTemplate { name: string color?: string children?: ConfigTemplate[] /** * Format: [provider]:repo[/subpath][#ref] * * See also https://github.com/unjs/giget#downloadtemplatesource-options */ url?: string giget?: DownloadTemplateOptions git?: { /** @default true */ init?: boolean /** @default false */ add?: boolean name?: string email?: string } variables?: Callbackable> replaces?: | ({ items: Arrayable> } & Partial) | ConfigReplace[] commands?: Callbackable> cwd?: string } export interface Config extends Pick< ConfigTemplate, 'git' | 'replaces' | 'variables' | 'commands' | 'cwd' > { templates?: Arrayable }