UNPKG

ymlgen

Version:

A generator for YML/YAML files

57 lines (56 loc) 2.43 kB
export declare type AutoTrim = "start-end" | "all" | boolean; export declare type WriteOptions = StringConvertionOptions & { autoTrim?: AutoTrim; }; export declare type TemplateConfigs = { output: string; generator: string; }; export declare type ConfigResolver = (config: string, value: string) => boolean; export declare type IncludeFileReader = (dataDir: string, name: string) => {}; export declare type GeneratorFactory<T> = (generatorName: string) => Promise<TextGenerator<T>>; export declare type ProcessFileOptions<T> = { generatorWorkspaceDir: string; dataFileWorkspaceDir: string; dataFile: string; fileName: string; content: string; getGenerator: GeneratorFactory<T>; writeFile: (fileName: string, content: string) => Promise<void>; configResolver?: ConfigResolver; includeFileReader?: IncludeFileReader; }; export declare type GenerationContext = { readonly dataFile: string; readonly texts: string[]; readonly options: WriteOptions; readonly data: any; readonly rawData: any; readonly key: any; $each: typeof $each; $use: typeof $use; extends(data: unknown, extraProps?: unknown): GenerationContext; write(...values: any[]): any; configure(options: WriteOptions): void; extra(values: Record<string, any>): void; }; export declare type EachOptions<T> = { sep?: TextGenerator<T> | string; start?: TextGenerator<T> | string; end?: TextGenerator<T> | string; alt?: TextGenerator<T> | string; extra?: any; }; export declare type TextGenerator<TExtra> = (context: GenerationContext & TExtra) => void | Promise<void> | TextGenerator<any> | Promise<TextGenerator<any>>; export declare type StringConvertionOptions = {}; declare const isDataFile: (content: string) => boolean; declare const defaultIncludeFileReader: IncludeFileReader; declare const processFile: <T>({ generatorWorkspaceDir, dataFileWorkspaceDir, dataFile, content, configResolver, includeFileReader, getGenerator, fileName, writeFile, }: ProcessFileOptions<T>) => Promise<{ onDone: string; onSuccess: string; onFail: string; error: any; }>; declare const $use: <T>(data: unknown, generator: TextGenerator<T>) => (context: GenerationContext) => any; declare const $each: <T>(data: unknown, generator: TextGenerator<T>, options?: EachOptions<T>) => TextGenerator<T>; export { processFile, isDataFile, defaultIncludeFileReader };