Skip to content

Commit

Permalink
chore: add env format for vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Apr 3, 2024
1 parent 1149044 commit cdb9445
Show file tree
Hide file tree
Showing 28 changed files with 154 additions and 100 deletions.
6 changes: 4 additions & 2 deletions packages/designer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, type LibraryFormats } from 'vite';
import { resolve } from 'node:path';
import { env } from 'node:process';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeDesigner',
formats: ['es', 'cjs'],
formats,
// the proper extensions will be added
fileName: 'designer',
},
Expand Down
6 changes: 4 additions & 2 deletions packages/editor-core/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, type LibraryFormats } from 'vite';
import { resolve } from 'node:path';
import { env } from 'node:process';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeEditorCore',
formats: ['es'],
formats,
// the proper extensions will be added
fileName: 'editorCore',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ export class SettingsPrimaryPane extends Component<
return (
<div className="lc-settings-navigator">
{createIcon(this.main.componentMeta?.icon, {
className: 'lc-settings-navigator-icon',
class: 'lc-settings-navigator-icon',
className: 'lc-settings-navigator-icon'
})}
<Breadcrumb className="lc-settings-node-breadcrumb">{items}</Breadcrumb>
</div>
Expand Down
7 changes: 0 additions & 7 deletions packages/editor-skeleton/src/widget/panel-dock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ export class PanelDock implements IWidget {
showPanel() {
this.panel?.setActive(true);
}

/**
* @deprecated
*/
onActiveChange(func: () => any) {
return this.panel?.onActiveChange(func);
}
}

export function isPanelDock(obj: any): obj is PanelDock {
Expand Down
31 changes: 0 additions & 31 deletions packages/editor-skeleton/src/widget/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,37 +234,6 @@ export class Panel implements IWidget {
return isPanelDock(item) && item.panelName === this.name;
}) as any;
}

/**
* @deprecated
*/
getSupportedPositions() {
return ['default'];
}

/**
* @deprecated
*/
getCurrentPosition() {
return 'default';
}

/**
* @deprecated
*/
setPosition(/* position: string */) {
// noop
}

/**
* @deprecated
*/
onActiveChange(fn: (flag: boolean) => void): () => void {
this.emitter.on('activechange', fn);
return () => {
this.emitter.removeListener('activechange', fn);
};
}
}

