GeezerVison is showing github.com — feat: handle extra slots · cnlon/lowcode-engine@20b34b7
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/const/index.ts +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,5 +8,26 @@ export const CONTAINER_TYPE = { | 8 | 8 |
| 9 | 9 | export const SUPPORT_SCHEMA_VERSION_LIST = ['0.0.1', '1.0.0']; | 10 | 10 |
| | 11 | +// built-in slot names which have been handled in ProjectBuilder | | 12 | +export const BUILTIN_SLOT_NAMES = [ | | 13 | + 'pages', | | 14 | + 'components', | | 15 | + 'router', | | 16 | + 'entry', | | 17 | + 'appConfig', | | 18 | + 'buildConfig', | | 19 | + 'constants', | | 20 | + 'utils', | | 21 | + 'i18n', | | 22 | + 'globalStyle', | | 23 | + 'htmlEntry', | | 24 | + 'packageJSON', | | 25 | + 'demo', | | 26 | +]; | | 27 | + | | 28 | +export const isBuiltinSlotName = function (name: string) { | | 29 | + return BUILTIN_SLOT_NAMES.includes(name); | | 30 | +}; | | 31 | + | 11 | 32 | export * from './file'; | 12 | 33 | export * from './generator'; |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/generator/ProjectBuilder.ts +19-11Lines changed: 19 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ import { createResultDir, addDirectory, addFile } from '../utils/resultHelper'; | 16 | 16 | import { createModuleBuilder } from './ModuleBuilder'; | 17 | 17 | import { ProjectPreProcessor, ProjectPostProcessor, IContextData } from '../types/core'; | 18 | 18 | import { CodeGeneratorError } from '../types/error'; | | 19 | +import { isBuiltinSlotName } from '../const'; | 19 | 20 |
| 20 | 21 | interface IModuleInfo { | 21 | 22 | moduleName?: string; | @@ -272,17 +273,8 @@ export class ProjectBuilder implements IProjectBuilder { | 272 | 273 | }); | 273 | 274 | } | 274 | 275 |
| 275 | | - // TODO: 更多 slots 的处理??是不是可以考虑把 template 中所有的 slots 都处理下? | 276 | | - // const whitelistSlotNames = [ | 277 | | - // 'router', | 278 | | - // 'entry', | 279 | | - // 'appConfig', | 280 | | - // 'buildConfig', | 281 | | - // 'router', | 282 | | - // ]; | 283 | | - // Object.keys(this.template.slots).forEach((slotName: string) => { | 284 | | - | 285 | | - // }); | | 276 | + // handle extra slots | | 277 | + await this.generateExtraSlots(builders, parseResult, buildResult); | 286 | 278 |
| 287 | 279 | // Post Process | 288 | 280 | const isSingleComponent = parseResult?.project?.projectRemark?.isSingleComponent; | @@ -339,6 +331,22 @@ export class ProjectBuilder implements IProjectBuilder { | 339 | 331 |
| 340 | 332 | return builders; | 341 | 333 | } | | 334 | + | | 335 | + private async generateExtraSlots( | | 336 | + builders: Record<string, IModuleBuilder>, | | 337 | + parseResult: IParseResult, | | 338 | + buildResult: IModuleInfo[], | | 339 | + ) { | | 340 | + for (const slotName in this.template.slots) { | | 341 | + if (!isBuiltinSlotName(slotName)) { | | 342 | + const { files } = await builders[slotName].generateModule(parseResult); | | 343 | + buildResult.push({ | | 344 | + path: this.template.slots[slotName].path, | | 345 | + files, | | 346 | + }); | | 347 | + } | | 348 | + } | | 349 | + } | 342 | 350 | } | 343 | 351 |
| 344 | 352 | export function createProjectBuilder(initOptions: ProjectBuilderInitOptions): IProjectBuilder { | |
|