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
101 lines (100 loc) • 3.33 kB
TypeScript
import CreateDebugGroup from "../utilities/logger/createDebugGroup";
import { AnswersHash } from "../types/settings";
import type { Template } from './template';
interface BuildBuilt {
files: string[];
directories: string[];
}
interface BuildOptions {
buildInDest: boolean;
buildNewFolder: boolean;
wipe: boolean;
force: boolean;
}
type RenderData = Record<string, any>;
export declare class Build {
/**
* Full absolute build path
*
* @example "/Users/lornelas/Templates/my-instance"
* @example "/Users/lornelas/Templates/some/extra/path/my-instance"
* @example "/Users/lornelas/Templates"
*/
readonly buildPath: string;
readonly template: Template;
/**
* Name of the build if present.
*
* Builds that are being created in the destination dont have names.
*/
readonly name: string;
/**
* Directory to render the contents into.
*
* If `buildInNewFolder` is `true`, then a directory of `name`
* will be created in this directory and contents will be rendered in that directory.
* Else contents will be rendered in `directory`
*/
readonly directory: string;
/**
* Files and directories that were created during render
*/
built: BuildBuilt;
options: BuildOptions;
constructor(
/**
* Full absolute build path
*
* @example "/Users/lornelas/Templates/my-instance"
* @example "/Users/lornelas/Templates/some/extra/path/my-instance"
* @example "/Users/lornelas/Templates"
*/
buildPath: string, template: Template, options?: Partial<BuildOptions>);
/**
* Final directory to create instance contents in.
*
* If `buildInDest` or `buildNewFolder` then we use the supplied buildPath. Note!
* when `buildInDest` is true, the build path wont have a instance name.
*
* TODO: when `buildInDest` is true, `name` should be null
*/
getDirectory(): string;
/**
* Checks to see if the final directory exists or not
*/
directoryExists(): Promise<boolean>;
createDirectory(): Promise<string>;
/**
* Destroy the final directory
*/
private wipe;
/**
* Wipes the directory if it should. Will return a boolean on whether or not
* directory was wiped.
*/
maybeWipe(hackyCallbackWhenFilesNeedToBeWiped?: () => void): Promise<boolean>;
getLoggerName(): string;
getLogger(clear?: boolean): CreateDebugGroup;
checkForConflicts(dest: string, data: RenderData): Promise<void>;
/**
* Render the build path
*/
render(answers?: AnswersHash, data?: RenderData): Promise<void>;
/**
* Creates all directories our instance needs. This will use all
* directories in any package that was loaded.
*/
private renderDirectories;
/**
* Creates all files that our template uses in `buildPath` folder
* @param {Object} [data={}] - data passed in for dot
*/
private renderFiles;
/**
* Delete everything that was created in this build. This will run if any file or directory
* error when being created. We dont want to leave broken templates created
* so this function will delete everything that this template built
*/
clean(buildNewFolder: boolean): Promise<void>;
}
export {};