mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
fix: some bugs fixed
This commit is contained in:
parent
d632e7f7e6
commit
42a53b504c
@ -1,6 +1,6 @@
|
|||||||
export * from './api/app';
|
export * from './api/app';
|
||||||
export * from './api/component';
|
export * from './api/component';
|
||||||
export { definePlugin } from './plugin';
|
export { defineRendererPlugin } from './plugin';
|
||||||
export * from './context/render';
|
export * from './context/render';
|
||||||
export * from './context/router';
|
export * from './context/router';
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,6 @@ export const rendererExtends: RendererExtends = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export function definePlugin(plugin: Plugin<RendererExtends>) {
|
export function defineRendererPlugin(plugin: Plugin<RendererExtends>) {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,9 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash-es": "^4.17.12"
|
"@types/lodash-es": "^4.17.12"
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@alilc/lowcode-shared": "workspace:*"
|
||||||
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public",
|
"access": "public",
|
||||||
"registry": "https://registry.npmjs.org/"
|
"registry": "https://registry.npmjs.org/"
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export function createRenderer<Render = IRender>(
|
|||||||
const rendererMain = instantiationService.createInstance(RendererMain);
|
const rendererMain = instantiationService.createInstance(RendererMain);
|
||||||
|
|
||||||
return async (options) => {
|
return async (options) => {
|
||||||
rendererMain.initialize(options);
|
await rendererMain.initialize(options);
|
||||||
|
|
||||||
return rendererMain.startup<Render>(renderAdapter);
|
return rendererMain.startup<Render>(renderAdapter);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -77,8 +77,11 @@ export class RendererMain {
|
|||||||
this.runtimeUtilService.add(util);
|
this.runtimeUtilService.add(util);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const constants = this.schemaService.get('constants') ?? {};
|
||||||
|
|
||||||
const globalScope = this.codeRuntimeService.getScope();
|
const globalScope = this.codeRuntimeService.getScope();
|
||||||
globalScope.setValue({
|
globalScope.setValue({
|
||||||
|
constants,
|
||||||
utils: this.runtimeUtilService.toExpose(),
|
utils: this.runtimeUtilService.toExpose(),
|
||||||
...this.runtimeIntlService.toExpose(),
|
...this.runtimeIntlService.toExpose(),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -54,7 +54,7 @@ export class CodeScope implements ICodeScope {
|
|||||||
if (this.__node.current[name] && !force) {
|
if (this.__node.current[name] && !force) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.__node.current.value[name] = value;
|
this.__node.current[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(value: PlainObject, replace = false) {
|
setValue(value: PlainObject, replace = false) {
|
||||||
|
|||||||
@ -39,7 +39,7 @@ export class SchemaService implements ISchemaService {
|
|||||||
|
|
||||||
initialize(schema: unknown): void {
|
initialize(schema: unknown): void {
|
||||||
if (!isObject(schema)) {
|
if (!isObject(schema)) {
|
||||||
throw Error('schema muse a object');
|
throw Error('schema must a object');
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(schema).forEach((key) => {
|
Object.keys(schema).forEach((key) => {
|
||||||
|
|||||||
@ -1,23 +1,54 @@
|
|||||||
import { type Spec } from '@alilc/lowcode-shared';
|
import { type Spec } from '@alilc/lowcode-shared';
|
||||||
|
|
||||||
const SCHEMA_VALIDATIONS_OPTIONS: Partial<
|
interface ValidationRule<T> {
|
||||||
Record<
|
valid: (value: T) => boolean;
|
||||||
keyof Spec.Project,
|
description: string;
|
||||||
{
|
}
|
||||||
valid: (value: any) => boolean;
|
|
||||||
description: string;
|
type ValidOptionRecord = {
|
||||||
}
|
[K in keyof Spec.Project]: ValidationRule<Spec.Project[K]>;
|
||||||
>
|
};
|
||||||
> = {};
|
|
||||||
|
const SCHEMA_KEYS = [
|
||||||
|
'version',
|
||||||
|
'componentsMap',
|
||||||
|
'componentsTree',
|
||||||
|
'utils',
|
||||||
|
'i18n',
|
||||||
|
'constants',
|
||||||
|
'css',
|
||||||
|
'config',
|
||||||
|
'meta',
|
||||||
|
'router',
|
||||||
|
'pages',
|
||||||
|
];
|
||||||
|
|
||||||
|
const SCHEMA_VALIDATIONS_OPTIONS: Partial<ValidOptionRecord> = {
|
||||||
|
componentsMap: {
|
||||||
|
valid(value) {
|
||||||
|
return Array.isArray(value);
|
||||||
|
},
|
||||||
|
description: 'componentsMap 必须是一个数组',
|
||||||
|
},
|
||||||
|
componentsTree: {
|
||||||
|
valid(value) {
|
||||||
|
return Array.isArray(value);
|
||||||
|
},
|
||||||
|
description: 'componentsTree 必须是一个数组',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export function schemaValidation<K extends keyof Spec.Project>(key: K, value: Spec.Project[K]) {
|
export function schemaValidation<K extends keyof Spec.Project>(key: K, value: Spec.Project[K]) {
|
||||||
|
if (!SCHEMA_KEYS.includes(key)) {
|
||||||
|
return `schema 的字段名必须是${JSON.stringify(SCHEMA_KEYS)}中的一个`;
|
||||||
|
}
|
||||||
|
|
||||||
const validOption = SCHEMA_VALIDATIONS_OPTIONS[key];
|
const validOption = SCHEMA_VALIDATIONS_OPTIONS[key];
|
||||||
|
|
||||||
if (validOption) {
|
if (validOption) {
|
||||||
const result = validOption.valid(value);
|
const result = validOption.valid(value);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw Error(validOption.description);
|
return validOption.description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "@alilc/lowcode-shared",
|
"name": "@alilc/lowcode-shared",
|
||||||
"version": "1.0.0-alpha.0",
|
"version": "1.0.0-alpha.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/low-code-shared.js",
|
"main": "dist/low-code-shared.cjs",
|
||||||
"module": "dist/low-code-shared.js",
|
"module": "dist/low-code-shared.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@ -53,11 +53,10 @@ export class KeyValueStore<O = PlainObject, K extends keyof O = keyof O> {
|
|||||||
if (this.setterValidation) {
|
if (this.setterValidation) {
|
||||||
const valid = this.setterValidation(key, value);
|
const valid = this.setterValidation(key, value);
|
||||||
|
|
||||||
invariant(
|
if (valid !== true) {
|
||||||
valid === false || typeof valid === 'string',
|
console.warn(`failed to config ${key.toString()}, validation error: ${valid ? valid : ''}`);
|
||||||
`failed to config ${key.toString()}, only predefined options can be set under strict mode, predefined options: ${valid ? valid : ''}`,
|
return;
|
||||||
'KeyValueStore',
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.store.set(key, value);
|
this.store.set(key, value);
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import baseConfigFn from '../../vite.base.config'
|
import baseConfigFn from '../../vite.base.config';
|
||||||
|
|
||||||
export default defineConfig(async () => baseConfigFn({
|
export default defineConfig(async () =>
|
||||||
name: 'LowCodeShared',
|
baseConfigFn({
|
||||||
}));
|
name: 'LowCodeShared',
|
||||||
|
defaultFormats: ['es', 'cjs'],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user