swico 1.2.1-beta.2 → 1.3.0-beta.1
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/command/start.js +3 -2
- package/src/template/react/$env/history.d.ts +1 -0
- package/src/template/react/$env/history.js +4 -3
- package/src/template/react/$env/index.d.ts +1 -0
- package/src/template/react/react-hooks.js +6 -5
- package/src/template/vue/$env/history.js +21 -2
- package/src/template/vue/vue-hooks.js +2 -1
- package/src/typings/global-type.d.ts +2 -0
- package/README.md +0 -21
package/package.json
CHANGED
package/src/command/start.js
CHANGED
|
@@ -67,7 +67,8 @@ var handleWatch = function (projectPath, devServer) {
|
|
|
67
67
|
.watch([path_1.default.join(projectPath, '/config/*.ts'), path_1.default.join(projectPath, '/.eslintrc')], {
|
|
68
68
|
interval: 500,
|
|
69
69
|
binaryInterval: 500,
|
|
70
|
-
ignoreInitial: true
|
|
70
|
+
ignoreInitial: true,
|
|
71
|
+
ignored: [path_1.default.join(projectPath, '/config/swico.prod.ts')]
|
|
71
72
|
})
|
|
72
73
|
.on('all', function (path, stats) { return __awaiter(void 0, void 0, void 0, function () {
|
|
73
74
|
return __generator(this, function (_a) {
|
|
@@ -104,7 +105,7 @@ var handleWatch = function (projectPath, devServer) {
|
|
|
104
105
|
switch (_a.label) {
|
|
105
106
|
case 0:
|
|
106
107
|
if (!((watchFiles.includes(path) || path.endsWith('.d.ts')) &&
|
|
107
|
-
['add'].includes(eventName))) return [3, 3];
|
|
108
|
+
['add', 'unlink'].includes(eventName))) return [3, 3];
|
|
108
109
|
return [4, devServer.stop()];
|
|
109
110
|
case 1:
|
|
110
111
|
_a.sent();
|
|
@@ -72,9 +72,9 @@ exports.formatAncPath = formatAncPath;
|
|
|
72
72
|
var getPathNameList = function (routes) {
|
|
73
73
|
var list = [];
|
|
74
74
|
var checkRouteItem = function (item, ancPath) {
|
|
75
|
-
var path = item.path, name = item.name, children = item.children;
|
|
75
|
+
var path = item.path, name = item.name, children = item.children, custom = item.custom;
|
|
76
76
|
var newAncPath = "".concat((0, exports.formatAncPath)(ancPath)).concat(path.startsWith('/') ? path : '/' + path);
|
|
77
|
-
list.push({ path: newAncPath, name: name });
|
|
77
|
+
list.push({ path: newAncPath, name: name, custom: custom });
|
|
78
78
|
if (children) {
|
|
79
79
|
children.some(function (item) { return checkRouteItem(item, newAncPath); });
|
|
80
80
|
}
|
|
@@ -97,7 +97,8 @@ var getLocation = function (historyLocation) {
|
|
|
97
97
|
query: search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {},
|
|
98
98
|
name: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.name,
|
|
99
99
|
params: params,
|
|
100
|
-
path: path
|
|
100
|
+
path: path,
|
|
101
|
+
custom: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.custom
|
|
101
102
|
};
|
|
102
103
|
};
|
|
103
104
|
var getFormatHistoryOption = function (to, pathList, type) {
|
|
@@ -19,20 +19,21 @@ var react_router_dom_1 = require("react-router-dom");
|
|
|
19
19
|
var history_1 = require("./$env/history");
|
|
20
20
|
var qs_1 = __importDefault(require("qs"));
|
|
21
21
|
var useLocation = function () {
|
|
22
|
-
var _a
|
|
22
|
+
var _a;
|
|
23
23
|
var location = (0, react_router_dom_1.useLocation)();
|
|
24
24
|
var params = (0, react_router_dom_1.useParams)();
|
|
25
25
|
var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
|
|
26
|
-
var
|
|
26
|
+
var matchItem = history_1.pathNameList.find(function (item) {
|
|
27
27
|
return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
|
|
28
28
|
item.path === pathname;
|
|
29
|
-
})
|
|
29
|
+
});
|
|
30
30
|
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
31
31
|
return {
|
|
32
|
-
name: name,
|
|
32
|
+
name: matchItem === null || matchItem === void 0 ? void 0 : matchItem.name,
|
|
33
|
+
custom: matchItem === null || matchItem === void 0 ? void 0 : matchItem.custom,
|
|
33
34
|
state: state !== null && state !== void 0 ? state : {},
|
|
34
35
|
path: pathname,
|
|
35
|
-
pathname: (
|
|
36
|
+
pathname: (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.pathname,
|
|
36
37
|
search: '',
|
|
37
38
|
query: query,
|
|
38
39
|
hash: hash,
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -8,10 +19,17 @@ var vue_router_1 = require("vue-router");
|
|
|
8
19
|
var config_1 = require("./config");
|
|
9
20
|
var routes_1 = __importDefault(require("./routes"));
|
|
10
21
|
var qs_1 = __importDefault(require("qs"));
|
|
22
|
+
var transformRouteItemCustomToMeta = function (routeItem) {
|
|
23
|
+
var newRouteItem = __assign({}, routeItem);
|
|
24
|
+
var custom = routeItem.custom, children = routeItem.children;
|
|
25
|
+
newRouteItem.meta = custom;
|
|
26
|
+
return __assign(__assign({}, newRouteItem), { children: children === null || children === void 0 ? void 0 : children.map(function (item) { return transformRouteItemCustomToMeta(item); }) });
|
|
27
|
+
};
|
|
28
|
+
var formatRoutes = routes_1.default.map(function (routeItem) { return transformRouteItemCustomToMeta(routeItem); });
|
|
11
29
|
var getRouter = function () {
|
|
12
30
|
var router = (0, vue_router_1.createRouter)({
|
|
13
31
|
history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
|
|
14
|
-
routes:
|
|
32
|
+
routes: formatRoutes
|
|
15
33
|
});
|
|
16
34
|
exports.history = {
|
|
17
35
|
push: function (options) {
|
|
@@ -39,9 +57,10 @@ var getRouter = function () {
|
|
|
39
57
|
var _a, _b;
|
|
40
58
|
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
41
59
|
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
42
|
-
var _c = router.currentRoute.value, path = _c.path, params = _c.params, query = _c.query, name = _c.name, hash = _c.hash, fullPath = _c.fullPath;
|
|
60
|
+
var _c = router.currentRoute.value, path = _c.path, params = _c.params, query = _c.query, name = _c.name, hash = _c.hash, fullPath = _c.fullPath, meta = _c.meta;
|
|
43
61
|
return {
|
|
44
62
|
path: path,
|
|
63
|
+
custom: meta,
|
|
45
64
|
pathname: formatRouterBase + path,
|
|
46
65
|
params: params,
|
|
47
66
|
query: query,
|
|
@@ -38,7 +38,7 @@ var useLocation = function () {
|
|
|
38
38
|
});
|
|
39
39
|
(0, vue_1.watchEffect)(function () {
|
|
40
40
|
var _a;
|
|
41
|
-
var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name;
|
|
41
|
+
var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name, meta = route.meta;
|
|
42
42
|
var search = query ? qs_1.default.stringify(query) : '';
|
|
43
43
|
location.name = name;
|
|
44
44
|
location.path = path;
|
|
@@ -48,6 +48,7 @@ var useLocation = function () {
|
|
|
48
48
|
location.hash = hash;
|
|
49
49
|
location.params = params;
|
|
50
50
|
location.state = ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.swicoState) || {};
|
|
51
|
+
location.custom = meta;
|
|
51
52
|
});
|
|
52
53
|
return location;
|
|
53
54
|
};
|
|
@@ -7,6 +7,7 @@ export type SwicoLocationType = {
|
|
|
7
7
|
pathname: string;
|
|
8
8
|
search: string;
|
|
9
9
|
state?: Record<string, any>;
|
|
10
|
+
custom?: any;
|
|
10
11
|
};
|
|
11
12
|
export type SwicoHistoryOptionType = {
|
|
12
13
|
query?: Record<string, any>;
|
|
@@ -15,6 +16,7 @@ export type SwicoHistoryOptionType = {
|
|
|
15
16
|
path?: string;
|
|
16
17
|
name?: string;
|
|
17
18
|
state?: Record<string, any>;
|
|
19
|
+
custom?: any;
|
|
18
20
|
};
|
|
19
21
|
export type SwicoHistoryType = {
|
|
20
22
|
push: (to: string | SwicoHistoryOptionType) => void;
|
package/README.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# SWICO介绍
|
|
2
|
-
|
|
3
|
-
Swico,发音近似于“斯威扣”。
|
|
4
|
-
|
|
5
|
-
为个人独立开发的一款实用的前端框架,它基于前端工程化最新技术栈实现了前端开发从创建项目,获取模板,本地开发,Git提交校验到打包构建的完整过程。
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## 主要特性
|
|
9
|
-
|
|
10
|
-
- 构建工具基于Webpack5,并配合esbuild-loader和swc-loader提升编译构建速率。
|
|
11
|
-
|
|
12
|
-
- 提供Vue3和React18两种开发模板选择,默认集成TypeScript5。同时最大化统一这两种模板的开发API。
|
|
13
|
-
|
|
14
|
-
- 提供可配置化路由方案,基于React-Router6和Vue-Router4进行二次封装,支持路由嵌套,懒加载,动态参数,装饰校验等功能。
|
|
15
|
-
|
|
16
|
-
- 内置ESLint + Prettier + Husky三大前端编码风格以及代码提交规范约束插件,保证代码风格统一以及 Git 提交规范。
|
|
17
|
-
|
|
18
|
-
- 提供配置文件可对部分项目配置进行修改扩展,例如Alias映射,本地请求代理等。
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
官方文档:[SWICO 官方文档](https://scw1997.github.io/swico-docs)
|