@mongez/gnz
Version:
Generator Z, the next generation of scaffolding tools.
18 lines (17 loc) • 1.28 kB
JavaScript
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 {gnQwikPage}from'./template.js';const generate = async (options) => {
const componentName = namesFactory.qwikPageComponent(options.name);
const now = Date.now();
const content = await gnQwikPage({
...options,
name: componentName,
});
const { saveTo } = options;
const componentPath = namesFactory.qwikPagePath(options.name);
ensureDirectory(saveTo + "/" + componentPath);
const componentFullPath = path.join(saveTo, componentPath, "index.tsx");
throwIf(fileExists(componentFullPath), `${chalk.green("index.tsx")} file already exists in ${chalk.yellow(saveTo + "/" + componentPath)}`);
putFile(componentFullPath, content);
console.log(`Component ${chalk.green(componentName)} page has been generated successfully in ${chalk.cyan(path
.relative(process.cwd(), path.join(path.resolve(saveTo), componentPath))
.replaceAll("\\", "/"))} ${chalk.gray(`(${Date.now() - now}ms)`)}`);
};export{generate};//# sourceMappingURL=generator.js.map