GeezerVison is showing github.com — feat: add a hook for customizing project builder options · zhYAO/lowcode-engine@7ddc155
File treeExpand file treeCollapse file tree Open diff view settings modules/code-generator/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/generator/ProjectBuilder.ts +20-10Lines changed: 20 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,6 +40,11 @@ export interface ProjectBuilderInitOptions { | 40 | 40 | inStrictMode?: boolean; | 41 | 41 | /** 一些额外的上下文数据 */ | 42 | 42 | extraContextData?: Record<string, unknown>; | | 43 | + /** | | 44 | + * Hook which is used to customize original options, we can reorder/add/remove plugins/processors | | 45 | + * of the existing solution. | | 46 | + */ | | 47 | + customizeBuilderOptions?(originalOptions: ProjectBuilderInitOptions): ProjectBuilderInitOptions; | 43 | 48 | } | 44 | 49 |
| 45 | 50 | export class ProjectBuilder implements IProjectBuilder { | @@ -67,16 +72,21 @@ export class ProjectBuilder implements IProjectBuilder { | 67 | 72 | /** 一些额外的上下文数据 */ | 68 | 73 | readonly extraContextData: IContextData; | 69 | 74 |
| 70 | | - constructor({ | 71 | | - template, | 72 | | - plugins, | 73 | | - postProcessors, | 74 | | - schemaParser = new SchemaParser(), | 75 | | - projectPreProcessors = [], | 76 | | - projectPostProcessors = [], | 77 | | - inStrictMode = false, | 78 | | - extraContextData = {}, | 79 | | - }: ProjectBuilderInitOptions) { | | 75 | + constructor(builderOptions: ProjectBuilderInitOptions) { | | 76 | + let customBuilderOptions = builderOptions; | | 77 | + if (typeof builderOptions.customizeBuilderOptions === 'function') { | | 78 | + customBuilderOptions = builderOptions.customizeBuilderOptions(builderOptions); | | 79 | + } | | 80 | + const { | | 81 | + template, | | 82 | + plugins, | | 83 | + postProcessors, | | 84 | + schemaParser = new SchemaParser(), | | 85 | + projectPreProcessors = [], | | 86 | + projectPostProcessors = [], | | 87 | + inStrictMode = false, | | 88 | + extraContextData = {}, | | 89 | + } = customBuilderOptions; | 80 | 90 | this.template = template; | 81 | 91 | this.plugins = plugins; | 82 | 92 | this.postProcessors = postProcessors; | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/solutions/icejs.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -91,6 +91,7 @@ export default function createIceJsProjectBuilder( | 91 | 91 | packageJSON: [icejs.plugins.packageJSON()], | 92 | 92 | }, | 93 | 93 | postProcessors: [prettier()], | | 94 | + customizeBuilderOptions: options?.customizeBuilderOptions, | 94 | 95 | }); | 95 | 96 | } | 96 | 97 |
| |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/solutions/rax-app.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,7 @@ export default function createRaxProjectBuilder( | 71 | 71 | packageJSON: [raxApp.plugins.packageJSON(options)], | 72 | 72 | }, | 73 | 73 | postProcessors: [prettier()], | | 74 | + customizeBuilderOptions: options?.customizeBuilderOptions, | 74 | 75 | }); | 75 | 76 | } | 76 | 77 |
| |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/types/core.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ import { | 14 | 14 |
| 15 | 15 | import { IParseResult } from './intermediate'; | 16 | 16 | import { IScopeBindings } from '../utils/ScopeBindings'; | | 17 | +import type { ProjectBuilderInitOptions } from '../generator/ProjectBuilder'; | 17 | 18 |
| 18 | 19 | export enum FileType { | 19 | 20 | CSS = 'css', | @@ -167,6 +168,11 @@ export interface IProjectBuilderOptions { | 167 | 168 | * - expr: 求值的表达式 | 168 | 169 | */ | 169 | 170 | evalErrorsHandler?: string; | | 171 | + /** | | 172 | + * Hook which is used to customize original options, we can reorder/add/remove plugins/processors | | 173 | + * of the existing solution. | | 174 | + */ | | 175 | + customizeBuilderOptions?(originalOptions: ProjectBuilderInitOptions): ProjectBuilderInitOptions; | 170 | 176 | } | 171 | 177 |
| 172 | 178 | export interface IProjectBuilder { | |
|