Skip to content

Commit

Permalink
feat(types): add FileTemplateType, generator files types, extendable …
Browse files Browse the repository at this point in the history
…generator config props.

Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Feb 13, 2023
1 parent 8a1c2a2 commit 20e2a2d
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions packages/types/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface GitConfig {

export interface GeneratorProps {
[key: string]: string | boolean | undefined

useRxJS6: boolean | string | undefined
usePromise: boolean | string | undefined
supportsES6: boolean | string | undefined
Expand All @@ -19,26 +20,65 @@ export interface GeneratorProps {
npmName: string | undefined
}

export interface GeneratorConfig extends GitConfig {
additionalProperties: GeneratorProps
export const FileTemplateType = {
Api: 'API',
ApiDocs: 'APIDocs',
ApiTests: 'APITests',
Model: 'Model',
ModelDocs: 'ModelDocs',
ModelTests: 'ModelTests',
SupportingFiles: 'SupportingFiles',
} as const

export type FileTemplateType =
(typeof FileTemplateType)[keyof typeof FileTemplateType]

export interface FileTemplate {
templateType: FileTemplateType
destinationFilename: string
folder?: string
}

export interface FileTemplateExtensions {
/**
* Path relative to client output to write file in.
*/
destinationPath?: string
sourcePath?: string
}

export interface ExtendedFileTemplate
extends FileTemplate,
FileTemplateExtensions {}

export interface GeneratorConfig<T extends GeneratorProps = GeneratorProps>
extends GitConfig {
additionalProperties?: T
generatorName: string | undefined
templateDir?: string | undefined
output: string
glob: string | undefined
inputSpec: string | undefined
removeOperationIdPrefix: boolean
legacyDiscriminatorBehavior: boolean
files?: Record<string, FileTemplate>
}

export interface TemplateConfig {
export interface TemplateConfig<T extends GeneratorProps = GeneratorProps> {
generatorVersion?: string | undefined
additionalProperties?: T
additionalArgs: string[]
drop?: string[]
files?: Record<string, ExtendedFileTemplate>
}

export interface ExtendedGeneratorConfig
extends GeneratorConfig,
TemplateConfig {}
export interface ExtendedGeneratorConfig<
T extends GeneratorProps = GeneratorProps,
> extends GeneratorConfig<T>,
TemplateConfig<T> {
files?: TemplateConfig['files']
addtionalProperties?: TemplateConfig['additionalProperties']
}

export interface OASConfig {
$schema?: string
Expand All @@ -49,11 +89,6 @@ export interface OASConfig {
}
}

export interface TemplatesConfig {
extends: string
drop?: string[]
}

export interface GenerateOptions {
clients: string[]
rootDir: string
Expand All @@ -74,8 +109,10 @@ export interface Workspace {

export interface WorkspaceProvider<T extends Workspace = Workspace> {
workspace: T

create(outputDir: string, overwrite?: boolean): Promise<this>

addTemplatePath(path: string, ...args: any[]): Promise<this>

setConfig(config: GeneratorConfig): Promise<this>
}

0 comments on commit 20e2a2d

Please sign in to comment.