UNPKG

@mongez/gnz

Version:

Generator Z, the next generation of scaffolding tools.

31 lines (30 loc) 1.8 kB
'use strict';var fs=require('@mongez/fs'),reinforcements=require('@mongez/reinforcements'),chalk=require('chalk'),path=require('path'),template=require('./template.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var chalk__default=/*#__PURE__*/_interopDefault(chalk);var path__default=/*#__PURE__*/_interopDefault(path);// 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. function prepareName(name) { // Make sure that the name ends with "-service" if (!name.endsWith("-service")) { name += "-service"; } return name; } async function generate(optionsList) { // this is just an example, you can remove it. const { saveTo, name } = optionsList; optionsList.name = prepareName(name); optionsList.saveAs ||= optionsList.name + ".ts"; optionsList.className ||= reinforcements.toStudlyCase(optionsList.name); optionsList.objectName ||= reinforcements.toCamelCase(optionsList.name); optionsList.route ||= "/" + reinforcements.toKebabCase(optionsList.name.replace("-service", "")); // make sure the directory exists fs.ensureDirectory(saveTo); // generate the content const contents = await template.getTemplateContents(optionsList); // stop the loader console.log(`Generated ${chalk__default.default.green(name)} restful service successfully.`); // save the content to the file fs.putFile(path__default.default.resolve(saveTo, optionsList.saveAs), contents); return optionsList; }exports.generate=generate;//# sourceMappingURL=generator.js.map