mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
fix: fix test result
This commit is contained in:
parent
584b4c25ee
commit
7f6fbe8939
@ -12,7 +12,8 @@
|
||||
],
|
||||
"scripts": {
|
||||
"start": "ava --watch",
|
||||
"build": "rimraf lib && build-scripts build --skip-demo",
|
||||
"build": "npm run build:tsc",
|
||||
"build:bs": "rimraf lib && rimraf es && build-scripts build --skip-demo",
|
||||
"build:tsc": "rimraf lib && tsc",
|
||||
"demo": "node ./demo/demo.js",
|
||||
"test": "ava",
|
||||
|
||||
@ -208,7 +208,13 @@ class SchemaParser implements ISchemaParser {
|
||||
const p = (con.deps || [])
|
||||
.map((dep) => (dep.dependencyType === DependencyType.External ? dep : null))
|
||||
.filter((dep) => dep !== null);
|
||||
npms.push(...((p as unknown) as INpmPackage[]));
|
||||
const npmInfos: INpmPackage[] = p
|
||||
.filter((i) => Boolean(i))
|
||||
.map((i) => ({
|
||||
package: (i as IExternalDependency).package,
|
||||
version: (i as IExternalDependency).version,
|
||||
}));
|
||||
npms.push(...npmInfos);
|
||||
});
|
||||
npms = uniqueArray<INpmPackage>(npms, (i) => i.package);
|
||||
|
||||
@ -227,6 +233,7 @@ class SchemaParser implements ISchemaParser {
|
||||
css: schema.css,
|
||||
constants: schema.constants,
|
||||
config: schema.config || {},
|
||||
meta: schema.meta || {},
|
||||
i18n: schema.i18n,
|
||||
containersDeps,
|
||||
utilsDeps,
|
||||
|
||||
@ -28,22 +28,17 @@ function groupDepsByPack(deps: IDependency[]): Record<string, IDependency[]> {
|
||||
};
|
||||
|
||||
// TODO: main 这个信息到底怎么用,是不是外部包不需要使用?
|
||||
// deps.forEach(dep => {
|
||||
// if (dep.dependencyType === DependencyType.Internal) {
|
||||
// addDep(
|
||||
// `${(dep as IInternalDependency).moduleName}${`/${dep.main}` || ''}`,
|
||||
// dep,
|
||||
// );
|
||||
// } else {
|
||||
// addDep(`${(dep as IExternalDependency).package}${`/${dep.main}` || ''}`, dep);
|
||||
// }
|
||||
// });
|
||||
|
||||
const depMainBlackList = ['lib', 'lib/index', 'es', 'es/index', 'main'];
|
||||
deps.forEach((dep) => {
|
||||
if (dep.dependencyType === DependencyType.Internal) {
|
||||
addDep(`${(dep as IInternalDependency).moduleName}`, dep);
|
||||
addDep(`${(dep as IInternalDependency).moduleName}${dep.main ? `/${dep.main}` : ''}`, dep);
|
||||
} else {
|
||||
addDep(`${(dep as IExternalDependency).package}`, dep);
|
||||
let depMain = '';
|
||||
// TODO: 部分类型的 main 暂时认为没用
|
||||
if (dep.main && depMainBlackList.indexOf(dep.main) < 0) {
|
||||
depMain = dep.main;
|
||||
}
|
||||
addDep(`${(dep as IExternalDependency).package}${depMain ? `/${depMain}` : ''}`, dep);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -304,7 +304,8 @@ function generateEventHandlerAttrForRax(
|
||||
return [
|
||||
{
|
||||
type: PIECE_TYPE.ATTR,
|
||||
value: `${attrName}={${valueExpr}}`,
|
||||
name: attrName,
|
||||
value: valueExpr,
|
||||
},
|
||||
];
|
||||
}
|
||||
@ -316,7 +317,8 @@ function generateEventHandlerAttrForRax(
|
||||
return [
|
||||
{
|
||||
type: PIECE_TYPE.ATTR,
|
||||
value: `${attrName}={${valueExpr}}`,
|
||||
name: attrName,
|
||||
value: valueExpr,
|
||||
},
|
||||
];
|
||||
}
|
||||
@ -336,11 +338,13 @@ function generateEventHandlerAttrForRax(
|
||||
return [
|
||||
...referencedLocalVariables.map((localVar) => ({
|
||||
type: PIECE_TYPE.ATTR,
|
||||
value: `data-${changeCase.snake(localVar)}={${localVar}}`,
|
||||
name: `data-${changeCase.snake(localVar)}`,
|
||||
value: localVar,
|
||||
})),
|
||||
{
|
||||
type: PIECE_TYPE.ATTR,
|
||||
value: `${attrName}={${wrappedAttrValueExpr}}`,
|
||||
name: attrName,
|
||||
value: wrappedAttrValueExpr,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import {
|
||||
ChunkType,
|
||||
FileType,
|
||||
ICodeStruct,
|
||||
IContainerInfo,
|
||||
} from '../../../types';
|
||||
|
||||
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
|
||||
@ -85,7 +85,7 @@ function getNpmDependencies(project: IProjectInfo): NpmInfo[] {
|
||||
const npmDeps: NpmInfo[] = [];
|
||||
const npmNameToPkgMap = new Map<string, NpmInfo>();
|
||||
|
||||
const allDeps = [...(project.containersDeps || []), ...(project.utilsDeps || [])];
|
||||
const allDeps = project.packages;
|
||||
|
||||
allDeps.forEach((dep) => {
|
||||
if (!isNpmInfo(dep)) {
|
||||
|
||||
@ -38,10 +38,7 @@ export interface IProjectInfo {
|
||||
constants?: JSONObject;
|
||||
i18n?: I18nMap;
|
||||
packages: INpmPackage[];
|
||||
meta?: {
|
||||
name?: string;
|
||||
title?: string;
|
||||
};
|
||||
meta?: { name?: string; title?: string } | Record<string, any>;
|
||||
config?: Record<string, any>;
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +43,14 @@ function mergeNodeGeneratorConfig(cfg1: NodeGeneratorConfig, cfg2: NodeGenerator
|
||||
return resCfg;
|
||||
}
|
||||
|
||||
export function isPureString(v: string) {
|
||||
return v[0] === "'" && v[v.length - 1] === "'";
|
||||
}
|
||||
|
||||
export function getPureStringContent(v: string) {
|
||||
return v.substring(1, v.length - 1);
|
||||
}
|
||||
|
||||
function generateAttrValue(
|
||||
attrData: { attrName: string; attrValue: CompositeValue },
|
||||
scope: IScope,
|
||||
@ -84,8 +92,9 @@ function generateAttr(
|
||||
// FIXME: 在经过 generateCompositeType 处理过之后,其实已经无法通过传入值的类型判断传出值是否为纯字面值字符串了(可能包裹了加工函数之类的)
|
||||
// 因此这个处理最好的方式是对传出值做语法分析,判断以哪种模版产出 Attr 值
|
||||
let newValue: string;
|
||||
if (p.value && p.value[0] === "'" && p.value[p.value.length - 1] === "'") {
|
||||
newValue = `"${p.value.substring(1, p.value.length - 1)}"`;
|
||||
if (p.value && isPureString(p.value)) {
|
||||
const content = getPureStringContent(p.value);
|
||||
newValue = `"${content}"`;
|
||||
} else {
|
||||
newValue = `{${p.value}}`;
|
||||
}
|
||||
@ -139,8 +148,17 @@ function generateBasicNode(nodeItem: NodeSchema, scope: IScope, config?: NodeGen
|
||||
function generateSimpleNode(nodeItem: NodeSchema, scope: IScope, config?: NodeGeneratorConfig): CodePiece[] {
|
||||
const basicParts = generateBasicNode(nodeItem, scope, config) || [];
|
||||
const attrParts = generateAttrs(nodeItem, scope, config) || [];
|
||||
const childrenParts: CodePiece[] = [];
|
||||
if (nodeItem.children && config?.self) {
|
||||
const childrenStr = config.self(nodeItem.children, scope);
|
||||
|
||||
return [...basicParts, ...attrParts];
|
||||
childrenParts.push({
|
||||
type: PIECE_TYPE.CHILDREN,
|
||||
value: childrenStr,
|
||||
});
|
||||
}
|
||||
|
||||
return [...basicParts, ...attrParts, ...childrenParts];
|
||||
}
|
||||
|
||||
function linkPieces(pieces: CodePiece[]): string {
|
||||
@ -194,15 +212,6 @@ function generateNodeSchema(nodeItem: NodeSchema, scope: IScope, config?: NodeGe
|
||||
pieces.push(...generateSimpleNode(nodeItem, scope, config));
|
||||
}
|
||||
|
||||
if (nodeItem.children && config?.self) {
|
||||
const childrenStr = config.self(nodeItem.children, scope);
|
||||
|
||||
pieces.push({
|
||||
type: PIECE_TYPE.CHILDREN,
|
||||
value: childrenStr,
|
||||
});
|
||||
}
|
||||
|
||||
return linkPieces(pieces);
|
||||
}
|
||||
|
||||
@ -331,10 +340,16 @@ export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerato
|
||||
});
|
||||
}
|
||||
|
||||
return generateCompositeType(nodeItem, scope, {
|
||||
const valueStr = generateCompositeType(nodeItem, scope, {
|
||||
handlers: cfg.handlers,
|
||||
nodeGenerator: generateNode,
|
||||
});
|
||||
|
||||
if (isPureString(valueStr)) {
|
||||
return getPureStringContent(valueStr);
|
||||
}
|
||||
|
||||
return `{${valueStr}}`;
|
||||
};
|
||||
|
||||
return generateNode;
|
||||
|
||||
@ -99,6 +99,7 @@ export interface ProjectSchema {
|
||||
css?: string;
|
||||
dataSource?: DataSource;
|
||||
config?: Record<string, any>;
|
||||
meta?: Record<string, any>;
|
||||
}
|
||||
|
||||
export function isNodeSchema(data: any): data is NodeSchema {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
tnpm i -g lerna @ali/tyarn
|
||||
tnpm i -g lerna @ali/tyarn tsc
|
||||
|
||||
rm -rf node_modules package-lock.json yarn.lock
|
||||
lerna clean -y
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user