mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 19:25:48 +00:00
fix: codes refactor
This commit is contained in:
parent
006b9b615e
commit
a02b19e6e3
2
TODOS.md
2
TODOS.md
@ -10,3 +10,5 @@
|
|||||||
5. test
|
5. test
|
||||||
6. publish
|
6. publish
|
||||||
7. github workflows
|
7. github workflows
|
||||||
|
|
||||||
|
lodaes replace
|
||||||
|
|||||||
@ -64,5 +64,6 @@ export default tseslint.config({
|
|||||||
'react-hooks/exhaustive-deps': 'off', // Checks effect dependencies
|
'react-hooks/exhaustive-deps': 'off', // Checks effect dependencies
|
||||||
|
|
||||||
'no-inner-declarations': 'off',
|
'no-inner-declarations': 'off',
|
||||||
|
'no-constant-condition': 'off',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
38
package.json
38
package.json
@ -20,27 +20,27 @@
|
|||||||
"prepare": "husky"
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/cli": "^2.27.1",
|
"@changesets/cli": "^2.27.7",
|
||||||
"@commitlint/cli": "^19.2.1",
|
"@commitlint/cli": "^19.3.0",
|
||||||
"@commitlint/config-conventional": "^19.1.0",
|
"@commitlint/config-conventional": "^19.2.2",
|
||||||
"@eslint/js": "^8.57.0",
|
"@eslint/js": "^8.57.0",
|
||||||
"@microsoft/api-extractor": "^7.43.0",
|
"@microsoft/api-extractor": "^7.47.4",
|
||||||
"@stylistic/eslint-plugin": "^1.7.0",
|
"@stylistic/eslint-plugin": "^1.8.1",
|
||||||
"@types/node": "^20.11.30",
|
"@types/node": "^22.0.0",
|
||||||
"@vanilla-extract/vite-plugin": "^4.0.7",
|
"@vanilla-extract/vite-plugin": "^4.0.13",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-react": "^7.34.1",
|
"eslint-plugin-react": "^7.35.0",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.2",
|
||||||
"globals": "^15.0.0",
|
"globals": "^15.8.0",
|
||||||
"husky": "^9.0.11",
|
"husky": "^9.1.3",
|
||||||
"jsdom": "^24.1.0",
|
"jsdom": "^24.1.1",
|
||||||
"lint-staged": "^15.2.2",
|
"lint-staged": "^15.2.7",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.3.3",
|
||||||
"rimraf": "^5.0.2",
|
"rimraf": "^6.0.1",
|
||||||
"typescript": "^5.4.2",
|
"typescript": "^5.5.4",
|
||||||
"typescript-eslint": "^7.5.0",
|
"typescript-eslint": "^7.17.0",
|
||||||
"vite": "^5.2.9",
|
"vite": "^5.3.5",
|
||||||
"vitest": "^1.6.0"
|
"vitest": "^1.6.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@ -1,14 +1,19 @@
|
|||||||
import { createRenderer } from '@alilc/lowcode-renderer-core';
|
import { createRenderer } from '@alilc/lowcode-renderer-core';
|
||||||
import { type Root, createRoot } from 'react-dom/client';
|
import { type Root, createRoot } from 'react-dom/client';
|
||||||
import { RendererContext, getRenderInstancesByAccessor } from './context';
|
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
|
||||||
import { ApplicationView, boosts } from '../app';
|
import { ApplicationView, boosts } from '../app';
|
||||||
import { type ReactAppOptions } from './types';
|
import { type ReactAppOptions } from './types';
|
||||||
|
|
||||||
export const createApp = async (options: ReactAppOptions) => {
|
export const createApp = async (options: ReactAppOptions) => {
|
||||||
return createRenderer(async (accessor) => {
|
return createRenderer(async (service) => {
|
||||||
const instances = getRenderInstancesByAccessor(accessor);
|
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
|
||||||
|
return {
|
||||||
|
options,
|
||||||
|
...getRenderInstancesByAccessor(accessor),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
instances.boostsManager.extend(boosts.toExpose());
|
contextValue.boostsManager.extend(boosts.toExpose());
|
||||||
|
|
||||||
let root: Root | undefined;
|
let root: Root | undefined;
|
||||||
|
|
||||||
@ -16,9 +21,8 @@ export const createApp = async (options: ReactAppOptions) => {
|
|||||||
async mount(containerOrId) {
|
async mount(containerOrId) {
|
||||||
if (root) return;
|
if (root) return;
|
||||||
|
|
||||||
const defaultId = instances.schema.get('config')?.targetRootID ?? 'app';
|
const defaultId = contextValue.schema.get<string>('config.targetRootID', 'app');
|
||||||
const rootElement = normalizeContainer(containerOrId, defaultId);
|
const rootElement = normalizeContainer(containerOrId, defaultId);
|
||||||
const contextValue = { ...instances, options };
|
|
||||||
|
|
||||||
root = createRoot(rootElement);
|
root = createRoot(rootElement);
|
||||||
root.render(
|
root.render(
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import { createRenderer } from '@alilc/lowcode-renderer-core';
|
import { createRenderer } from '@alilc/lowcode-renderer-core';
|
||||||
import { FunctionComponent } from 'react';
|
import { type ComponentTreeRoot } from '@alilc/lowcode-shared';
|
||||||
|
import { type FunctionComponent } from 'react';
|
||||||
import {
|
import {
|
||||||
type LowCodeComponentProps,
|
type LowCodeComponentProps,
|
||||||
createComponent as createSchemaComponent,
|
createComponent as createSchemaComponent,
|
||||||
} from '../runtime/createComponent';
|
} from '../runtime/createComponent';
|
||||||
import { RendererContext, getRenderInstancesByAccessor } from './context';
|
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
|
||||||
import { type ReactAppOptions } from './types';
|
import { type ReactAppOptions } from './types';
|
||||||
|
|
||||||
interface Render {
|
interface Render {
|
||||||
@ -12,17 +13,25 @@ interface Render {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createComponent(options: ReactAppOptions) {
|
export async function createComponent(options: ReactAppOptions) {
|
||||||
const creator = createRenderer<Render>((accessor) => {
|
const creator = createRenderer<Render>((service) => {
|
||||||
const instances = getRenderInstancesByAccessor(accessor);
|
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
|
||||||
const componentsTree = instances.schema.get('componentsTree')[0];
|
return {
|
||||||
|
options,
|
||||||
|
...getRenderInstancesByAccessor(accessor),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const componentsTree = contextValue.schema.get<ComponentTreeRoot>('componentsTree.0');
|
||||||
|
|
||||||
|
if (!componentsTree) {
|
||||||
|
throw new Error('componentsTree is required');
|
||||||
|
}
|
||||||
|
|
||||||
const LowCodeComponent = createSchemaComponent(componentsTree, {
|
const LowCodeComponent = createSchemaComponent(componentsTree, {
|
||||||
displayName: componentsTree.componentName,
|
displayName: componentsTree.componentName,
|
||||||
...options.component,
|
...options.component,
|
||||||
});
|
});
|
||||||
|
|
||||||
const contextValue = { ...instances, options };
|
|
||||||
|
|
||||||
function Component(props: LowCodeComponentProps) {
|
function Component(props: LowCodeComponentProps) {
|
||||||
return (
|
return (
|
||||||
<RendererContext.Provider value={contextValue}>
|
<RendererContext.Provider value={contextValue}>
|
||||||
|
|||||||
@ -12,15 +12,14 @@ const buildTypes = args['types'] || args['t'];
|
|||||||
async function run() {
|
async function run() {
|
||||||
const packages = await findWorkspacePackages(cwd());
|
const packages = await findWorkspacePackages(cwd());
|
||||||
const targetPackageName = `@alilc/lowcode-${targets[0]}`;
|
const targetPackageName = `@alilc/lowcode-${targets[0]}`;
|
||||||
const finalName = packages
|
const manifest = packages.filter((item) => item.manifest.name === targetPackageName)[0].manifest;
|
||||||
.filter((item) => item.manifest.name === targetPackageName)
|
|
||||||
.map(item => item.manifest.name);
|
|
||||||
|
|
||||||
await execa('pnpm', ['--filter', finalName[0], 'build:target'], {
|
await execa('pnpm', ['--filter', manifest.name, 'build:target'], {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
env: {
|
env: {
|
||||||
PROD: prod,
|
PROD: prod,
|
||||||
FORMATS: formatArgs ? formatArgs : !prod ? 'es' : undefined,
|
FORMATS: formatArgs ? formatArgs : !prod ? 'es' : undefined,
|
||||||
|
VERSION: manifest.version,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
"importHelpers": false,
|
"importHelpers": false,
|
||||||
// Enables experimental support for ES7 decorators.
|
// Enables experimental support for ES7 decorators.
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
|
||||||
// Generates corresponding .map file.
|
// Generates corresponding .map file.
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
// Disallow inconsistently-cased references to the same file.
|
// Disallow inconsistently-cased references to the same file.
|
||||||
@ -37,7 +36,7 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"@alilc/lowcode-*": ["packages/*/src"]
|
"@alilc/lowcode-*": ["packages/*/src"]
|
||||||
},
|
},
|
||||||
"types": ["vite/client", "vitest/globals", "node"]
|
"types": ["vitest/globals", "node"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"packages/global.d.ts",
|
"packages/global.d.ts",
|
||||||
|
|||||||
@ -32,6 +32,10 @@ export default async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return defineConfig({
|
return defineConfig({
|
||||||
|
define: {
|
||||||
|
__DEV__: JSON.stringify(!isProduction),
|
||||||
|
__VERSION__: JSON.stringify(env['VERSION']),
|
||||||
|
},
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolvePath(entry),
|
entry: resolvePath(entry),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user