UNPKG

@mongez/gnz

Version:

Generator Z, the next generation of scaffolding tools.

19 lines (18 loc) 1.19 kB
import {ensureDirectory,fileExists,putFile}from'@mongez/fs';import chalk from'chalk';import path from'path';import {namesFactory}from'../../../factories/names-factory.js';import'os';import'eslint';import'prettier';import {throwIf}from'../../../utils/throw-if.js';import {gnWarlockOutput}from'./template.js';const generate = async (options) => { const { saveTo } = options; const outputName = options.name; options.name = namesFactory.outputClassName(options.name); ensureDirectory(saveTo); options.fileName ||= namesFactory.outputFilePath(outputName); const outputFilePath = options.fileName + ".ts"; const now = Date.now(); const Path = path.join(saveTo, outputFilePath); throwIf(fileExists(Path), ` ${chalk.green(options.fileName)}.ts already exists in ${chalk.yellow(saveTo)}`); const content = await gnWarlockOutput(options); putFile(Path, content); console.log(` ${chalk.green(options.name)} has been generated successfully in ${chalk.cyan(saveTo + "/" + outputFilePath)} ${chalk.gray(`(${Date.now() - now}ms)`)}`); return { ...options, path: Path, }; };export{generate};//# sourceMappingURL=generator.js.map