UNPKG

templates-mo

Version:

Templates is a scaffolding framework that makes code generation simple, dynamic, and reusable. Generate files, parts of your app, or whole project structures—without the repetitive copy-pasting

109 lines (108 loc) • 3.23 kB
import dot from "./dot"; import { FileNode } from '../fileSystemTree'; type Defs = Record<string, string>; type Data = Record<string, unknown>; export interface FileOptions { force?: boolean; useExperimentalTemplateEngine?: boolean; } /** * File */ declare class File { /** * Full path to the file. This value will preserve the * `.tps`, `.def`, `.jst` or `.dot` * * @example "./path/to/file/index.js" * @example "./path/to/file/index.js.dot" */ file: string; /** * File contents */ contents: string; /** * Name of the file with all extensions. If the name includes a `.tps`, `.def`, * `.jst`, or `.dot` extension we strip this from the name and mark `isDynamic` as true * * @example "index.js" * @example "nav.css" * @example ".tpsrc" */ readonly name: string; /** * The directory this file should be in when rendered * * @example "./path/to/folder" */ readonly location: string; /** * File should be processed as a dynamic file */ readonly isDynamic: boolean; /** * The templating language engine */ readonly engine: any; /** * File options */ options: FileOptions; _dotNameCompiled: dot.RenderFunction; /** * Generate a File from a FileNode */ static fromFileNode(fileNode: FileNode, options?: Partial<FileOptions>): File; /** * Generate a File from a FileObject */ static from(file: string, content: string, options?: Partial<FileOptions>): File; constructor( /** * Full path to the file. This value will preserve the * `.tps`, `.def`, `.jst` or `.dot` * * @example "./path/to/file/index.js" * @example "./path/to/file/index.js.dot" */ file: string, /** * File contents */ contents: string, options?: Partial<FileOptions>); /** * Get the final result of the file name for this file. If the name has any * * @param data - Meta data to pass to the template engine * @param defs - defs to send to the temnplate engine */ private fileName; /** * Get the file contents for this file. If file is a dynamic file then * this will be the final result after the template engine process it. * * @param location - directory to render this file into * @param data - Meta data to pass to the template engine * @param defs - defs to send to the temnplate engine */ private getContents; /** * Render this file to a specific location * * @param location - directory to render this file into * @param data - Meta data to pass to the template engine * @param defs - defs to send to the temnplate engine */ render(location: string, data: Data, defs: Defs): Promise<string>; private _buildParentDir; /** * Full destination to render this file to. * * @param location - directory to render this file into * @param data - Meta data to pass to the template engine * @param defs - defs to send to the temnplate engine */ dest(location: string, data: Data, defs: Defs): string; } export default File;