swico 0.5.0-beta2 → 0.5.0-beta20
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 +3 -2
- package/src/template/react/history.js +9 -8
- package/src/template/react/hooks.d.ts +10 -0
- package/src/template/react/hooks.js +51 -0
- package/src/template/vue/hooks.d.ts +2 -0
- package/src/template/vue/hooks.js +40 -0
- package/src/template/vue/index.js +13 -3
- package/src/template/vue/routes.d.ts +2 -2
- package/src/template/vue/routes.js +2 -1
- package/src/utils/config.js +40 -43
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,10 +1,11 @@
|
|
|
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
|
+
}>;
|
|
8
9
|
export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type']) => {
|
|
9
10
|
history: SwicoHistoryType;
|
|
10
11
|
originalHistory: import("history").HashHistory;
|
|
@@ -3,10 +3,10 @@ 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");
|
|
9
|
+
var routes_1 = __importDefault(require("./routes"));
|
|
10
10
|
var react_router_dom_1 = require("react-router-dom");
|
|
11
11
|
Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
|
|
12
12
|
var interpolatePath = function (pathTemplate, params) {
|
|
@@ -32,7 +32,7 @@ var formatAncPath = function (ancPath) {
|
|
|
32
32
|
return newAncPath;
|
|
33
33
|
};
|
|
34
34
|
exports.formatAncPath = formatAncPath;
|
|
35
|
-
var getPathNameList = function () {
|
|
35
|
+
var getPathNameList = function (routes) {
|
|
36
36
|
var list = [];
|
|
37
37
|
var checkRouteItem = function (item, ancPath) {
|
|
38
38
|
var path = item.path, name = item.name, children = item.children;
|
|
@@ -42,12 +42,12 @@ var getPathNameList = function () {
|
|
|
42
42
|
children.some(function (item) { return checkRouteItem(item, newAncPath); });
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
|
|
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,
|
|
@@ -84,6 +84,7 @@ var getHistory = function (routerBase, routerType) {
|
|
|
84
84
|
var _a;
|
|
85
85
|
var history;
|
|
86
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_1.default);
|
|
87
88
|
var lastIndexBase = routerBase[routerBase.length - 1];
|
|
88
89
|
var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
|
|
89
90
|
history = {
|
|
@@ -96,7 +97,7 @@ var getHistory = function (routerBase, routerType) {
|
|
|
96
97
|
originalHistory.push("".concat(formatRouterBase).concat(to));
|
|
97
98
|
break;
|
|
98
99
|
case 'object':
|
|
99
|
-
var formatOption = getFormatHistoryOption(to, formatRouterBase,
|
|
100
|
+
var formatOption = getFormatHistoryOption(to, formatRouterBase, pathNameList, 'push');
|
|
100
101
|
originalHistory.push(formatOption);
|
|
101
102
|
break;
|
|
102
103
|
default:
|
|
@@ -109,7 +110,7 @@ var getHistory = function (routerBase, routerType) {
|
|
|
109
110
|
originalHistory.replace("".concat(formatRouterBase).concat(to));
|
|
110
111
|
break;
|
|
111
112
|
case 'object':
|
|
112
|
-
var formatOption = getFormatHistoryOption(to, formatRouterBase,
|
|
113
|
+
var formatOption = getFormatHistoryOption(to, formatRouterBase, pathNameList, 'replace');
|
|
113
114
|
originalHistory.replace(formatOption);
|
|
114
115
|
break;
|
|
115
116
|
default:
|
|
@@ -0,0 +1,51 @@
|
|
|
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 routes_1 = __importDefault(require("./routes"));
|
|
8
|
+
var react_router_dom_1 = require("react-router-dom");
|
|
9
|
+
var history_1 = require("./history");
|
|
10
|
+
var qs_1 = __importDefault(require("qs"));
|
|
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
|
+
console.log('useLocationRoutes', routes_1.default);
|
|
32
|
+
var location = (0, react_router_dom_1.useLocation)();
|
|
33
|
+
var params = (0, react_router_dom_1.useParams)();
|
|
34
|
+
var search = location.search, hash = location.hash, pathname = location.pathname;
|
|
35
|
+
var pathNameList = (0, history_1.getPathNameList)(routes_1.default);
|
|
36
|
+
var name = (_a = pathNameList.find(function (item) {
|
|
37
|
+
return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
|
|
38
|
+
item.path === pathname;
|
|
39
|
+
})) === null || _a === void 0 ? void 0 : _a.name;
|
|
40
|
+
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
41
|
+
return {
|
|
42
|
+
name: name,
|
|
43
|
+
path: pathname,
|
|
44
|
+
pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
|
|
45
|
+
search: '',
|
|
46
|
+
query: query,
|
|
47
|
+
hash: hash,
|
|
48
|
+
params: params
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.useLocation = useLocation;
|
|
@@ -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,7 +5,7 @@ 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");
|
|
@@ -14,7 +14,7 @@ var global_1 = __importDefault(require("../global"));
|
|
|
14
14
|
var qs_1 = __importDefault(require("qs"));
|
|
15
15
|
var router = (0, vue_router_1.createRouter)({
|
|
16
16
|
history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
|
|
17
|
-
routes: routes_1.
|
|
17
|
+
routes: routes_1.routes
|
|
18
18
|
});
|
|
19
19
|
var app = (0, vue_1.createApp)(Container_1.default);
|
|
20
20
|
var Swico = { history: null };
|
|
@@ -41,8 +41,18 @@ Swico.history = {
|
|
|
41
41
|
back: router.back,
|
|
42
42
|
forward: router.forward,
|
|
43
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;
|
|
44
46
|
var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
|
|
45
|
-
return {
|
|
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
|
+
};
|
|
46
56
|
}
|
|
47
57
|
};
|
|
48
58
|
app.component('Layout', Layout_1.default);
|
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 = (
|
|
175
|
-
return [4,
|
|
174
|
+
routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
175
|
+
return [4, initTemplateConfig(routerConfig, templateType)];
|
|
176
176
|
case 5:
|
|
177
|
-
|
|
178
|
-
return [4,
|
|
177
|
+
_e.sent();
|
|
178
|
+
return [4, initCliIndexFile(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, {
|
|
@@ -219,7 +219,7 @@ var getFormatRouter = function (routes, templateType) {
|
|
|
219
219
|
return _main(item);
|
|
220
220
|
});
|
|
221
221
|
};
|
|
222
|
-
var
|
|
222
|
+
var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
223
223
|
var targetPath, targetTypesPath, replaceFileText, fileTypesText;
|
|
224
224
|
return __generator(this, function (_a) {
|
|
225
225
|
switch (_a.label) {
|
|
@@ -228,6 +228,9 @@ var handleCliIndexFile = function (templateType) { return __awaiter(void 0, void
|
|
|
228
228
|
targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
|
|
229
229
|
replaceFileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8');
|
|
230
230
|
fileTypesText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8');
|
|
231
|
+
if (templateType === 'react') {
|
|
232
|
+
replaceFileText = replaceFileText.replaceAll('require("./template/react/hooks");', "require(\"".concat(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), "\");"));
|
|
233
|
+
}
|
|
231
234
|
return [4, (0, tools_1.writeFile)(targetPath, replaceFileText)];
|
|
232
235
|
case 1:
|
|
233
236
|
_a.sent();
|
|
@@ -238,28 +241,24 @@ var handleCliIndexFile = function (templateType) { return __awaiter(void 0, void
|
|
|
238
241
|
}
|
|
239
242
|
});
|
|
240
243
|
}); };
|
|
241
|
-
var
|
|
244
|
+
var formatRouterConfig = function (_a, templateType) {
|
|
242
245
|
var _b = _a.routes, routes = _b === void 0 ? [] : _b, _c = _a.type, type = _c === void 0 ? 'browser' : _c, _d = _a.base, base = _d === void 0 ? '/' : _d;
|
|
243
246
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
244
|
-
var formatRouter, textData, modifiedText,
|
|
247
|
+
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
245
248
|
return __generator(this, function (_a) {
|
|
246
249
|
switch (_a.label) {
|
|
247
250
|
case 0:
|
|
248
251
|
formatRouter = getFormatRouter(routes, templateType);
|
|
249
|
-
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.
|
|
252
|
+
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.routes = ".concat(JSON.stringify(formatRouter), ";");
|
|
250
253
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
251
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(
|
|
254
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/routes.js'), modifiedText)];
|
|
252
255
|
case 1:
|
|
253
256
|
_a.sent();
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
indexText = fs_extra_1.default.readFileSync(indexFilePath, 'utf8');
|
|
257
|
-
configText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
258
|
-
replaceIndexText = indexText;
|
|
259
|
-
replaceConfigText = configText;
|
|
257
|
+
configFilePath = path_1.default.resolve(projectPath, './src/.swico/config.js');
|
|
258
|
+
replaceConfigText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
260
259
|
if (base) {
|
|
261
260
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
262
|
-
return "exports.routerBase = '".concat(
|
|
261
|
+
return "exports.routerBase = '".concat(templateType === 'react' && type === 'hash' ? '/' : base, "';");
|
|
263
262
|
});
|
|
264
263
|
}
|
|
265
264
|
if (type) {
|
|
@@ -267,11 +266,8 @@ var formatTemplateFileText = function (_a, templateType) {
|
|
|
267
266
|
return "exports.routerType = '".concat(type, "';");
|
|
268
267
|
});
|
|
269
268
|
}
|
|
270
|
-
return [4, (0, tools_1.writeFile)(indexFilePath, replaceIndexText)];
|
|
271
|
-
case 2:
|
|
272
|
-
_a.sent();
|
|
273
269
|
return [4, (0, tools_1.writeFile)(configFilePath, replaceConfigText)];
|
|
274
|
-
case
|
|
270
|
+
case 2:
|
|
275
271
|
_a.sent();
|
|
276
272
|
resolve(null);
|
|
277
273
|
return [2];
|
|
@@ -279,24 +275,25 @@ var formatTemplateFileText = function (_a, templateType) {
|
|
|
279
275
|
});
|
|
280
276
|
}); });
|
|
281
277
|
};
|
|
282
|
-
var
|
|
278
|
+
var initTemplateConfig = function (routerConfig, templateType) {
|
|
283
279
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
284
280
|
var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
|
|
285
281
|
return __generator(this, function (_a) {
|
|
286
282
|
switch (_a.label) {
|
|
287
|
-
case 0:
|
|
288
|
-
case 1:
|
|
289
|
-
_a.sent();
|
|
283
|
+
case 0:
|
|
290
284
|
copyTargetPath = path_1.default.resolve(projectPath, './src/.swico');
|
|
291
|
-
if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3,
|
|
285
|
+
if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3, 2];
|
|
292
286
|
return [4, fs_extra_1.default.remove(copyTargetPath)];
|
|
293
|
-
case
|
|
287
|
+
case 1:
|
|
294
288
|
_a.sent();
|
|
295
|
-
_a.label =
|
|
296
|
-
case
|
|
289
|
+
_a.label = 2;
|
|
290
|
+
case 2: return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) {
|
|
297
291
|
return !fileName.endsWith('.d.ts') &&
|
|
298
292
|
(templateType === 'vue' ? fileName !== 'Container.js' : true);
|
|
299
293
|
})];
|
|
294
|
+
case 3:
|
|
295
|
+
_a.sent();
|
|
296
|
+
return [4, formatRouterConfig(routerConfig, templateType)];
|
|
300
297
|
case 4:
|
|
301
298
|
_a.sent();
|
|
302
299
|
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
|