export function isPanel(obj: any): obj is Panel {
Expand Down
6 changes: 4 additions & 2 deletions packages/editor-skeleton/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, type LibraryFormats } from 'vite';
import { resolve } from 'node:path';
import { env } from 'node:process'
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeEditorSkeleton',
formats: ['es', 'cjs'],
formats,
// the proper extensions will be added
fileName: 'editorSkeleton',
},
Expand Down
1 change: 0 additions & 1 deletion packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@alilc/lowcode-designer": "workspace:*",
"@alilc/lowcode-editor-core": "workspace:*",
"@alilc/lowcode-editor-skeleton": "workspace:*",
"@alilc/lowcode-engine-ext": "^1.0.0",
"@alilc/lowcode-plugin-command": "workspace:*",
"@alilc/lowcode-plugin-designer": "workspace:*",
"@alilc/lowcode-plugin-outline-pane": "workspace:*",
Expand Down
33 changes: 18 additions & 15 deletions packages/engine/src/engine-core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable max-len */
/* eslint-disable no-param-reassign */
import { createElement } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { createRoot, type Root } from 'react-dom/client';
import {
globalContext,
Editor,
Expand Down Expand Up @@ -210,13 +208,14 @@ engineConfig.set('isOpenSource', isOpenSource);

// container which will host LowCodeEngine DOM
let engineContainer: HTMLElement;
// @ts-ignore webpack Define variable

export { version }
engineConfig.set('ENGINE_VERSION', version);

const pluginPromise = registryInnerPlugin(designer, editor, plugins);

let root: Root | undefined;

export async function init(
container?: HTMLElement,
options?: IPublicTypeEngineOptions,
Expand Down Expand Up @@ -244,15 +243,19 @@ export async function init(
if (options && options.enableWorkspaceMode) {
const disposeFun = await pluginPromise;
disposeFun && disposeFun();
render(
createElement(WorkSpaceWorkbench, {

if (!root) {
root = createRoot(
engineContainer,
);
root.render(createElement(WorkSpaceWorkbench, {
workspace: innerWorkspace,
// skeleton: workspace.skeleton,
className: 'engine-main',
topAreaItemClassName: 'engine-actionitem',
}),
engineContainer,
);
}))
}

innerWorkspace.enableAutoOpenFirstWindow = engineConfig.get('enableAutoOpenFirstWindow', true);
innerWorkspace.setActive(true);
innerWorkspace.initWindow();
Expand All @@ -263,14 +266,14 @@ export async function init(

await plugins.init(pluginPreference as any);

render(
createElement(Workbench, {
if (!root) {
root = createRoot(engineContainer)
root.render(createElement(Workbench, {
skeleton: innerSkeleton,
className: 'engine-main',
topAreaItemClassName: 'engine-actionitem',
}),
engineContainer,
);
}))
}
}

export async function destroy() {
Expand All @@ -284,5 +287,5 @@ export async function destroy() {

// unmount DOM container, this will trigger React componentWillUnmount lifeCycle,
// so necessary cleanups will be done.
engineContainer && unmountComponentAtNode(engineContainer);
root && root.unmount();
}
9 changes: 5 additions & 4 deletions packages/engine/src/inner-plugins/setter-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ export const setterRegistry = (ctx: IPublicModelPluginContext) => {
init() {
const { config } = ctx;
if (config.get('disableDefaultSetters')) return;
const builtinSetters = require('@alilc/lowcode-engine-ext')?.setters;
if (builtinSetters) {
ctx.setters.registerSetter(builtinSetters);
}
// todo: 互相依赖
// const builtinSetters = require('@alilc/lowcode-engine-ext')?.setters;
// if (builtinSetters) {
// ctx.setters.registerSetter(builtinSetters);
// }
},
};
};
Expand Down
7 changes: 5 additions & 2 deletions packages/engine/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, LibraryFormats } from 'vite';
import { resolve } from 'node:path';
import { env } from 'node:process';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'AliLowCodeEngine',
formats: ['es', 'cjs', 'iife'],
formats,
// the proper extensions will be added
fileName: 'engine',
},
Expand All @@ -22,6 +24,7 @@ export default defineConfig({
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'@alifd/next': 'Next'
},
},
},
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-command/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { defineConfig } from 'vite';
import { defineConfig, LibraryFormats } from 'vite';
import { resolve } from 'node:path';
import { env } from 'node:process';

const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodePluginCommand',
formats: ['es', 'cjs'],
formats,
// the proper extensions will be added
fileName: 'plugin-command',
},
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-designer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, LibraryFormats } from 'vite';
import { env } from 'node:process';
import { resolve } from 'node:path';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.tsx'),
name: 'LowCodePluginDesigner',
formats: ['es', 'cjs'],
formats,
// the proper extensions will be added
fileName: 'plugin-designer',
},
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-outline-pane/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, LibraryFormats } from 'vite';
import { env } from 'node:process';
import { resolve } from 'node:path';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.tsx'),
name: 'LowCodePluginOutlinePane',
formats: ['es', 'cjs'],
formats,
// the proper extensions will be added
fileName: 'plugin-outline-pane',
},
Expand Down
6 changes: 4 additions & 2 deletions packages/react-renderer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, LibraryFormats } from 'vite';
import { env } from 'node:process';
import { resolve } from 'node:path';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs', 'iife']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeReactRenderer',
formats: ['es', 'cjs', 'iife'],
formats,
// the proper extensions will be added
fileName: 'reactRenderer',
},
Expand Down
6 changes: 4 additions & 2 deletions packages/react-simulator-renderer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { defineConfig } from 'vite';
import { defineConfig, LibraryFormats } from 'vite';
import { env } from 'node:process';
import { resolve } from 'node:path';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';

const externals = [...Object.keys(devDependencies), ...Object.keys(peerDependencies)];
const formats = (env['FORMATS']?.split(',') ?? ['es', 'cjs', 'iife']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeSimulatorReactRenderer',
formats: ['es', 'cjs', 'iife'],
formats,
// the proper extensions will be added
fileName: 'SimulatorReactRenderer',
},
Expand Down
7 changes: 5 additions & 2 deletions packages/renderer-core/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { defineConfig } from 'vite';
import { defineConfig, LibraryFormats } from 'vite';
import { env } from 'node:process';
import { resolve } from 'node:path';

const formats = (env['FORMATS']?.split(',') ?? ['es']) as LibraryFormats[];

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeRendererCore',
formats: ['es'],
formats,
// the proper extensions will be added
fileName: 'rendererCore',
},
Expand Down
Loading

0 comments on commit cdb9445

Please sign in to comment.