From ba1a5500a8a5ea4ab44da44ac509e48c723d7efd Mon Sep 17 00:00:00 2001 From: David Luecke Date: Sun, 18 Dec 2022 16:31:55 -0800 Subject: [PATCH] fix(cli): Minor generated app improvements (#2936) --- .../cli/src/service/templates/client.tpl.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/service/templates/client.tpl.ts b/packages/cli/src/service/templates/client.tpl.ts index 97173f2681..ab4a4f8fe3 100644 --- a/packages/cli/src/service/templates/client.tpl.ts +++ b/packages/cli/src/service/templates/client.tpl.ts @@ -6,7 +6,9 @@ const importTemplate = ({ upperName, folder, fileName, - className + className, + camelName, + type }: ServiceGeneratorContext) => /* ts */ `import type { ${upperName}, ${upperName}Data, @@ -18,13 +20,11 @@ export type { ${upperName}Data, ${upperName}Query } -` - -const methodsTemplate = ({ camelName, upperName, className, type }: ServiceGeneratorContext) => ` -const ${camelName}ServiceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'] as const -type ${upperName}ClientService = Pick<${className}${ +export const ${camelName}ServiceMethods = ['find', 'get', 'create', 'patch', 'remove'] as const +export type ${upperName}ClientService = Pick<${className}${ type !== 'custom' ? `>` : '' -}, typeof ${camelName}ServiceMethods[number]>` +}, typeof ${camelName}ServiceMethods[number]> +` const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) => ` '${path}': ${upperName}ClientService` @@ -44,14 +44,13 @@ export const generate = async (ctx: ServiceGeneratorContext) => .then( when( (ctx) => ctx.language === 'js', - injectSource(methodsTemplate, after('import authenticationClient'), toClientFile) + injectSource(importTemplate, after('import authenticationClient'), toClientFile) ) ) .then( when( (ctx) => ctx.language === 'ts', - injectSource(importTemplate, after('import authenticationClient'), toClientFile), - injectSource(methodsTemplate, before('\nexport interface ServiceTypes'), toClientFile), + injectSource(importTemplate, after('import type { AuthenticationClientOptions }'), toClientFile), injectSource(declarationTemplate, after('export interface ServiceTypes'), toClientFile) ) )