yeoman-generator
Version:
Rails-inspired generator system that provides scaffolding for your apps
177 lines (176 loc) • 11.2 kB
TypeScript
import { type MemFsEditor } from 'mem-fs-editor';
import type { BaseGenerator } from '../generator.js';
import type { PathOptions } from '../types.js';
type CopyOptions = NonNullable<Parameters<MemFsEditor['copy']>[2]>;
type CopyAsyncOptions = NonNullable<Parameters<MemFsEditor['copyAsync']>[2]>;
type WriteOptions = NonNullable<Parameters<MemFsEditor['write']>[2]>;
type WriteJSONParameters = Parameters<MemFsEditor['writeJSON']>;
type WriteJSONReplacer = WriteJSONParameters[2];
type WriteJSONSpace = WriteJSONParameters[3];
type WriteJSONOptions = WriteOptions & PathOptions & {
replacer?: WriteJSONReplacer;
space?: WriteJSONSpace;
};
type DeleteOptions = NonNullable<Parameters<MemFsEditor['delete']>[1]>;
type CopyTplOptions = NonNullable<Parameters<MemFsEditor['copyTpl']>[3]>;
type CopyTplAsyncOptions = NonNullable<Parameters<MemFsEditor['copyTplAsync']>[3]>;
export type Template<G, C extends 'copyTplAsync' | 'copyTpl', D extends NonNullable<Parameters<MemFsEditor[C]>[2]>> = {
/**
* Template file, relative to templatePath(), or absolute inside the source root (outside when the `allowTemplatesOutsideRoot` feature is enabled, inside the generator package when the `allowPackageTemplates` feature is enabled).
*/
source: string;
/**
* Conditional if the template should be written.
* @param TemplateData
* @param Generator
* @returns
*/
when?: (data: D, generator: G) => boolean;
/**
* Destination, relative to destinationPath(), or absolute inside the destination root (outside when the `allowDestinationOutsideRoot` feature is enabled).
*/
destination?: string;
/**
* Mem-fs-editor copy options, `allowOutsideRoot` applies to both source and destination.
*/
copyOptions?: NonNullable<Parameters<MemFsEditor[C]>[3]> & PathOptions;
/**
* Ejs data
*/
templateData?: string | D;
};
export type Templates<G, C extends 'copyTplAsync' | 'copyTpl', D extends NonNullable<Parameters<MemFsEditor[C]>[2]>> = Array<Template<G, C, D>>;
export declare class FsMixin {
fs: MemFsEditor;
/**
* Read file from templates folder.
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.read(this.templatePath(filepath))
*/
readTemplate(this: BaseGenerator, filepath: string, options?: PathOptions): string;
readTemplate<const DefaultType extends string | null>(this: BaseGenerator, filepath: string, options: {
raw?: false;
defaults: DefaultType;
} & PathOptions): string | DefaultType;
readTemplate(this: BaseGenerator, filepath: string, options: {
raw: true;
defaults?: never;
} & PathOptions): Buffer;
readTemplate<const DefaultType extends Buffer | null>(this: BaseGenerator, filepath: string, options: {
raw: true;
defaults: DefaultType;
} & PathOptions): Buffer | DefaultType;
/**
* Copy file from templates folder to destination folder.
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.copy(this.templatePath(from), this.destinationPath(to))
*/
copyTemplate(this: BaseGenerator, ...args: [from: string | string[], to: string, options?: CopyOptions & PathOptions]): ReturnType<MemFsEditor['copy']>;
/**
* Copy file from templates folder to destination folder.
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.copy(this.templatePath(from), this.destinationPath(to))
*/
copyTemplateAsync(this: BaseGenerator, ...args: [from: string | string[], to: string, options?: CopyAsyncOptions & PathOptions]): ReturnType<MemFsEditor['copyAsync']>;
/**
* Read file from destination folder
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.read(this.destinationPath(filepath)).
*/
readDestination(this: BaseGenerator, filepath: string, options?: PathOptions): string;
readDestination<const DefaultType extends string | null>(this: BaseGenerator, filepath: string, options: {
raw?: false;
defaults: DefaultType;
} & PathOptions): string | DefaultType;
readDestination(this: BaseGenerator, filepath: string, options: {
raw: true;
defaults?: never;
} & PathOptions): Buffer;
readDestination<const DefaultType extends Buffer | null>(this: BaseGenerator, filepath: string, options: {
raw: true;
defaults: DefaultType;
} & PathOptions): Buffer | DefaultType;
/**
* Read JSON file from destination folder
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.readJSON(this.destinationPath(filepath)).
*/
readDestinationJSON(this: BaseGenerator, filepath: string, defaults?: undefined, options?: PathOptions): object | undefined;
readDestinationJSON<T>(this: BaseGenerator, filepath: string, defaults: T, options?: PathOptions): object | T;
/**
* Write file to destination folder
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.write(this.destinationPath(filepath)).
*/
writeDestination(this: BaseGenerator, ...args: [filepath: string, contents: string | Buffer, options?: WriteOptions & PathOptions]): ReturnType<MemFsEditor['write']>;
/**
* Write json file to destination folder
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.writeJSON(this.destinationPath(filepath)).
*/
writeDestinationJSON(this: BaseGenerator, filepath: string, contents: unknown, options?: WriteJSONOptions): ReturnType<MemFsEditor['writeJSON']>;
writeDestinationJSON(this: BaseGenerator, filepath: string, contents: unknown, replacer?: WriteJSONReplacer, space?: WriteJSONSpace, options?: WriteOptions & PathOptions): ReturnType<MemFsEditor['writeJSON']>;
/**
* Delete file from destination folder
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.delete(this.destinationPath(filepath)).
*/
deleteDestination(this: BaseGenerator, ...args: [paths: string | string[], options?: DeleteOptions & PathOptions]): ReturnType<MemFsEditor['delete']>;
/**
* Copy file from destination folder to another destination folder.
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.copy(this.destinationPath(from), this.destinationPath(to)).
*/
copyDestination(this: BaseGenerator, ...args: [from: string | string[], to: string, options?: CopyOptions & PathOptions]): ReturnType<MemFsEditor['copy']>;
/**
* Move file from destination folder to another destination folder.
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.move(this.destinationPath(from), this.destinationPath(to)).
*/
moveDestination(this: BaseGenerator, ...args: [from: string, to: string, options?: CopyOptions & PathOptions]): ReturnType<MemFsEditor['move']>;
/**
* Exists file on destination folder.
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.exists(this.destinationPath(filepath)).
*/
existsDestination(this: BaseGenerator, ...args: [filepath: string, options?: PathOptions]): ReturnType<MemFsEditor['exists']>;
/**
* Copy a template from templates folder to the destination.
*
* @param source - template file, relative to templatePath(), or absolute inside the source root (outside when the `allowTemplatesOutsideRoot` feature is enabled, inside the generator package when the `allowPackageTemplates` feature is enabled).
* @param destination - destination, relative to destinationPath(), or absolute inside the destination root (outside when the `allowDestinationOutsideRoot` feature is enabled).
* @param templateData - ejs data
* @param templateOptions - ejs options
* @param copyOptions - mem-fs-editor copy options, `allowOutsideRoot` applies to both source and destination
*/
renderTemplate<const D extends NonNullable<Parameters<MemFsEditor['copyTpl']>[2]>>(this: BaseGenerator, source?: string | string[], destination?: string | string[], templateData?: string | D, copyOptions?: CopyTplOptions & PathOptions): void;
/**
* Copy a template from templates folder to the destination.
*
* @param source - template file, relative to templatePath(), or absolute inside the source root (outside when the `allowTemplatesOutsideRoot` feature is enabled, inside the generator package when the `allowPackageTemplates` feature is enabled).
* @param destination - destination, relative to destinationPath(), or absolute inside the destination root (outside when the `allowDestinationOutsideRoot` feature is enabled).
* @param templateData - ejs data
* @param templateOptions - ejs options
* @param copyOptions - mem-fs-editor copy options, `allowOutsideRoot` applies to both source and destination
*/
renderTemplateAsync<const D extends NonNullable<Parameters<MemFsEditor['copyTplAsync']>[2]>>(this: BaseGenerator, source?: string | string[], destination?: string | string[], templateData?: string | D, copyOptions?: CopyTplAsyncOptions & PathOptions): Promise<void>;
/**
* Copy templates from templates folder to the destination.
*/
renderTemplates<const D extends NonNullable<Parameters<MemFsEditor['copyTpl']>[2]>>(this: BaseGenerator, templates: Templates<typeof this, 'copyTpl', D>, templateData?: string | D): void;
/**
* Copy templates from templates folder to the destination.
*
* @param templates - template file, relative to templatePath(), or absolute inside the source root (outside when the `allowTemplatesOutsideRoot` feature is enabled, inside the generator package when the `allowPackageTemplates` feature is enabled).
* @param templateData - ejs data
*/
renderTemplatesAsync<const D extends NonNullable<Parameters<MemFsEditor['copyTplAsync']>[2]>>(this: BaseGenerator, templates: Templates<typeof this, 'copyTplAsync', D>, templateData?: string | D): Promise<void[]>;
/**
* Utility method to get a formatted data for templates.
*
* @param path - path to the storage key.
* @return data to be passed to the templates.
*/
_templateData(this: BaseGenerator, path?: string): any;
}
export {};