swico 0.5.0-beta19 → 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 +3 -3
- package/src/template/react/history.d.ts +2 -10
- package/src/template/react/history.js +5 -40
- package/src/template/react/hooks.d.ts +10 -1
- package/src/template/react/hooks.js +5 -7
- package/src/template/react/index.js +2 -2
- package/src/template/react/routes.d.ts +2 -1
- package/src/template/react/routes.js +1 -2
- package/src/utils/config.js +9 -6
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 {
|
|
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
|
@@ -3,7 +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.defineGlobal = exports.defineConfig = exports.
|
|
6
|
+
exports.defineGlobal = exports.defineConfig = exports.useLocation = exports.Outlet = exports.Link = void 0;
|
|
7
7
|
var react_router_dom_1 = require("react-router-dom");
|
|
8
8
|
var react_1 = __importDefault(require("react"));
|
|
9
9
|
var Link = function (_a) {
|
|
@@ -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, "
|
|
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) {
|
|
@@ -1,7 +1,8 @@
|
|
|
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 getPathNameList: () => Array<{
|
|
5
|
+
export declare const getPathNameList: (routes: RoutesItemType[]) => Array<{
|
|
5
6
|
path: string;
|
|
6
7
|
name: string;
|
|
7
8
|
}>;
|
|
@@ -9,12 +10,3 @@ export declare const getHistory: (routerBase: ConfigRouterType['base'], routerTy
|
|
|
9
10
|
history: SwicoHistoryType;
|
|
10
11
|
originalHistory: import("history").HashHistory;
|
|
11
12
|
};
|
|
12
|
-
export declare const func: () => {
|
|
13
|
-
name: string;
|
|
14
|
-
path: string;
|
|
15
|
-
pathname: string;
|
|
16
|
-
search: string;
|
|
17
|
-
query: any;
|
|
18
|
-
hash: string;
|
|
19
|
-
params: any;
|
|
20
|
-
};
|
|
@@ -3,13 +3,12 @@ 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.
|
|
6
|
+
exports.getHistory = exports.getPathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
|
|
7
7
|
var qs_1 = __importDefault(require("qs"));
|
|
8
8
|
var history_1 = require("history");
|
|
9
|
-
var routes_1 = require("./routes");
|
|
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
|
-
console.log('routes_public', routes_1.routes);
|
|
13
12
|
var interpolatePath = function (pathTemplate, params) {
|
|
14
13
|
var pathParts = pathTemplate.split('/');
|
|
15
14
|
var interpolatedParts = pathParts.map(function (part) {
|
|
@@ -33,7 +32,7 @@ var formatAncPath = function (ancPath) {
|
|
|
33
32
|
return newAncPath;
|
|
34
33
|
};
|
|
35
34
|
exports.formatAncPath = formatAncPath;
|
|
36
|
-
var getPathNameList = function () {
|
|
35
|
+
var getPathNameList = function (routes) {
|
|
37
36
|
var list = [];
|
|
38
37
|
var checkRouteItem = function (item, ancPath) {
|
|
39
38
|
var path = item.path, name = item.name, children = item.children;
|
|
@@ -43,8 +42,7 @@ var getPathNameList = function () {
|
|
|
43
42
|
children.some(function (item) { return checkRouteItem(item, newAncPath); });
|
|
44
43
|
}
|
|
45
44
|
};
|
|
46
|
-
|
|
47
|
-
routes_1.routes.forEach(function (item) { return checkRouteItem(item, ''); });
|
|
45
|
+
routes.forEach(function (item) { return checkRouteItem(item, ''); });
|
|
48
46
|
return list;
|
|
49
47
|
};
|
|
50
48
|
exports.getPathNameList = getPathNameList;
|
|
@@ -86,8 +84,7 @@ var getHistory = function (routerBase, routerType) {
|
|
|
86
84
|
var _a;
|
|
87
85
|
var history;
|
|
88
86
|
var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
|
|
89
|
-
|
|
90
|
-
var pathNameList = (0, exports.getPathNameList)();
|
|
87
|
+
var pathNameList = (0, exports.getPathNameList)(routes_1.default);
|
|
91
88
|
var lastIndexBase = routerBase[routerBase.length - 1];
|
|
92
89
|
var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
|
|
93
90
|
history = {
|
|
@@ -127,35 +124,3 @@ var getHistory = function (routerBase, routerType) {
|
|
|
127
124
|
return { history: history, originalHistory: originalHistory };
|
|
128
125
|
};
|
|
129
126
|
exports.getHistory = getHistory;
|
|
130
|
-
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
131
|
-
var patternWithValuesParts = urlPatternWithValues.split('/');
|
|
132
|
-
var patternWithParamsParts = urlPatternWithParams.split('/');
|
|
133
|
-
if (patternWithValuesParts.length !== patternWithParamsParts.length) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
for (var i = 0; i < patternWithValuesParts.length; i++) {
|
|
137
|
-
var valuePart = patternWithValuesParts[i];
|
|
138
|
-
var paramPart = patternWithParamsParts[i];
|
|
139
|
-
if (paramPart.startsWith(':') && paramPart !== '') {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (valuePart !== paramPart) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return true;
|
|
147
|
-
};
|
|
148
|
-
var func = function () {
|
|
149
|
-
var _a;
|
|
150
|
-
console.log('routes2', routes_1.routes);
|
|
151
|
-
return {
|
|
152
|
-
name: '',
|
|
153
|
-
path: '',
|
|
154
|
-
pathname: (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.pathname,
|
|
155
|
-
search: '',
|
|
156
|
-
query: {},
|
|
157
|
-
hash: '',
|
|
158
|
-
params: {}
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
exports.func = func;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import qs from 'qs';
|
|
2
|
+
export declare const useLocation: () => {
|
|
3
|
+
name: string;
|
|
4
|
+
path: string;
|
|
5
|
+
pathname: string;
|
|
6
|
+
search: string;
|
|
7
|
+
query: qs.ParsedQs;
|
|
8
|
+
hash: string;
|
|
9
|
+
params: Readonly<import("react-router-dom").Params<string>>;
|
|
10
|
+
};
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.useLocation = void 0;
|
|
7
|
+
var routes_1 = __importDefault(require("./routes"));
|
|
7
8
|
var react_router_dom_1 = require("react-router-dom");
|
|
8
|
-
var qs_1 = __importDefault(require("qs"));
|
|
9
9
|
var history_1 = require("./history");
|
|
10
|
-
var
|
|
10
|
+
var qs_1 = __importDefault(require("qs"));
|
|
11
11
|
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
12
12
|
var patternWithValuesParts = urlPatternWithValues.split('/');
|
|
13
13
|
var patternWithParamsParts = urlPatternWithParams.split('/');
|
|
@@ -26,15 +26,13 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
|
26
26
|
}
|
|
27
27
|
return true;
|
|
28
28
|
};
|
|
29
|
-
console.log('routes1', routes_1.routes);
|
|
30
29
|
var useLocation = function () {
|
|
31
30
|
var _a, _b;
|
|
31
|
+
console.log('useLocationRoutes', routes_1.default);
|
|
32
32
|
var location = (0, react_router_dom_1.useLocation)();
|
|
33
33
|
var params = (0, react_router_dom_1.useParams)();
|
|
34
34
|
var search = location.search, hash = location.hash, pathname = location.pathname;
|
|
35
|
-
|
|
36
|
-
var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
|
|
37
|
-
console.log('pathNameList', pathNameList);
|
|
35
|
+
var pathNameList = (0, history_1.getPathNameList)(routes_1.default);
|
|
38
36
|
var name = (_a = pathNameList.find(function (item) {
|
|
39
37
|
return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
|
|
40
38
|
item.path === pathname;
|
|
@@ -44,7 +42,7 @@ var useLocation = function () {
|
|
|
44
42
|
name: name,
|
|
45
43
|
path: pathname,
|
|
46
44
|
pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
|
|
47
|
-
search:
|
|
45
|
+
search: '',
|
|
48
46
|
query: query,
|
|
49
47
|
hash: hash,
|
|
50
48
|
params: params
|
|
@@ -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 = require("./routes");
|
|
32
|
+
var routes_1 = __importDefault(require("./routes"));
|
|
33
33
|
var loading_1 = __importDefault(require("./loading"));
|
|
34
34
|
var history_1 = require("./history");
|
|
35
35
|
var config_1 = require("./config");
|
|
@@ -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.default, '')))));
|
|
58
58
|
};
|
|
59
59
|
var root = (0, client_1.createRoot)(document.getElementById('root'));
|
|
60
60
|
root.render(react_1.default.createElement(App, null));
|
package/src/utils/config.js
CHANGED
|
@@ -172,10 +172,10 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
172
172
|
case 4:
|
|
173
173
|
templateType = customConfig['base'].template;
|
|
174
174
|
routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
175
|
-
return [4,
|
|
175
|
+
return [4, initTemplateConfig(routerConfig, templateType)];
|
|
176
176
|
case 5:
|
|
177
177
|
_e.sent();
|
|
178
|
-
return [4,
|
|
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');
|
|
@@ -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,7 +241,7 @@ 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
247
|
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
@@ -272,7 +275,7 @@ var formatTemplateFileText = function (_a, templateType) {
|
|
|
272
275
|
});
|
|
273
276
|
}); });
|
|
274
277
|
};
|
|
275
|
-
var
|
|
278
|
+
var initTemplateConfig = function (routerConfig, templateType) {
|
|
276
279
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
277
280
|
var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
|
|
278
281
|
return __generator(this, function (_a) {
|
|
@@ -290,7 +293,7 @@ var initTemplateRouterConfig = function (routerConfig, templateType) {
|
|
|
290
293
|
})];
|
|
291
294
|
case 3:
|
|
292
295
|
_a.sent();
|
|
293
|
-
return [4,
|
|
296
|
+
return [4, formatRouterConfig(routerConfig, templateType)];
|
|
294
297
|
case 4:
|
|
295
298
|
_a.sent();
|
|
296
299
|
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
|