swico 0.5.0-beta1 → 0.5.0-beta10
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/package.json +1 -1
- package/src/index.react.d.ts +1 -1
- package/src/index.react.js +2 -2
- package/src/index.vue.d.ts +1 -1
- package/src/index.vue.js +2 -2
- package/src/template/hooks/react.js +3 -1
- package/src/template/hooks/vue.d.ts +1 -0
- package/src/template/hooks/vue.js +8 -2
- package/src/template/react/history.d.ts +4 -3
- package/src/template/react/history.js +18 -11
- package/src/template/react/hooks.d.ts +1 -0
- package/src/template/react/hooks.js +47 -0
- package/src/template/react/index.js +3 -3
- package/src/template/react/routes.d.ts +1 -2
- package/src/template/react/routes.js +2 -1
- package/src/template/vue/hooks.d.ts +2 -0
- package/src/template/vue/hooks.js +40 -0
- package/src/template/vue/index.js +18 -3
- package/src/template/vue/routes.d.ts +2 -2
- package/src/template/vue/routes.js +2 -1
- package/src/utils/config.js +19 -19
package/package.json
CHANGED
package/src/index.react.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare const Link: FC<{
|
|
|
10
10
|
children: ReactNode;
|
|
11
11
|
}>;
|
|
12
12
|
export { Outlet } from 'react-router-dom';
|
|
13
|
-
export { useLocation } from './template/hooks
|
|
13
|
+
export { useLocation } from './template/react/hooks';
|
|
14
14
|
export interface DefineSwicoConfigType {
|
|
15
15
|
(env: 'base', config: CustomConfigType['base']): any;
|
|
16
16
|
(env: 'dev', config: CustomConfigType['dev']): any;
|
package/src/index.react.js
CHANGED
|
@@ -13,8 +13,8 @@ var Link = function (_a) {
|
|
|
13
13
|
exports.Link = Link;
|
|
14
14
|
var react_router_dom_2 = require("react-router-dom");
|
|
15
15
|
Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return react_router_dom_2.Outlet; } });
|
|
16
|
-
var
|
|
17
|
-
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return
|
|
16
|
+
var hooks_1 = require("./template/react/hooks");
|
|
17
|
+
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return hooks_1.useLocation; } });
|
|
18
18
|
var defineConfig = function (env, config) { return config; };
|
|
19
19
|
exports.defineConfig = defineConfig;
|
|
20
20
|
var defineGlobal = function (config) {
|
package/src/index.vue.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { App } from 'vue';
|
|
|
3
3
|
import { Router } from 'vue-router';
|
|
4
4
|
export type CustomConfigType = GlobalData['customConfig'];
|
|
5
5
|
export { RouterView as Outlet } from 'vue-router';
|
|
6
|
-
export { useLocation } from './template/hooks
|
|
6
|
+
export { useLocation } from './template/vue/hooks';
|
|
7
7
|
export type { GlobalSwicoConfigType };
|
|
8
8
|
export declare const Link: import("vue").DefineComponent<{
|
|
9
9
|
to: {
|
package/src/index.vue.js
CHANGED
|
@@ -5,8 +5,8 @@ var vue_1 = require("vue");
|
|
|
5
5
|
var vue_router_1 = require("vue-router");
|
|
6
6
|
var vue_router_2 = require("vue-router");
|
|
7
7
|
Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return vue_router_2.RouterView; } });
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return
|
|
8
|
+
var hooks_1 = require("./template/vue/hooks");
|
|
9
|
+
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return hooks_1.useLocation; } });
|
|
10
10
|
exports.Link = (0, vue_1.defineComponent)({
|
|
11
11
|
components: {
|
|
12
12
|
RouterLink: vue_router_1.RouterLink
|
|
@@ -7,6 +7,7 @@ exports.useLocation = void 0;
|
|
|
7
7
|
var react_router_dom_1 = require("react-router-dom");
|
|
8
8
|
var qs_1 = __importDefault(require("qs"));
|
|
9
9
|
var history_1 = require("../react/history");
|
|
10
|
+
var routes_1 = require("../react/routes");
|
|
10
11
|
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
11
12
|
var patternWithValuesParts = urlPatternWithValues.split('/');
|
|
12
13
|
var patternWithParamsParts = urlPatternWithParams.split('/');
|
|
@@ -30,7 +31,8 @@ var useLocation = function () {
|
|
|
30
31
|
var location = (0, react_router_dom_1.useLocation)();
|
|
31
32
|
var params = (0, react_router_dom_1.useParams)();
|
|
32
33
|
var search = location.search, hash = location.hash, pathname = location.pathname;
|
|
33
|
-
var
|
|
34
|
+
var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
|
|
35
|
+
var name = (_a = pathNameList.find(function (item) { return (params && compareURLPatterns(pathname, item.path)) || item.path === pathname; })) === null || _a === void 0 ? void 0 : _a.name;
|
|
34
36
|
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
35
37
|
return {
|
|
36
38
|
name: name,
|
|
@@ -3,10 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useLocation = void 0;
|
|
6
|
+
exports.useLocation = exports.getFormatRouterBase = void 0;
|
|
7
7
|
var vue_router_1 = require("vue-router");
|
|
8
8
|
var qs_1 = __importDefault(require("qs"));
|
|
9
9
|
var vue_1 = require("vue");
|
|
10
|
+
var config_1 = require("../vue/config");
|
|
11
|
+
var getFormatRouterBase = function (routerBase) {
|
|
12
|
+
var lastIndexBase = routerBase[routerBase.length - 1];
|
|
13
|
+
return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
|
|
14
|
+
};
|
|
15
|
+
exports.getFormatRouterBase = getFormatRouterBase;
|
|
10
16
|
var useLocation = function () {
|
|
11
17
|
var route = (0, vue_router_1.useRoute)();
|
|
12
18
|
var location = (0, vue_1.reactive)({
|
|
@@ -23,7 +29,7 @@ var useLocation = function () {
|
|
|
23
29
|
var search = query ? qs_1.default.stringify(query) : '';
|
|
24
30
|
location.name = name;
|
|
25
31
|
location.path = path;
|
|
26
|
-
location.pathname =
|
|
32
|
+
location.pathname = (0, exports.getFormatRouterBase)(config_1.routerBase) + path;
|
|
27
33
|
location.search = search;
|
|
28
34
|
location.query = query;
|
|
29
35
|
location.hash = hash;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ConfigRouterType } from '../../utils/config';
|
|
2
|
+
import { RoutesItemType } from './index';
|
|
2
3
|
export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
|
|
3
4
|
export declare const formatAncPath: (ancPath: string) => string;
|
|
4
|
-
export declare const
|
|
5
|
+
export declare const getPathNameList: (routes: RoutesItemType[]) => Array<{
|
|
5
6
|
path: string;
|
|
6
7
|
name: string;
|
|
7
|
-
}
|
|
8
|
-
export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type']) => {
|
|
8
|
+
}>;
|
|
9
|
+
export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type'], routes: RoutesItemType[]) => {
|
|
9
10
|
history: SwicoHistoryType;
|
|
10
11
|
originalHistory: import("history").HashHistory;
|
|
11
12
|
};
|
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getHistory = exports.
|
|
7
|
-
var routes_1 = __importDefault(require("./routes"));
|
|
6
|
+
exports.getHistory = exports.getPathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
|
|
8
7
|
var qs_1 = __importDefault(require("qs"));
|
|
9
8
|
var history_1 = require("history");
|
|
10
9
|
var react_router_dom_1 = require("react-router-dom");
|
|
@@ -32,7 +31,7 @@ var formatAncPath = function (ancPath) {
|
|
|
32
31
|
return newAncPath;
|
|
33
32
|
};
|
|
34
33
|
exports.formatAncPath = formatAncPath;
|
|
35
|
-
var getPathNameList = function () {
|
|
34
|
+
var getPathNameList = function (routes) {
|
|
36
35
|
var list = [];
|
|
37
36
|
var checkRouteItem = function (item, ancPath) {
|
|
38
37
|
var path = item.path, name = item.name, children = item.children;
|
|
@@ -42,16 +41,21 @@ var getPathNameList = function () {
|
|
|
42
41
|
children.some(function (item) { return checkRouteItem(item, newAncPath); });
|
|
43
42
|
}
|
|
44
43
|
};
|
|
45
|
-
|
|
44
|
+
console.log('rrr', routes);
|
|
45
|
+
routes.forEach(function (item) { return checkRouteItem(item, ''); });
|
|
46
46
|
return list;
|
|
47
47
|
};
|
|
48
|
-
exports.
|
|
48
|
+
exports.getPathNameList = getPathNameList;
|
|
49
49
|
var getLocation = function (originalHistory) {
|
|
50
|
-
var
|
|
50
|
+
var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
|
|
51
51
|
return {
|
|
52
52
|
hash: hash,
|
|
53
53
|
search: search,
|
|
54
|
-
pathname: pathname
|
|
54
|
+
pathname: pathname,
|
|
55
|
+
query: search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {},
|
|
56
|
+
name: '',
|
|
57
|
+
params: {},
|
|
58
|
+
path: ''
|
|
55
59
|
};
|
|
56
60
|
};
|
|
57
61
|
var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
|
|
@@ -76,10 +80,11 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
|
|
|
76
80
|
}
|
|
77
81
|
return obj;
|
|
78
82
|
};
|
|
79
|
-
var getHistory = function (routerBase, routerType) {
|
|
83
|
+
var getHistory = function (routerBase, routerType, routes) {
|
|
80
84
|
var _a;
|
|
81
85
|
var history;
|
|
82
86
|
var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
|
|
87
|
+
var pathNameList = (0, exports.getPathNameList)(routes);
|
|
83
88
|
var lastIndexBase = routerBase[routerBase.length - 1];
|
|
84
89
|
var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
|
|
85
90
|
history = {
|
|
@@ -92,7 +97,7 @@ var getHistory = function (routerBase, routerType) {
|
|
|
92
97
|
originalHistory.push("".concat(formatRouterBase).concat(to));
|
|
93
98
|
break;
|
|
94
99
|
case 'object':
|
|
95
|
-
var formatOption = getFormatHistoryOption(to, formatRouterBase,
|
|
100
|
+
var formatOption = getFormatHistoryOption(to, formatRouterBase, pathNameList, 'push');
|
|
96
101
|
originalHistory.push(formatOption);
|
|
97
102
|
break;
|
|
98
103
|
default:
|
|
@@ -105,14 +110,16 @@ var getHistory = function (routerBase, routerType) {
|
|
|
105
110
|
originalHistory.replace("".concat(formatRouterBase).concat(to));
|
|
106
111
|
break;
|
|
107
112
|
case 'object':
|
|
108
|
-
var formatOption = getFormatHistoryOption(to, formatRouterBase,
|
|
113
|
+
var formatOption = getFormatHistoryOption(to, formatRouterBase, pathNameList, 'replace');
|
|
109
114
|
originalHistory.replace(formatOption);
|
|
110
115
|
break;
|
|
111
116
|
default:
|
|
112
117
|
throw "An error occurred while executing Navigation.replace operation: unexpected type of 'to':".concat(typeof to);
|
|
113
118
|
}
|
|
114
119
|
},
|
|
115
|
-
location
|
|
120
|
+
get location() {
|
|
121
|
+
return getLocation(originalHistory);
|
|
122
|
+
}
|
|
116
123
|
};
|
|
117
124
|
return { history: history, originalHistory: originalHistory };
|
|
118
125
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useLocation: UseLocationType;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useLocation = void 0;
|
|
7
|
+
var react_router_dom_1 = require("react-router-dom");
|
|
8
|
+
var qs_1 = __importDefault(require("qs"));
|
|
9
|
+
var history_1 = require("./history");
|
|
10
|
+
var routes_1 = require("./routes");
|
|
11
|
+
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
12
|
+
var patternWithValuesParts = urlPatternWithValues.split('/');
|
|
13
|
+
var patternWithParamsParts = urlPatternWithParams.split('/');
|
|
14
|
+
if (patternWithValuesParts.length !== patternWithParamsParts.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
for (var i = 0; i < patternWithValuesParts.length; i++) {
|
|
18
|
+
var valuePart = patternWithValuesParts[i];
|
|
19
|
+
var paramPart = patternWithParamsParts[i];
|
|
20
|
+
if (paramPart.startsWith(':') && paramPart !== '') {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (valuePart !== paramPart) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
var useLocation = function () {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
var location = (0, react_router_dom_1.useLocation)();
|
|
32
|
+
var params = (0, react_router_dom_1.useParams)();
|
|
33
|
+
var search = location.search, hash = location.hash, pathname = location.pathname;
|
|
34
|
+
var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
|
|
35
|
+
var name = (_a = pathNameList.find(function (item) { return (params && compareURLPatterns(pathname, item.path)) || item.path === pathname; })) === null || _a === void 0 ? void 0 : _a.name;
|
|
36
|
+
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
37
|
+
return {
|
|
38
|
+
name: name,
|
|
39
|
+
path: pathname,
|
|
40
|
+
pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
|
|
41
|
+
search: search,
|
|
42
|
+
query: query,
|
|
43
|
+
hash: hash,
|
|
44
|
+
params: params
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.useLocation = useLocation;
|
|
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
var client_1 = require("react-dom/client");
|
|
30
30
|
var react_1 = __importStar(require("react"));
|
|
31
31
|
var react_router_dom_1 = require("react-router-dom");
|
|
32
|
-
var routes_1 =
|
|
32
|
+
var routes_1 = require("./routes");
|
|
33
33
|
var loading_1 = __importDefault(require("./loading"));
|
|
34
34
|
var history_1 = require("./history");
|
|
35
35
|
var config_1 = require("./config");
|
|
@@ -43,7 +43,7 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
var App = function () {
|
|
46
|
-
var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType), history = _a.history, originalHistory = _a.originalHistory;
|
|
46
|
+
var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType, routes_1.routes), history = _a.history, originalHistory = _a.originalHistory;
|
|
47
47
|
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
48
48
|
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
49
49
|
window.location.replace("".concat(config_1.routerBase));
|
|
@@ -54,7 +54,7 @@ var App = function () {
|
|
|
54
54
|
};
|
|
55
55
|
return (react_1.default.createElement(history_1.HistoryRouter, { basename: config_1.routerBase, history: originalHistory },
|
|
56
56
|
react_1.default.createElement(react_router_dom_1.Routes, null,
|
|
57
|
-
react_1.default.createElement(react_router_dom_1.Route, { element: react_1.default.createElement(layout_1.default, null), path: '' }, renderChildrenRouteList(routes_1.
|
|
57
|
+
react_1.default.createElement(react_router_dom_1.Route, { element: react_1.default.createElement(layout_1.default, null), path: '' }, renderChildrenRouteList(routes_1.routes, '')))));
|
|
58
58
|
};
|
|
59
59
|
var root = (0, client_1.createRoot)(document.getElementById('root'));
|
|
60
60
|
root.render(react_1.default.createElement(App, null));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useLocation = exports.getFormatRouterBase = void 0;
|
|
7
|
+
var vue_router_1 = require("vue-router");
|
|
8
|
+
var qs_1 = __importDefault(require("qs"));
|
|
9
|
+
var vue_1 = require("vue");
|
|
10
|
+
var config_1 = require("./config");
|
|
11
|
+
var getFormatRouterBase = function (routerBase) {
|
|
12
|
+
var lastIndexBase = routerBase[routerBase.length - 1];
|
|
13
|
+
return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
|
|
14
|
+
};
|
|
15
|
+
exports.getFormatRouterBase = getFormatRouterBase;
|
|
16
|
+
var useLocation = function () {
|
|
17
|
+
var route = (0, vue_router_1.useRoute)();
|
|
18
|
+
var location = (0, vue_1.reactive)({
|
|
19
|
+
name: '',
|
|
20
|
+
path: '',
|
|
21
|
+
search: '',
|
|
22
|
+
hash: '',
|
|
23
|
+
pathname: '',
|
|
24
|
+
params: {},
|
|
25
|
+
query: {}
|
|
26
|
+
});
|
|
27
|
+
(0, vue_1.watchEffect)(function () {
|
|
28
|
+
var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name;
|
|
29
|
+
var search = query ? qs_1.default.stringify(query) : '';
|
|
30
|
+
location.name = name;
|
|
31
|
+
location.path = path;
|
|
32
|
+
location.pathname = (0, exports.getFormatRouterBase)(config_1.routerBase) + path;
|
|
33
|
+
location.search = search;
|
|
34
|
+
location.query = query;
|
|
35
|
+
location.hash = hash;
|
|
36
|
+
location.params = params;
|
|
37
|
+
});
|
|
38
|
+
return location;
|
|
39
|
+
};
|
|
40
|
+
exports.useLocation = useLocation;
|
|
@@ -5,15 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
var _a;
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
var vue_1 = require("vue");
|
|
8
|
-
var routes_1 =
|
|
8
|
+
var routes_1 = require("./routes");
|
|
9
9
|
var vue_router_1 = require("vue-router");
|
|
10
10
|
var Container_1 = __importDefault(require("./Container"));
|
|
11
11
|
var config_1 = require("./config");
|
|
12
12
|
var Layout_1 = __importDefault(require("../layout/Layout"));
|
|
13
13
|
var global_1 = __importDefault(require("../global"));
|
|
14
|
+
var qs_1 = __importDefault(require("qs"));
|
|
14
15
|
var router = (0, vue_router_1.createRouter)({
|
|
15
16
|
history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
|
|
16
|
-
routes: routes_1.
|
|
17
|
+
routes: routes_1.routes
|
|
17
18
|
});
|
|
18
19
|
var app = (0, vue_1.createApp)(Container_1.default);
|
|
19
20
|
var Swico = { history: null };
|
|
@@ -38,7 +39,21 @@ Swico.history = {
|
|
|
38
39
|
},
|
|
39
40
|
go: router.go,
|
|
40
41
|
back: router.back,
|
|
41
|
-
|
|
42
|
+
forward: router.forward,
|
|
43
|
+
get location() {
|
|
44
|
+
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
45
|
+
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
46
|
+
var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
|
|
47
|
+
return {
|
|
48
|
+
path: path,
|
|
49
|
+
pathname: formatRouterBase + path,
|
|
50
|
+
params: params,
|
|
51
|
+
query: query,
|
|
52
|
+
name: name,
|
|
53
|
+
hash: hash,
|
|
54
|
+
search: query ? qs_1.default.stringify(query) : ''
|
|
55
|
+
};
|
|
56
|
+
}
|
|
42
57
|
};
|
|
43
58
|
app.component('Layout', Layout_1.default);
|
|
44
59
|
app.use(router);
|
package/src/utils/config.js
CHANGED
|
@@ -81,9 +81,9 @@ var tools_1 = require("./tools");
|
|
|
81
81
|
var projectPath = process.cwd();
|
|
82
82
|
var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
83
|
var configDir, configPath, customConfig, _loop_1, _i, _a, key, templateType, routerConfig, entryPath, templatePath;
|
|
84
|
-
var _b, _c, _d
|
|
85
|
-
return __generator(this, function (
|
|
86
|
-
switch (
|
|
84
|
+
var _b, _c, _d;
|
|
85
|
+
return __generator(this, function (_e) {
|
|
86
|
+
switch (_e.label) {
|
|
87
87
|
case 0:
|
|
88
88
|
configDir = path_1.default.join(projectPath, '/config');
|
|
89
89
|
configPath = {
|
|
@@ -93,16 +93,16 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
93
93
|
};
|
|
94
94
|
customConfig = {};
|
|
95
95
|
_loop_1 = function (key) {
|
|
96
|
-
var curConfigFilePath, exists, configObj, configFields, supportedFieldList_1, configFileName, unSupportedField, msgText,
|
|
97
|
-
return __generator(this, function (
|
|
98
|
-
switch (
|
|
96
|
+
var curConfigFilePath, exists, configObj, configFields, supportedFieldList_1, configFileName, unSupportedField, msgText, _f, _g;
|
|
97
|
+
return __generator(this, function (_h) {
|
|
98
|
+
switch (_h.label) {
|
|
99
99
|
case 0:
|
|
100
100
|
curConfigFilePath = configPath[key];
|
|
101
101
|
exists = fs_extra_1.default.existsSync(curConfigFilePath);
|
|
102
102
|
if (!exists) return [3, 3];
|
|
103
103
|
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
104
104
|
case 1:
|
|
105
|
-
configObj = (
|
|
105
|
+
configObj = (_h.sent()).default;
|
|
106
106
|
configFields = Object.keys(configObj);
|
|
107
107
|
configFileName = void 0;
|
|
108
108
|
switch (key) {
|
|
@@ -147,37 +147,37 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
147
147
|
tools_1.toast.error("The field '".concat(chalk_1.default.blue('router.type'), "' does not support the value '").concat(chalk_1.default.red(configObj['router'].type), "',the value can be 'browser' or 'hash' "));
|
|
148
148
|
process.exit();
|
|
149
149
|
}
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
_f = customConfig;
|
|
151
|
+
_g = key;
|
|
152
152
|
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
153
153
|
case 2:
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
_f[_g] = (_h.sent()).default;
|
|
155
|
+
_h.label = 3;
|
|
156
156
|
case 3: return [2];
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
159
|
};
|
|
160
160
|
_i = 0, _a = Object.keys(configPath);
|
|
161
|
-
|
|
161
|
+
_e.label = 1;
|
|
162
162
|
case 1:
|
|
163
163
|
if (!(_i < _a.length)) return [3, 4];
|
|
164
164
|
key = _a[_i];
|
|
165
165
|
return [5, _loop_1(key)];
|
|
166
166
|
case 2:
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
_e.sent();
|
|
168
|
+
_e.label = 3;
|
|
169
169
|
case 3:
|
|
170
170
|
_i++;
|
|
171
171
|
return [3, 1];
|
|
172
172
|
case 4:
|
|
173
173
|
templateType = customConfig['base'].template;
|
|
174
|
-
routerConfig = (
|
|
174
|
+
routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
175
175
|
return [4, initTemplateRouterConfig(routerConfig, templateType)];
|
|
176
176
|
case 5:
|
|
177
|
-
|
|
177
|
+
_e.sent();
|
|
178
178
|
return [4, handleCliIndexFile(templateType)];
|
|
179
179
|
case 6:
|
|
180
|
-
|
|
180
|
+
_e.sent();
|
|
181
181
|
entryPath = path_1.default.resolve(projectPath, './src/.swico/index.js');
|
|
182
182
|
templatePath = path_1.default.join(projectPath, '/src/index.ejs');
|
|
183
183
|
return [2, {
|
|
@@ -246,7 +246,7 @@ var formatTemplateFileText = function (_a, templateType) {
|
|
|
246
246
|
switch (_a.label) {
|
|
247
247
|
case 0:
|
|
248
248
|
formatRouter = getFormatRouter(routes, templateType);
|
|
249
|
-
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.
|
|
249
|
+
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.routes = ".concat(JSON.stringify(formatRouter), ";");
|
|
250
250
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
251
251
|
return [4, (0, tools_1.writeFile)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/routes.js")), modifiedText)];
|
|
252
252
|
case 1:
|
|
@@ -259,7 +259,7 @@ var formatTemplateFileText = function (_a, templateType) {
|
|
|
259
259
|
replaceConfigText = configText;
|
|
260
260
|
if (base) {
|
|
261
261
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
262
|
-
return "exports.routerBase = '".concat(
|
|
262
|
+
return "exports.routerBase = '".concat(templateType === 'react' && type === 'hash' ? '/' : base, "';");
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
265
|
if (type) {
|