/** Project creation is executable product code, shared by its CLI and the host. */ export interface ProductCreateRequest { name: string; targetDir: string; /** A starter the product offers (its `templates`), or none for its default. */ template?: string; /** One of the product's example projects (its `examples`), in place of a template. */ example?: string; } export interface ProductCreateResult { targetDir: string; manifest: unknown; } /** A starter or an example a product creates, as a picker lists it. */ interface ProductCreateChoice { readonly id: string; readonly name: string; readonly description?: string; } export interface ProductCreateDeclaration { readonly product: string; /** The starters a new project begins from. */ readonly templates: readonly ProductCreateChoice[]; /** Finished projects to learn from, each made whole (`create --example `). */ readonly examples?: readonly ProductCreateChoice[]; create(request: ProductCreateRequest): Promise; } export function assertProductCreateDeclaration(value: unknown, source: string): ProductCreateDeclaration { const declaration = value as Partial | null; const choices = (list: unknown): boolean => Array.isArray(list) && !list.some(t => typeof t?.id !== 'string' || typeof t?.name !== 'string'); if (!declaration || typeof declaration.product !== 'string' || typeof declaration.create !== 'function' || !choices(declaration.templates) || (declaration.examples !== undefined && !choices(declaration.examples))) { throw new Error(`${source}: expected a product, templates (and any examples) and create(request) function`); } return declaration as ProductCreateDeclaration; }