feat(cli,data-source,editor,playground,runtime): 支持自定义数据源
This commit is contained in:
@@ -23,9 +23,14 @@ import legacy from '@vitejs/plugin-legacy';
|
||||
import reactRefresh from '@vitejs/plugin-react-refresh';
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
if (['value', 'config', 'event', 'value:admin', 'config:admin', 'event:admin'].includes(mode)) {
|
||||
const [type, isAdmin] = mode.split(':');
|
||||
const capitalToken = type.charAt(0).toUpperCase() + type.slice(1);
|
||||
if (['value', 'config', 'event', 'ds:value', 'ds:config', 'ds:event'].includes(mode)) {
|
||||
const capitalToken = mode
|
||||
.split(':')
|
||||
.map((word) => word[0].toUpperCase() + word.slice(1))
|
||||
.join('');
|
||||
|
||||
const fileName = mode.replace(':', '-');
|
||||
|
||||
return {
|
||||
publicDir: './.tmagic/public',
|
||||
build: {
|
||||
@@ -33,10 +38,10 @@ export default defineConfig(({ mode }) => {
|
||||
sourcemap: true,
|
||||
minify: false,
|
||||
target: 'esnext',
|
||||
outDir: isAdmin ? `./dist/entry/${type}` : `../../playground/public/entry/react/${type}`,
|
||||
outDir: `../../playground/public/entry/react/${fileName}`,
|
||||
|
||||
lib: {
|
||||
entry: `.tmagic/${type}-entry.ts`,
|
||||
entry: `.tmagic/${fileName}-entry.ts`,
|
||||
name: `magicPreset${capitalToken}s`,
|
||||
fileName: 'index',
|
||||
formats: ['umd'],
|
||||
@@ -45,12 +50,7 @@ export default defineConfig(({ mode }) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (['page', 'playground', 'page:admin', 'playground:admin'].includes(mode)) {
|
||||
const [type, isAdmin] = mode.split(':');
|
||||
const base = isAdmin ? `/static/react/runtime/${type}/` : `/tmagic-editor/playground/runtime/react/${type}`;
|
||||
const outDir = isAdmin
|
||||
? path.resolve(process.cwd(), `./dist/runtime/${type}`)
|
||||
: path.resolve(process.cwd(), `../../playground/public/runtime/react/${type}`);
|
||||
if (['page', 'playground'].includes(mode)) {
|
||||
return {
|
||||
plugins: [
|
||||
reactRefresh(),
|
||||
@@ -59,16 +59,16 @@ export default defineConfig(({ mode }) => {
|
||||
}),
|
||||
],
|
||||
|
||||
root: `./${type}/`,
|
||||
root: `./${mode}/`,
|
||||
|
||||
publicDir: '../public',
|
||||
|
||||
base,
|
||||
base: `/tmagic-editor/playground/runtime/react/${mode}`,
|
||||
|
||||
build: {
|
||||
emptyOutDir: true,
|
||||
sourcemap: true,
|
||||
outDir,
|
||||
outDir: path.resolve(process.cwd(), `../../playground/public/runtime/react/${mode}`),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,23 +6,21 @@
|
||||
"scripts": {
|
||||
"dev:react": "npm run build:libs && vite --config dev.vite.config.ts",
|
||||
"build": "npm run build:libs && npm run build:page && npm run build:playground",
|
||||
"build:admin": "npm run build:libs:admin && npm run build:page:admin && npm run build:playground:admin",
|
||||
"build:page": "vite build --config build.vite.config.ts --mode page",
|
||||
"build:playground": "vite build --config build.vite.config.ts --mode playground",
|
||||
"build:page:admin": "vite build --config build.vite.config.ts --mode page:admin",
|
||||
"build:playground:admin": "vite build --config build.vite.config.ts --mode playground:admin",
|
||||
"build:libs": "tmagic entry && npm run build:config && npm run build:value && npm run build:event",
|
||||
"build:libs:admin": "tmagic entry && npm run build:config:admin && npm run build:value:admin && npm run build:event:admin",
|
||||
"build:libs": "tmagic entry && npm run build:config && npm run build:value && npm run build:event && npm run build:ds:libs",
|
||||
"build:ds:libs": "npm run build:ds:config && npm run build:ds:value && npm run build:ds:event",
|
||||
"build:config": "vite build --config build.vite.config.ts --mode config",
|
||||
"build:value": "vite build --config build.vite.config.ts --mode value",
|
||||
"build:event": "vite build --config build.vite.config.ts --mode event",
|
||||
"build:config:admin": "vite build --config build.vite.config.ts --mode config:admin",
|
||||
"build:value:admin": "vite build --config build.vite.config.ts --mode value:admin",
|
||||
"build:event:admin": "vite build --config build.vite.config.ts --mode event:admin"
|
||||
"build:ds:config": "vite build --config build.vite.config.ts --mode ds:config",
|
||||
"build:ds:value": "vite build --config build.vite.config.ts --mode ds:value",
|
||||
"build:ds:event": "vite build --config build.vite.config.ts --mode ds:event"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/cli": "1.3.0-alpha.19",
|
||||
"@tmagic/core": "1.3.0-alpha.19",
|
||||
"@tmagic/data-source": "1.3.0-alpha.19",
|
||||
"@tmagic/ui-react": "1.3.0-alpha.19",
|
||||
"@tmagic/schema": "1.3.0-alpha.19",
|
||||
"@tmagic/stage": "1.3.0-alpha.19",
|
||||
|
||||
@@ -19,11 +19,13 @@ import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import Core from '@tmagic/core';
|
||||
import { DataSourceManager } from '@tmagic/data-source';
|
||||
import type { MApp } from '@tmagic/schema';
|
||||
import { AppContent } from '@tmagic/ui-react';
|
||||
import { getUrlParam } from '@tmagic/utils';
|
||||
|
||||
import components from '../.tmagic/comp-entry';
|
||||
import datasources from '../.tmagic/datasource-entry';
|
||||
import plugins from '../.tmagic/plugin-entry';
|
||||
|
||||
import App from './App';
|
||||
@@ -51,6 +53,10 @@ const getLocalConfig = (): MApp[] => {
|
||||
|
||||
window.magicDSL = [];
|
||||
|
||||
Object.entries(datasources).forEach(([type, ds]: [string, any]) => {
|
||||
DataSourceManager.registe(type, ds);
|
||||
});
|
||||
|
||||
const app = new Core({
|
||||
ua: window.navigator.userAgent,
|
||||
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
|
||||
@@ -60,6 +66,7 @@ const app = new Core({
|
||||
app.setDesignWidth(app.env.isWeb ? window.document.documentElement.getBoundingClientRect().width : 375);
|
||||
|
||||
Object.keys(components).forEach((type: string) => app.registerComponent(type, components[type]));
|
||||
|
||||
Object.values(plugins).forEach((plugin: any) => {
|
||||
plugin.install(app);
|
||||
});
|
||||
|
||||
@@ -21,12 +21,14 @@ import ReactDOM from 'react-dom';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
import Core from '@tmagic/core';
|
||||
import { DataSourceManager } from '@tmagic/data-source';
|
||||
import type { MApp } from '@tmagic/schema';
|
||||
import type { RemoveData, SortEventData, UpdateData } from '@tmagic/stage';
|
||||
import { AppContent } from '@tmagic/ui-react';
|
||||
import { replaceChildNode } from '@tmagic/utils';
|
||||
|
||||
import components from '../.tmagic/comp-entry';
|
||||
import datasources from '../.tmagic/datasource-entry';
|
||||
import plugins from '../.tmagic/plugin-entry';
|
||||
|
||||
import App from './App';
|
||||
@@ -39,6 +41,10 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
Object.entries(datasources).forEach(([type, ds]: [string, any]) => {
|
||||
DataSourceManager.registe(type, ds);
|
||||
});
|
||||
|
||||
const app = new Core({
|
||||
ua: window.navigator.userAgent,
|
||||
platform: 'editor',
|
||||
|
||||
Reference in New Issue
Block a user