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