UNPKG

@mongez/gnz

Version:

Generator Z, the next generation of scaffolding tools.

34 lines (31 loc) 1.62 kB
'use strict';var reinforcements=require('@mongez/reinforcements'),pluralize=require('pluralize');require('os');var prettifier=require('../../utils/prettifier.js');// This file is responsible for generating the code template. // This file is auto imported by default in generator.ts file. // If you're going to generate a single file, you can put the code template here directly. // If the generated template is huge, create a directory called 'template' and create 'index.ts' file inside it, // then collect all templates and export it from 'index.ts' file, // Put each template file in a separate file then collected them all here. // If you're going to generate multiple but small files, you can create functions in this file directly. async function getTemplateContents({ endpointPath = "shared/endpoint", name, route, }) { const nameInPlural = reinforcements.toStudlyCase(pluralize.plural(name)); const nameSingle = reinforcements.toStudlyCase(pluralize.singular(name)); const routePath = route || `/${reinforcements.toKebabCase(name)}`; const contents = ` import endpoint from "${endpointPath}"; /** * Get ${nameInPlural} list */ export function get${nameInPlural}List(params: any = {}) { return endpoint.get("${routePath}", { params, }); } /** * Get ${name} details */ export function get${nameSingle}(id: string | number) { return endpoint.get("${routePath}/" + id); } `; // prettify the content return await prettifier.prettifyTypescript(contents); }exports.getTemplateContents=getTemplateContents;//# sourceMappingURL=template.js.map