@morningfast/create-ui 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -55
- package/dist/templates/main-app/README.md +1 -1
- package/dist/templates/main-app/package.json +1 -1
- package/dist/templates/main-app/src/micro-apps/demo-apps.ts +1 -1
- package/dist/templates/main-app/src/router/business-routes.ts +21 -2
- package/dist/templates/main-app/src/router/mock-routes.ts +3 -74
- package/dist/templates/main-app/src/setup.ts +1 -2
- package/dist/templates/sub-app/package.json +1 -1
- package/dist/templates/sub-app/src/router/business-routes.ts +21 -0
- package/dist/templates/sub-app/src/router/index.ts +2 -2
- package/dist/templates/sub-app/src/router/mock-routes.ts +3 -39
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -809,9 +809,9 @@ async function customizeAppTemplate(appRoot, variables) {
|
|
|
809
809
|
if (!variables.keepDemo) {
|
|
810
810
|
await rm(path.join(appRoot, "src", "pages", "demo"), { recursive: true, force: true });
|
|
811
811
|
await rm(path.join(appRoot, "src", "micro-apps", "demo-apps.ts"), { force: true });
|
|
812
|
-
await
|
|
813
|
-
await
|
|
814
|
-
await
|
|
812
|
+
await rm(path.join(appRoot, "src", "router", "mock-routes.ts"), { force: true });
|
|
813
|
+
await removeDemoRoute(path.join(appRoot, "src", "router", "business-routes.ts"));
|
|
814
|
+
await removeSubAppDemoRedirect(path.join(appRoot, "src", "router", "index.ts"));
|
|
815
815
|
await removeMainAppDemoSetup(path.join(appRoot, "src", "setup.ts"));
|
|
816
816
|
}
|
|
817
817
|
}
|
|
@@ -882,9 +882,7 @@ async function removeDemoRoute(filePath) {
|
|
|
882
882
|
return;
|
|
883
883
|
}
|
|
884
884
|
const source = await readFile(filePath, "utf8");
|
|
885
|
-
|
|
886
|
-
updated = removeRouteObject(updated, "path: 'micro'");
|
|
887
|
-
updated = updated.replace(/\n\s+'demo-user-management': \(\) => import\('@\/pages\/demo\/user-management\/index\.vue'\),/g, "").replace(/\n\s+'demo-mapping-config': \(\) => import\('@\/pages\/demo\/mapping-config\/index\.vue'\),/g, "").replace(/\n\s+'demo-table-page': \(\) => import\('@\/pages\/demo\/table-page-demo\/index\.vue'\),/g, "").replace(/\n\s+'demo-upload': \(\) => import\('@\/pages\/demo\/upload-demo\/index\.vue'\),/g, "");
|
|
885
|
+
const updated = source.replace(/\nimport \{ mockComponentMap, mockRouteItems \} from '\.\/mock-routes';?\n/, "\n").replace(/\n\s+\.\.\.mockRouteItems,/g, "").replace(/\n\s+\.\.\.mockComponentMap,/g, "").replace(/\n{3,}/g, "\n\n");
|
|
888
886
|
if (updated !== source) {
|
|
889
887
|
await writeFile(filePath, updated, "utf8");
|
|
890
888
|
}
|
|
@@ -894,45 +892,15 @@ async function removeMainAppDemoSetup(filePath) {
|
|
|
894
892
|
return;
|
|
895
893
|
}
|
|
896
894
|
const source = await readFile(filePath, "utf8");
|
|
897
|
-
const updated = source.replace(
|
|
895
|
+
const updated = source.replace(
|
|
896
|
+
/import \{ setDefaultAppConfigs, type MountMorningfastAppContext \} from '@morningfast\/platform\/main';\n/,
|
|
897
|
+
"import type { MountMorningfastAppContext } from '@morningfast/platform/main';\n"
|
|
898
|
+
).replace(/\nimport \{ setDefaultAppConfigs \} from '@morningfast\/platform\/main\/micro-apps\/config';\n/, "\n").replace(/\nimport \{ demoAppConfigs \} from '\.\/micro-apps\/demo-apps';\n/, "\n").replace(/\n\s+setDefaultAppConfigs\(demoAppConfigs\);\n/, "\n").replace(/\n{3,}/g, "\n\n").replace(/\{\n\n\s+\/\//g, "{\n //");
|
|
898
899
|
if (updated !== source) {
|
|
899
900
|
await writeFile(filePath, updated, "utf8");
|
|
900
901
|
}
|
|
901
902
|
}
|
|
902
|
-
function
|
|
903
|
-
const markerIndex = source.indexOf(marker);
|
|
904
|
-
if (markerIndex < 0) {
|
|
905
|
-
return source;
|
|
906
|
-
}
|
|
907
|
-
const objectStart = source.lastIndexOf(" {", markerIndex);
|
|
908
|
-
if (objectStart < 0) {
|
|
909
|
-
return source;
|
|
910
|
-
}
|
|
911
|
-
let index = objectStart;
|
|
912
|
-
let depth = 0;
|
|
913
|
-
let objectEnd = -1;
|
|
914
|
-
for (; index < source.length; index += 1) {
|
|
915
|
-
const char = source[index];
|
|
916
|
-
if (char === "{") {
|
|
917
|
-
depth += 1;
|
|
918
|
-
} else if (char === "}") {
|
|
919
|
-
depth -= 1;
|
|
920
|
-
if (depth === 0) {
|
|
921
|
-
objectEnd = index + 1;
|
|
922
|
-
break;
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
if (objectEnd < 0) {
|
|
927
|
-
return source;
|
|
928
|
-
}
|
|
929
|
-
const trailingCommaEnd = source.slice(objectEnd).match(/^,\n?/)?.[0].length ?? 0;
|
|
930
|
-
const leadingCommaStart = trailingCommaEnd ? objectStart : source.lastIndexOf(",", objectStart);
|
|
931
|
-
const removeStart = leadingCommaStart >= 0 && source.slice(leadingCommaStart, objectStart).trim() === "" ? leadingCommaStart : objectStart;
|
|
932
|
-
const removeEnd = objectEnd + trailingCommaEnd;
|
|
933
|
-
return source.slice(0, removeStart) + source.slice(removeEnd);
|
|
934
|
-
}
|
|
935
|
-
async function removeSubAppDemoRoute(filePath) {
|
|
903
|
+
async function removeSubAppDemoRedirect(filePath) {
|
|
936
904
|
if (!existsSync(filePath)) {
|
|
937
905
|
return;
|
|
938
906
|
}
|
|
@@ -940,25 +908,11 @@ async function removeSubAppDemoRoute(filePath) {
|
|
|
940
908
|
const updated = source.replace(
|
|
941
909
|
/\n\s+\{\n\s+path: '\/orders',\n\s+redirect: '\/demo\/orders',\n\s+\},/g,
|
|
942
910
|
""
|
|
943
|
-
).replace(
|
|
944
|
-
/\n\s+\{\n\s+path: '\/demo\/orders',\n\s+name: 'demo-orders',\n\s+component: \(\) => import\('@\/pages\/demo\/orders\/index\.vue'\),\n\s+meta: \{\n\s+title: '订单管理',\n\s+\},\n\s+\},/g,
|
|
945
|
-
""
|
|
946
911
|
);
|
|
947
912
|
if (updated !== source) {
|
|
948
913
|
await writeFile(filePath, updated, "utf8");
|
|
949
914
|
}
|
|
950
915
|
}
|
|
951
|
-
async function removeSubAppDemoMockRoute(filePath) {
|
|
952
|
-
if (!existsSync(filePath)) {
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
const source = await readFile(filePath, "utf8");
|
|
956
|
-
let updated = removeRouteObject(source, "path: '/demo/orders'");
|
|
957
|
-
updated = updated.replace(/\n\s+'demo-orders': \(\) => import\('@\/pages\/demo\/orders\/index\.vue'\),/g, "");
|
|
958
|
-
if (updated !== source) {
|
|
959
|
-
await writeFile(filePath, updated, "utf8");
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
916
|
async function replaceText(filePath, searchValue, replaceValue) {
|
|
963
917
|
if (!existsSync(filePath)) {
|
|
964
918
|
return;
|
|
@@ -82,7 +82,7 @@ pnpm --filter __MORNINGFAST_SUB_APP_DIR__ dev
|
|
|
82
82
|
4. 保存后刷新主应用。
|
|
83
83
|
5. 通过主应用菜单进入该子应用路径。
|
|
84
84
|
|
|
85
|
-
子应用菜单路由复用同一个平台承载页,不需要为每个子应用新增 `componentKey` 或组件映射。完全新增一个子应用菜单时,在 `src/router/
|
|
85
|
+
子应用菜单路由复用同一个平台承载页,不需要为每个子应用新增 `componentKey` 或组件映射。完全新增一个子应用菜单时,在 `src/router/business-routes.ts` 里写 `microApp: true` 即可:
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
88
|
{
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
2
|
+
import { createRoutesFromItems, type AppRouteItem } from '@morningfast/platform/main';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { mockComponentMap, mockRouteItems } from './mock-routes';
|
|
5
|
+
|
|
6
|
+
export const businessRouteItems: AppRouteItem[] = [
|
|
7
|
+
{
|
|
8
|
+
path: 'dashboard',
|
|
9
|
+
name: 'dashboard',
|
|
10
|
+
title: '首页',
|
|
11
|
+
icon: 'House',
|
|
12
|
+
componentKey: 'dashboard',
|
|
13
|
+
},
|
|
14
|
+
...mockRouteItems,
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const componentMap: Record<string, RouteRecordRaw['component']> = {
|
|
18
|
+
dashboard: () => import('@/pages/dashboard/Workplace.vue'),
|
|
19
|
+
...mockComponentMap,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const businessRoutes = createRoutesFromItems(businessRouteItems, componentMap);
|
|
@@ -1,36 +1,7 @@
|
|
|
1
1
|
import type { RouteRecordRaw } from 'vue-router';
|
|
2
|
-
import {
|
|
2
|
+
import type { AppRouteItem } from '@morningfast/platform/main';
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
path: string;
|
|
6
|
-
name: string;
|
|
7
|
-
title: string;
|
|
8
|
-
icon?: string;
|
|
9
|
-
permission?: string;
|
|
10
|
-
hidden?: boolean;
|
|
11
|
-
redirect?: string;
|
|
12
|
-
componentKey?: string;
|
|
13
|
-
microApp?: boolean;
|
|
14
|
-
children?: MockRouteItem[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type MutableRouteRecord = {
|
|
18
|
-
path: string;
|
|
19
|
-
name: string;
|
|
20
|
-
redirect?: string;
|
|
21
|
-
component?: RouteRecordRaw['component'];
|
|
22
|
-
children?: RouteRecordRaw[];
|
|
23
|
-
meta: NonNullable<RouteRecordRaw['meta']>;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const mockRouteItems: MockRouteItem[] = [
|
|
27
|
-
{
|
|
28
|
-
path: 'dashboard',
|
|
29
|
-
name: 'dashboard',
|
|
30
|
-
title: '首页',
|
|
31
|
-
icon: 'House',
|
|
32
|
-
componentKey: 'dashboard',
|
|
33
|
-
},
|
|
4
|
+
export const mockRouteItems: AppRouteItem[] = [
|
|
34
5
|
{
|
|
35
6
|
path: 'demo',
|
|
36
7
|
name: 'demo',
|
|
@@ -87,53 +58,11 @@ export const mockRouteItems: MockRouteItem[] = [
|
|
|
87
58
|
},
|
|
88
59
|
],
|
|
89
60
|
},
|
|
90
|
-
{
|
|
91
|
-
path: 'micro2/sub-app-2/demo/orders',
|
|
92
|
-
name: 'micro2-sub-app2-demo-orders',
|
|
93
|
-
title: '订单管理',
|
|
94
|
-
microApp: true,
|
|
95
|
-
},
|
|
96
61
|
];
|
|
97
62
|
|
|
98
|
-
const
|
|
99
|
-
dashboard: () => import('@/pages/dashboard/Workplace.vue'),
|
|
63
|
+
export const mockComponentMap: Record<string, RouteRecordRaw['component']> = {
|
|
100
64
|
'demo-user-management': () => import('@/pages/demo/user-management/index.vue'),
|
|
101
65
|
'demo-mapping-config': () => import('@/pages/demo/mapping-config/index.vue'),
|
|
102
66
|
'demo-table-page': () => import('@/pages/demo/table-page-demo/index.vue'),
|
|
103
67
|
'demo-upload': () => import('@/pages/demo/upload-demo/index.vue'),
|
|
104
68
|
};
|
|
105
|
-
|
|
106
|
-
export function createRoutesFromMock(items = mockRouteItems): RouteRecordRaw[] {
|
|
107
|
-
return items.map(createRouteFromMock);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function createRouteFromMock(item: MockRouteItem): RouteRecordRaw {
|
|
111
|
-
const route: MutableRouteRecord = {
|
|
112
|
-
path: item.path,
|
|
113
|
-
name: item.name,
|
|
114
|
-
meta: {
|
|
115
|
-
title: item.title,
|
|
116
|
-
icon: item.icon,
|
|
117
|
-
permission: item.permission,
|
|
118
|
-
hidden: item.hidden,
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
if (item.redirect) {
|
|
123
|
-
route.redirect = item.redirect;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (item.componentKey) {
|
|
127
|
-
route.component = componentMap[item.componentKey];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (item.microApp) {
|
|
131
|
-
route.component = MicroAppView;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (item.children?.length) {
|
|
135
|
-
route.children = createRoutesFromMock(item.children);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return route as RouteRecordRaw;
|
|
139
|
-
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { setDefaultAppConfigs } from '@morningfast/platform/main/micro-apps/config';
|
|
1
|
+
import { setDefaultAppConfigs, type MountMorningfastAppContext } from '@morningfast/platform/main';
|
|
3
2
|
|
|
4
3
|
import { demoAppConfigs } from './micro-apps/demo-apps';
|
|
5
4
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RouteRecordRaw } from 'vue-router'
|
|
2
|
+
import { createRoutesFromItems, type RouteItem } from '@morningfast/platform/sub'
|
|
3
|
+
|
|
4
|
+
import { mockComponentMap, mockRouteItems } from './mock-routes'
|
|
5
|
+
|
|
6
|
+
export const businessRouteItems: RouteItem[] = [
|
|
7
|
+
{
|
|
8
|
+
path: '/home',
|
|
9
|
+
name: 'home',
|
|
10
|
+
title: '工作台',
|
|
11
|
+
componentKey: 'home',
|
|
12
|
+
},
|
|
13
|
+
...mockRouteItems,
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
const componentMap: Record<string, RouteRecordRaw['component']> = {
|
|
17
|
+
home: () => import('@/pages/home/index.vue'),
|
|
18
|
+
...mockComponentMap,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const businessRoutes = createRoutesFromItems(businessRouteItems, componentMap)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RouteRecordRaw } from 'vue-router'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { businessRoutes } from './business-routes'
|
|
4
4
|
|
|
5
5
|
export const routes: RouteRecordRaw[] = [
|
|
6
6
|
{
|
|
@@ -11,7 +11,7 @@ export const routes: RouteRecordRaw[] = [
|
|
|
11
11
|
path: '/orders',
|
|
12
12
|
redirect: '/demo/orders',
|
|
13
13
|
},
|
|
14
|
-
...
|
|
14
|
+
...businessRoutes,
|
|
15
15
|
{
|
|
16
16
|
path: '/403',
|
|
17
17
|
name: 'forbidden',
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
import type { RouteRecordRaw } from 'vue-router'
|
|
2
|
+
import type { RouteItem } from '@morningfast/platform/sub'
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
path: string
|
|
5
|
-
name: string
|
|
6
|
-
title: string
|
|
7
|
-
componentKey: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const mockRouteItems: MockRouteItem[] = [
|
|
11
|
-
{
|
|
12
|
-
path: '/home',
|
|
13
|
-
name: 'home',
|
|
14
|
-
title: '工作台',
|
|
15
|
-
componentKey: 'home',
|
|
16
|
-
},
|
|
4
|
+
export const mockRouteItems: RouteItem[] = [
|
|
17
5
|
{
|
|
18
6
|
path: '/demo/orders',
|
|
19
7
|
name: 'demo-orders',
|
|
@@ -22,30 +10,6 @@ export const mockRouteItems: MockRouteItem[] = [
|
|
|
22
10
|
},
|
|
23
11
|
]
|
|
24
12
|
|
|
25
|
-
const
|
|
26
|
-
home: () => import('@/pages/home/index.vue'),
|
|
13
|
+
export const mockComponentMap: Record<string, RouteRecordRaw['component']> = {
|
|
27
14
|
'demo-orders': () => import('@/pages/demo/orders/index.vue'),
|
|
28
15
|
}
|
|
29
|
-
|
|
30
|
-
export function createRoutesFromMock(items = mockRouteItems): RouteRecordRaw[] {
|
|
31
|
-
const routes: RouteRecordRaw[] = []
|
|
32
|
-
|
|
33
|
-
items.forEach((item) => {
|
|
34
|
-
const component = componentMap[item.componentKey]
|
|
35
|
-
|
|
36
|
-
if (!component) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
routes.push({
|
|
41
|
-
path: item.path,
|
|
42
|
-
name: item.name,
|
|
43
|
-
component,
|
|
44
|
-
meta: {
|
|
45
|
-
title: item.title,
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
return routes
|
|
51
|
-
}
|