UNPKG

@mongez/gnz

Version:

Generator Z, the next generation of scaffolding tools.

22 lines (21 loc) 1.38 kB
import {ensureDirectory,putFile}from'@mongez/fs';import {toKebabCase}from'@mongez/reinforcements';import chalk from'chalk';import'os';import'eslint';import'prettier';import {showSpinner}from'../../utils/show-spinner.js';import {getTemplateContents}from'./template.js';// This file is responsible for generating the code template. // It is called when user calls this generator. // Code template should not be added here, use 'template.ts' instead then get the output // of the function and put it in the file here, this makes it easier to maintain your generator. async function generate(optionsList) { // this is just an example, you can remove it. const { saveTo } = optionsList; optionsList.name = toKebabCase(optionsList.name); optionsList.saveAs ??= optionsList.name + "-service.ts"; // use loader to show a spinner while generating the content const loader = showSpinner(`Generating ${chalk.yellow("index.ts")} file...`); // make sure the directory exists ensureDirectory(saveTo); // generate the content const contents = await getTemplateContents(optionsList); // stop the loader loader.stop(`Generated ${chalk.green("index.ts")} file successfully.`); // save the content to the file putFile(saveTo + `/${optionsList.saveAs}`, contents); return optionsList; }export{generate};//# sourceMappingURL=generator.js.map