mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-10 18:03:01 +00:00
feat: handle extra slots
This commit is contained in:
parent
37e07bb238
commit
20b34b74a2
@ -8,5 +8,26 @@ export const CONTAINER_TYPE = {
|
||||
|
||||
export const SUPPORT_SCHEMA_VERSION_LIST = ['0.0.1', '1.0.0'];
|
||||
|
||||
// built-in slot names which have been handled in ProjectBuilder
|
||||
export const BUILTIN_SLOT_NAMES = [
|
||||
'pages',
|
||||
'components',
|
||||
'router',
|
||||
'entry',
|
||||
'appConfig',
|
||||
'buildConfig',
|
||||
'constants',
|
||||
'utils',
|
||||
'i18n',
|
||||
'globalStyle',
|
||||
'htmlEntry',
|
||||
'packageJSON',
|
||||
'demo',
|
||||
];
|
||||
|
||||
export const isBuiltinSlotName = function (name: string) {
|
||||
return BUILTIN_SLOT_NAMES.includes(name);
|
||||
};
|
||||
|
||||
export * from './file';
|
||||
export * from './generator';
|
||||
|
||||
@ -16,6 +16,7 @@ import { createResultDir, addDirectory, addFile } from '../utils/resultHelper';
|
||||
import { createModuleBuilder } from './ModuleBuilder';
|
||||
import { ProjectPreProcessor, ProjectPostProcessor, IContextData } from '../types/core';
|
||||
import { CodeGeneratorError } from '../types/error';
|
||||
import { isBuiltinSlotName } from '../const';
|
||||
|
||||
interface IModuleInfo {
|
||||
moduleName?: string;
|
||||
@ -272,17 +273,8 @@ export class ProjectBuilder implements IProjectBuilder {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: 更多 slots 的处理??是不是可以考虑把 template 中所有的 slots 都处理下?
|
||||
// const whitelistSlotNames = [
|
||||
// 'router',
|
||||
// 'entry',
|
||||
// 'appConfig',
|
||||
// 'buildConfig',
|
||||
// 'router',
|
||||
// ];
|
||||
// Object.keys(this.template.slots).forEach((slotName: string) => {
|
||||
|
||||
// });
|
||||
// handle extra slots
|
||||
await this.generateExtraSlots(builders, parseResult, buildResult);
|
||||
|
||||
// Post Process
|
||||
const isSingleComponent = parseResult?.project?.projectRemark?.isSingleComponent;
|
||||
@ -339,6 +331,22 @@ export class ProjectBuilder implements IProjectBuilder {
|
||||
|
||||
return builders;
|
||||
}
|
||||
|
||||
private async generateExtraSlots(
|
||||
builders: Record<string, IModuleBuilder>,
|
||||
parseResult: IParseResult,
|
||||
buildResult: IModuleInfo[],
|
||||
) {
|
||||
for (const slotName in this.template.slots) {
|
||||
if (!isBuiltinSlotName(slotName)) {
|
||||
const { files } = await builders[slotName].generateModule(parseResult);
|
||||
buildResult.push({
|
||||
path: this.template.slots[slotName].path,
|
||||
files,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createProjectBuilder(initOptions: ProjectBuilderInitOptions): IProjectBuilder {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user