lodash#TemplateExecutor TypeScript Examples

The following examples show how to use lodash#TemplateExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: api-client-generator.ts    From selling-partner-api-sdk with MIT License 5 votes vote down vote up
function generateAPIClient(
  project: Project,
  executor: TemplateExecutor,
  apiModel: APIModel,
  apiClientFileName: string,
  apiClientClassName: string,
) {
  log.info(`Starting generating ${apiClientClassName} client`)

  // Find main class inside api.ts file of api models
  const sourceFile = project.getSourceFileOrThrow(`${apiModel.outputPath}/${API_MODEL_FILE_NAME}`)
  const apiClasses = sourceFile.getClasses().filter((c) => c.getNameOrThrow().includes('Api'))

  let extendable = ''
  const helpers = ['ApiClientHelpers']
  const extendedClassNames = apiClasses.map((c) => c.getNameOrThrow()).join(',')

  // apply Mixins for api models that have multiple API classes
  if (apiClasses.length > 1) {
    extendable = `
    export interface ${apiClientClassName} extends ${extendedClassNames} {}
    applyMixins(${apiClientClassName}, [${extendedClassNames}])
    `

    helpers.push('applyMixins')
  }

  const compiledFile = executor({
    importApiModelClassName: extendedClassNames,
    importHelpers: helpers.join(','),
    dirname: apiModel.dirname,
    apiModelClassName: apiClasses[0].getNameOrThrow(),
    apiClientClassName,
    extendable,
  })

  project.createSourceFile(`src/api-clients/${apiClientFileName}.ts`, compiledFile, {
    overwrite: true,
  })

  log.info(`Finished generating ${apiClientClassName} client:
    - File name: ${apiClientFileName}.ts
    - Class name: ${apiClientClassName}
    - Model: ${apiModel.dirname}
  `)
}