mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 09:41:57 +00:00
feat: 🎸 出码模块的 schema 相关的类型统一都改成引用 @ali/lowcode-types 中的,与设计器一致
This commit is contained in:
parent
adcfacb233
commit
27a9800705
@ -8,12 +8,12 @@ import { SUPPORT_SCHEMA_VERSION_LIST } from '../const';
|
||||
import { handleChildren } from '../utils/nodeToJSX';
|
||||
|
||||
import {
|
||||
ChildNodeType,
|
||||
NodeData,
|
||||
CodeGeneratorError,
|
||||
CompatibilityError,
|
||||
DependencyType,
|
||||
IBasicSchema,
|
||||
IComponentNodeItem,
|
||||
NodeSchema,
|
||||
IContainerInfo,
|
||||
IContainerNodeItem,
|
||||
IDependency,
|
||||
@ -24,7 +24,7 @@ import {
|
||||
IParseResult,
|
||||
IProjectSchema,
|
||||
ISchemaParser,
|
||||
IUtilItem,
|
||||
UtilItem,
|
||||
} from '../types';
|
||||
|
||||
const defaultContainer: IContainerInfo = {
|
||||
@ -85,7 +85,7 @@ class SchemaParser implements ISchemaParser {
|
||||
// 整个 schema 描述一个容器,且无根节点定义
|
||||
const container: IContainerInfo = {
|
||||
...defaultContainer,
|
||||
children: schema.componentsTree as IComponentNodeItem[],
|
||||
children: schema.componentsTree as NodeSchema[],
|
||||
};
|
||||
containers = [container];
|
||||
} else {
|
||||
@ -167,7 +167,7 @@ class SchemaParser implements ISchemaParser {
|
||||
.filter((dep) => !!dep);
|
||||
|
||||
// 分析 Utils 依赖
|
||||
let utils: IUtilItem[];
|
||||
let utils: UtilItem[];
|
||||
if (schema.utils) {
|
||||
utils = schema.utils;
|
||||
utilsDeps = schema.utils.filter((u) => u.type !== 'function').map((u) => u.content as IExternalDependency);
|
||||
@ -198,9 +198,9 @@ class SchemaParser implements ISchemaParser {
|
||||
};
|
||||
}
|
||||
|
||||
public getComponentNames(children: ChildNodeType): string[] {
|
||||
public getComponentNames(children: NodeData | NodeData[]): string[] {
|
||||
return handleChildren(children, {
|
||||
node: (i: IComponentNodeItem) => [i.componentName],
|
||||
node: (i: NodeSchema) => [i.componentName],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ import {
|
||||
ICodeChunk,
|
||||
ICodeStruct,
|
||||
IContainerInfo,
|
||||
IJSExpression,
|
||||
JSExpression,
|
||||
} from '../../../types';
|
||||
|
||||
type PluginConfig = {
|
||||
@ -50,7 +50,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
// fileType: cfg.fileType,
|
||||
// name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||
// content: getFuncExprBody(
|
||||
// (lifeCycles[lifeCycleName] as IJSExpression).value,
|
||||
// (lifeCycles[lifeCycleName] as JSExpression).value,
|
||||
// ),
|
||||
// linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorStart]],
|
||||
// };
|
||||
@ -61,7 +61,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
// fileType: cfg.fileType,
|
||||
// name: RAX_CHUNK_NAME.ClassRenderPre,
|
||||
// content: getFuncExprBody(
|
||||
// (lifeCycles[lifeCycleName] as IJSExpression).value,
|
||||
// (lifeCycles[lifeCycleName] as JSExpression).value,
|
||||
// ),
|
||||
// linkAfter: [RAX_CHUNK_NAME.ClassRenderStart],
|
||||
// };
|
||||
@ -73,7 +73,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
// name: CLASS_DEFINE_CHUNK_NAME.InsMethod,
|
||||
// content: transformFuncExpr2MethodMember(
|
||||
// exportName,
|
||||
// (lifeCycles[lifeCycleName] as IJSExpression).value,
|
||||
// (lifeCycles[lifeCycleName] as JSExpression).value,
|
||||
// ),
|
||||
// linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsMethod]],
|
||||
// };
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
import { CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from '../../../const/generator';
|
||||
import { REACT_CHUNK_NAME } from './const';
|
||||
|
||||
import {
|
||||
getFuncExprBody,
|
||||
transformFuncExpr2MethodMember,
|
||||
} from '../../../utils/jsExpression';
|
||||
import { getFuncExprBody, transformFuncExpr2MethodMember } from '../../../utils/jsExpression';
|
||||
|
||||
import {
|
||||
BuilderComponentPlugin,
|
||||
@ -15,14 +12,14 @@ import {
|
||||
ICodeChunk,
|
||||
ICodeStruct,
|
||||
IContainerInfo,
|
||||
IJSExpression,
|
||||
JSExpression,
|
||||
} from '../../../types';
|
||||
|
||||
type PluginConfig = {
|
||||
fileType: string;
|
||||
exportNameMapping: Record<string, string>;
|
||||
normalizeNameMapping: Record<string, string>;
|
||||
}
|
||||
};
|
||||
|
||||
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
||||
const cfg: PluginConfig = {
|
||||
@ -41,7 +38,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
|
||||
if (ir.lifeCycles) {
|
||||
const lifeCycles = ir.lifeCycles;
|
||||
const chunks = Object.keys(lifeCycles).map<ICodeChunk>(lifeCycleName => {
|
||||
const chunks = Object.keys(lifeCycles).map<ICodeChunk>((lifeCycleName) => {
|
||||
const normalizeName = cfg.normalizeNameMapping[lifeCycleName] || lifeCycleName;
|
||||
const exportName = cfg.exportNameMapping[lifeCycleName] || lifeCycleName;
|
||||
if (normalizeName === 'constructor') {
|
||||
@ -49,9 +46,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||
content: getFuncExprBody(
|
||||
(lifeCycles[lifeCycleName] as IJSExpression).value,
|
||||
),
|
||||
content: getFuncExprBody((lifeCycles[lifeCycleName] as JSExpression).value),
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorStart]],
|
||||
};
|
||||
}
|
||||
@ -60,9 +55,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: REACT_CHUNK_NAME.ClassRenderPre,
|
||||
content: getFuncExprBody(
|
||||
(lifeCycles[lifeCycleName] as IJSExpression).value,
|
||||
),
|
||||
content: getFuncExprBody((lifeCycles[lifeCycleName] as JSExpression).value),
|
||||
linkAfter: [REACT_CHUNK_NAME.ClassRenderStart],
|
||||
};
|
||||
}
|
||||
@ -71,10 +64,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.InsMethod,
|
||||
content: transformFuncExpr2MethodMember(
|
||||
exportName,
|
||||
(lifeCycles[lifeCycleName] as IJSExpression).value,
|
||||
),
|
||||
content: transformFuncExpr2MethodMember(exportName, (lifeCycles[lifeCycleName] as JSExpression).value),
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsMethod]],
|
||||
};
|
||||
});
|
||||
|
||||
@ -10,12 +10,12 @@ import {
|
||||
ICodeChunk,
|
||||
ICodeStruct,
|
||||
IContainerInfo,
|
||||
IJSExpression,
|
||||
JSExpression,
|
||||
} from '../../../types';
|
||||
|
||||
type PluginConfig = {
|
||||
fileType: string;
|
||||
}
|
||||
};
|
||||
|
||||
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
||||
const cfg: PluginConfig = {
|
||||
@ -32,14 +32,11 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
|
||||
if (ir.methods) {
|
||||
const methods = ir.methods;
|
||||
const chunks = Object.keys(methods).map<ICodeChunk>(methodName => ({
|
||||
const chunks = Object.keys(methods).map<ICodeChunk>((methodName) => ({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.InsMethod,
|
||||
content: transformFuncExpr2MethodMember(
|
||||
methodName,
|
||||
(methods[methodName] as IJSExpression).value,
|
||||
),
|
||||
content: transformFuncExpr2MethodMember(methodName, (methods[methodName] as JSExpression).value),
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsMethod]],
|
||||
}));
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
ChunkType,
|
||||
ICodeStruct,
|
||||
IContainerInfo,
|
||||
IComponentNodeItem,
|
||||
NodeSchema,
|
||||
CodePiece,
|
||||
PIECE_TYPE,
|
||||
} from '../../../types';
|
||||
@ -14,14 +14,16 @@ import { createNodeGenerator, generateString } from '../../../utils/nodeToJSX';
|
||||
import { generateExpression } from '../../../utils/jsExpression';
|
||||
import { generateCompositeType, handleStringValueDefault } from '../../../utils/compositeType';
|
||||
|
||||
const generateGlobalProps = (nodeItem: IComponentNodeItem): CodePiece[] => {
|
||||
return [{
|
||||
value: `{...globalProps.${nodeItem.componentName}}`,
|
||||
type: PIECE_TYPE.ATTR,
|
||||
}];
|
||||
const generateGlobalProps = (nodeItem: NodeSchema): CodePiece[] => {
|
||||
return [
|
||||
{
|
||||
value: `{...globalProps.${nodeItem.componentName}}`,
|
||||
type: PIECE_TYPE.ATTR,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
const generateCtrlLine = (nodeItem: IComponentNodeItem): CodePiece[] => {
|
||||
const generateCtrlLine = (nodeItem: NodeSchema): CodePiece[] => {
|
||||
const pieces: CodePiece[] = [];
|
||||
|
||||
if (nodeItem.loop && nodeItem.loopArgs) {
|
||||
@ -49,13 +51,13 @@ const generateCtrlLine = (nodeItem: IComponentNodeItem): CodePiece[] => {
|
||||
};
|
||||
|
||||
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
const generator = createNodeGenerator({
|
||||
string: generateString,
|
||||
expression: (input) => [generateExpression(input)],
|
||||
}, [
|
||||
generateGlobalProps,
|
||||
generateCtrlLine,
|
||||
]);
|
||||
const generator = createNodeGenerator(
|
||||
{
|
||||
string: generateString,
|
||||
expression: (input) => [generateExpression(input)],
|
||||
},
|
||||
[generateGlobalProps, generateCtrlLine],
|
||||
);
|
||||
|
||||
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
|
||||
const next: ICodeStruct = {
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import { JSExpression, JSFunction, NodeSchema } from '@ali/lowcode-types';
|
||||
|
||||
import { CustomHandlerSet } from '../utils/compositeType';
|
||||
import { IBasicSchema, IParseResult, IProjectSchema, IResultDir, IResultFile, IComponentNodeItem } from './index';
|
||||
import { IParseResult } from './intermediate';
|
||||
import { IResultDir, IResultFile } from './result';
|
||||
import { IBasicSchema, IProjectSchema } from './schema';
|
||||
|
||||
export enum FileType {
|
||||
CSS = 'css',
|
||||
@ -158,7 +161,7 @@ export interface HandlerSet<T> {
|
||||
common?: (input: unknown) => T[];
|
||||
}
|
||||
|
||||
export type ExtGeneratorPlugin = (nodeItem: IComponentNodeItem, handlers: CustomHandlerSet) => CodePiece[];
|
||||
export type ExtGeneratorPlugin = (nodeItem: NodeSchema, handlers: CustomHandlerSet) => CodePiece[];
|
||||
|
||||
// export interface InteratorScope {
|
||||
// [$item: string]: string; // $item 默认取值 "item"
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
import {
|
||||
IAppConfig,
|
||||
IAppMeta,
|
||||
IContainerNodeItem,
|
||||
IDependency,
|
||||
II18nMap,
|
||||
IInternalDependency,
|
||||
IUtilItem,
|
||||
} from './index';
|
||||
import { IAppConfig, IAppMeta, IContainerNodeItem, IDependency, II18nMap, UtilItem } from '.';
|
||||
|
||||
export interface IParseResult {
|
||||
containers: IContainerInfo[];
|
||||
@ -27,7 +19,7 @@ export interface IWithDependency {
|
||||
}
|
||||
|
||||
export interface IUtilInfo extends IWithDependency {
|
||||
utils: IUtilItem[];
|
||||
utils: UtilItem[];
|
||||
}
|
||||
|
||||
export interface IRouterInfo extends IWithDependency {
|
||||
|
||||
@ -1,33 +1,7 @@
|
||||
import {
|
||||
ProjectSchema,
|
||||
CompositeObject,
|
||||
JSExpression,
|
||||
JSONObject,
|
||||
NpmInfo,
|
||||
NodeData,
|
||||
NodeSchema,
|
||||
UtilItem,
|
||||
PageSchema,
|
||||
BlockSchema,
|
||||
ComponentSchema,
|
||||
DataSourceConfig,
|
||||
} from '@ali/lowcode-types';
|
||||
import { BlockSchema, ComponentSchema, NodeSchema, PageSchema, ProjectSchema } from '@ali/lowcode-types';
|
||||
|
||||
export * from '@ali/lowcode-types';
|
||||
|
||||
/**
|
||||
* 搭建基础协议 - 函数表达式
|
||||
*
|
||||
* @export
|
||||
* @interface IJSExpression
|
||||
*/
|
||||
export type IJSExpression = JSExpression;
|
||||
|
||||
// JSON 基本类型
|
||||
export type IJSONObject = JSONObject;
|
||||
|
||||
export type ICompositeObject = CompositeObject;
|
||||
|
||||
/**
|
||||
* 搭建基础协议 - 多语言描述
|
||||
*
|
||||
@ -56,38 +30,15 @@ export interface IProjectSchema extends IBasicSchema {
|
||||
meta: IAppMeta; // 当前应用元数据信息
|
||||
}
|
||||
|
||||
export interface IComponentsMapItem extends NpmInfo {}
|
||||
|
||||
export type IUtilItem = UtilItem;
|
||||
export type ChildNodeItem = NodeData;
|
||||
export type ChildNodeType = ChildNodeItem | ChildNodeItem[];
|
||||
|
||||
/**
|
||||
* 搭建基础协议 - 单个组件树节点描述
|
||||
* 转换成一个 .jsx 文件内 React Class 类 render 函数返回的 jsx 代码
|
||||
*
|
||||
* @export
|
||||
* @interface IComponentNodeItem
|
||||
*/
|
||||
export interface IComponentNodeItem extends NodeSchema {}
|
||||
|
||||
/**
|
||||
* 搭建基础协议 - 单个容器节点描述
|
||||
*
|
||||
* @export
|
||||
* @interface IContainerNodeItem
|
||||
* @extends {IComponentNodeItem}
|
||||
* @extends {NodeSchema}
|
||||
*/
|
||||
export type IContainerNodeItem = PageSchema | BlockSchema | ComponentSchema;
|
||||
|
||||
/**
|
||||
* 搭建基础协议 - 数据源单个配置
|
||||
*
|
||||
* @export
|
||||
* @interface IDataSourceConfig
|
||||
*/
|
||||
export interface IDataSourceConfig extends DataSourceConfig {}
|
||||
|
||||
// TODO...
|
||||
export interface IBasicMeta {
|
||||
title: string; // 标题描述
|
||||
@ -103,7 +54,7 @@ export interface IAppConfig {
|
||||
sdkVersion?: string; // 渲染模块版本
|
||||
historyMode?: 'browser' | 'hash'; // 浏览器路由:browser 哈希路由:hash
|
||||
targetRootID?: string; // 渲染根节点 ID
|
||||
layout?: IComponentNodeItem;
|
||||
layout?: NodeSchema;
|
||||
theme?: object; // 主题配置,根据接入的主题模块不同
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user