UNPKG

@mongez/gnz

Version:

Generator Z, the next generation of scaffolding tools.

22 lines (21 loc) 1.57 kB
'use strict';var fs=require('@mongez/fs'),reinforcements=require('@mongez/reinforcements'),chalk=require('chalk');require('os'),require('eslint'),require('prettier');var showSpinner=require('../../utils/show-spinner.js'),template=require('./template.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var chalk__default=/*#__PURE__*/_interopDefault(chalk);// 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 = reinforcements.toKebabCase(optionsList.name); optionsList.saveAs ??= optionsList.name + "-service.ts"; // use loader to show a spinner while generating the content const loader = showSpinner.showSpinner(`Generating ${chalk__default.default.yellow("index.ts")} file...`); // make sure the directory exists fs.ensureDirectory(saveTo); // generate the content const contents = await template.getTemplateContents(optionsList); // stop the loader loader.stop(`Generated ${chalk__default.default.green("index.ts")} file successfully.`); // save the content to the file fs.putFile(saveTo + `/${optionsList.saveAs}`, contents); return optionsList; }exports.generate=generate;//# sourceMappingURL=generator.js.map