import type CoreGenerator from './index.ts'; export type EditFileCallback = (this: Generator, content: string, filePath: string) => string; export type EditFileOptions = { create?: boolean; ignoreNonExisting?: boolean | string; assertModified?: boolean; autoCrlf?: boolean }; export type CascatedEditFileCallback = ( ...callbacks: EditFileCallback[] ) => CascatedEditFileCallback; type DataCallback = Type | ((this: Generator, data: DataType) => Type); export type WriteFileTemplate = | string | ((this: Generator, data: DataType) => string) | { condition?: DataCallback; /** source file */ sourceFile?: DataCallback; /** destination file */ destinationFile?: DataCallback; /** @deprecated, use sourceFile instead */ file?: DataCallback; /** @deprecated, use destinationFile instead */ renameTo?: string | ((this: Generator, data: DataType) => string); /** transforms (files processing) to be applied */ transform?: boolean | (() => string)[]; /** binary files skips ejs render, ejs extension and file transform */ binary?: boolean; /** ejs options. Refer to https://ejs.co/#docs */ options?: Record; override?: DataCallback; }; export type WriteFileBlock = { /** relative path were sources are placed */ from?: ((this: Generator, data: DataType) => string) | string; /** relative path were the files should be written, fallbacks to from/path */ to?: ((this: Generator, data: DataType) => string) | string; path?: ((this: Generator, data: DataType) => string) | string; /** generate destinationFile based on sourceFile */ renameTo?: (this: Generator, data: DataType, filePath: string) => string; /** condition to enable to write the block */ condition?: (this: Generator, data: DataType) => boolean | undefined; /** transforms (files processing) to be applied */ transform?: boolean | (() => string)[]; templates: WriteFileTemplate[]; }; export type WriteFileSection = Record[]>; export type WriteFileOptions = { /** transforms (files processing) to be applied */ transform?: EditFileCallback[]; /** context to be used as template data */ context?: any; /** config passed to render methods */ renderOptions?: Record; /** * path(s) to look for templates. * Single absolute path or relative path(s) between the templates folder and template path. */ rootTemplatesPath?: string | string[]; /** @experimental Customize templates sourceFile and destinationFile */ customizeTemplatePath?: (file: { sourceFile: string; resolvedSourceFile: string; destinationFile: string; }) => undefined | { sourceFile: string; resolvedSourceFile: string; destinationFile: string }; } & ( | { sections: WriteFileSection & { _?: { transform?: (() => string)[] } }; } | { /** templates to be written */ templates: WriteFileTemplate[]; } | { /** blocks to be written */ blocks: WriteFileBlock[]; } ); export type ValidationResult = { debug?: unknown; info?: string | string[]; warning?: string | string[]; error?: string | string[]; }; export type WriteContext = { /** Customize templates sourceFile and destinationFile */ customizeTemplatePaths: (( this: CoreGenerator, file: { namespace: string; sourceFile: string; resolvedSourceFile: string; destinationFile: string; templatesRoots: string[]; }, context: any, ) => undefined | { sourceFile: string; resolvedSourceFile: string; destinationFile: string; templatesRoots: string[] })[]; };