Skip to content

Commit

Permalink
fix(cli): Minor generated app improvements (#2936)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Dec 19, 2022
1 parent 0415654 commit ba1a550
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/cli/src/service/templates/client.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const importTemplate = ({
upperName,
folder,
fileName,
className
className,
camelName,
type
}: ServiceGeneratorContext) => /* ts */ `import type {
${upperName},
${upperName}Data,
Expand All @@ -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' ? `<Params<${upperName}Query>>` : ''
}, typeof ${camelName}ServiceMethods[number]>`
}, typeof ${camelName}ServiceMethods[number]>
`

const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
` '${path}': ${upperName}ClientService`
Expand All @@ -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)
)
)

0 comments on commit ba1a550

Please sign in to comment.