swico 0.6.0-beta24 → 0.6.0-beta26

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.
Files changed (26) hide show
  1. package/package.json +1 -1
  2. package/src/task.js +2 -2
  3. package/src/template/react/{config.d.ts → env/config.d.ts} +1 -1
  4. package/src/template/react/{history.d.ts → env/history.d.ts} +1 -1
  5. package/src/template/react/{history.js → env/history.js} +19 -3
  6. package/src/template/react/{index.d.ts → env/index.d.ts} +1 -1
  7. package/src/template/react/{index.js → env/index.js} +2 -2
  8. package/src/template/react/hooks.d.ts +0 -1
  9. package/src/template/react/hooks.js +3 -4
  10. package/src/template/vue/{config.d.ts → env/config.d.ts} +1 -1
  11. package/src/template/vue/{index.js → env/index.js} +2 -2
  12. package/src/template/vue/hooks.js +1 -1
  13. package/src/utils/config.js +37 -53
  14. package/src/utils/tools.js +1 -2
  15. /package/src/template/react/{config.js → env/config.js} +0 -0
  16. /package/src/template/react/{loading.d.ts → env/loading.d.ts} +0 -0
  17. /package/src/template/react/{loading.js → env/loading.js} +0 -0
  18. /package/src/template/react/{routes.d.ts → env/routes.d.ts} +0 -0
  19. /package/src/template/react/{routes.js → env/routes.js} +0 -0
  20. /package/src/template/vue/{Container.d.ts → env/Container.d.ts} +0 -0
  21. /package/src/template/vue/{Container.js → env/Container.js} +0 -0
  22. /package/src/template/vue/{Container.vue → env/Container.vue} +0 -0
  23. /package/src/template/vue/{config.js → env/config.js} +0 -0
  24. /package/src/template/vue/{index.d.ts → env/index.d.ts} +0 -0
  25. /package/src/template/vue/{routes.d.ts → env/routes.d.ts} +0 -0
  26. /package/src/template/vue/{routes.js → env/routes.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "0.6.0-beta24",
3
+ "version": "0.6.0-beta26",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/task.js CHANGED
@@ -46,8 +46,8 @@ var copyVueFiles = function () { return __awaiter(void 0, void 0, void 0, functi
46
46
  return __generator(this, function (_a) {
47
47
  switch (_a.label) {
48
48
  case 0:
49
- filePath = path_1.default.resolve(__dirname, './template/vue/Container.vue');
50
- targetPath = path_1.default.resolve(__dirname, '../dist/src/template/vue/Container.vue');
49
+ filePath = path_1.default.resolve(__dirname, './template/vue/env/Container.vue');
50
+ targetPath = path_1.default.resolve(__dirname, '../dist/src/template/vue/env/Container.vue');
51
51
  return [4, fs_extra_1.default.copyFile(filePath, targetPath)];
52
52
  case 1:
53
53
  _a.sent();
@@ -1,3 +1,3 @@
1
- import { ConfigRouterType } from '../../utils/config';
1
+ import { ConfigRouterType } from '../../../utils/config';
2
2
  export declare const routerType: ConfigRouterType['type'];
3
3
  export declare const routerBase: ConfigRouterType['base'];
@@ -1,4 +1,4 @@
1
- import { ConfigRouterType } from '../../utils/config';
1
+ import { ConfigRouterType } from '../../../utils/config';
2
2
  export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
3
3
  export declare const formatAncPath: (ancPath: string) => string;
4
4
  export declare const pathNameList: {
@@ -8,11 +8,28 @@ var qs_1 = __importDefault(require("qs"));
8
8
  var history_1 = require("history");
9
9
  var routes_1 = __importDefault(require("./routes"));
10
10
  var config_1 = require("./config");
11
- var hooks_1 = require("./hooks");
12
11
  var react_router_dom_1 = require("react-router-dom");
13
12
  Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
14
13
  var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
15
14
  var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
15
+ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
16
+ var patternWithValuesParts = urlPatternWithValues.split('/');
17
+ var patternWithParamsParts = urlPatternWithParams.split('/');
18
+ if (patternWithValuesParts.length !== patternWithParamsParts.length) {
19
+ return false;
20
+ }
21
+ for (var i = 0; i < patternWithValuesParts.length; i++) {
22
+ var valuePart = patternWithValuesParts[i];
23
+ var paramPart = patternWithParamsParts[i];
24
+ if (paramPart.startsWith(':') && paramPart !== '') {
25
+ continue;
26
+ }
27
+ if (valuePart !== paramPart) {
28
+ return false;
29
+ }
30
+ }
31
+ return true;
32
+ };
16
33
  var interpolatePath = function (pathTemplate, params) {
17
34
  var pathParts = pathTemplate.split('/');
18
35
  var interpolatedParts = pathParts.map(function (part) {
@@ -71,8 +88,7 @@ var getLocation = function (originalHistory) {
71
88
  var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
72
89
  var routerBaseLength = formatRouterBase.length;
73
90
  var path = pathname.slice(routerBaseLength);
74
- var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, hooks_1.compareURLPatterns)(path, item.path); });
75
- console.log('matchPathNameItem', matchPathNameItem);
91
+ var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || compareURLPatterns(path, item.path); });
76
92
  var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
77
93
  return {
78
94
  hash: hash,
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import '../global';
2
+ import '../../global';
3
3
  export type RoutesItemType = {
4
4
  component?: () => Promise<{
5
5
  default: FC;
@@ -33,8 +33,8 @@ 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");
36
- require("../global");
37
- var layout_1 = __importDefault(require("../layout"));
36
+ require("../../global");
37
+ var layout_1 = __importDefault(require("../../layout"));
38
38
  var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
39
39
  return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
40
40
  var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
@@ -1,2 +1 @@
1
- export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
2
1
  export declare const useLocation: UseLocationType;
@@ -3,9 +3,9 @@ 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 = exports.compareURLPatterns = void 0;
6
+ exports.useLocation = void 0;
7
7
  var react_router_dom_1 = require("react-router-dom");
8
- var history_1 = require("./history");
8
+ var history_1 = require("./env/history");
9
9
  var qs_1 = __importDefault(require("qs"));
10
10
  var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
11
11
  var patternWithValuesParts = urlPatternWithValues.split('/');
@@ -25,14 +25,13 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
25
25
  }
26
26
  return true;
27
27
  };
28
- exports.compareURLPatterns = compareURLPatterns;
29
28
  var useLocation = function () {
30
29
  var _a, _b;
31
30
  var location = (0, react_router_dom_1.useLocation)();
32
31
  var params = (0, react_router_dom_1.useParams)();
33
32
  var search = location.search, hash = location.hash, pathname = location.pathname;
34
33
  var name = (_a = history_1.pathNameList.find(function (item) {
35
- return (Object.keys(params).length > 0 && (0, exports.compareURLPatterns)(pathname, item.path)) ||
34
+ return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
36
35
  item.path === pathname;
37
36
  })) === null || _a === void 0 ? void 0 : _a.name;
38
37
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
@@ -1,3 +1,3 @@
1
- import { ConfigRouterType } from '../../utils/config';
1
+ import { ConfigRouterType } from '../../../utils/config';
2
2
  export declare const routerType: ConfigRouterType['type'];
3
3
  export declare const routerBase: ConfigRouterType['base'];
@@ -9,8 +9,8 @@ var routes_1 = __importDefault(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
- var Layout_1 = __importDefault(require("../layout/Layout"));
13
- var global_1 = __importDefault(require("../global"));
12
+ var Layout_1 = __importDefault(require("../../layout/Layout"));
13
+ 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),
@@ -7,7 +7,7 @@ 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("./config");
10
+ var config_1 = require("./env/config");
11
11
  var getFormatRouterBase = function (routerBase) {
12
12
  var lastIndexBase = routerBase[routerBase.length - 1];
13
13
  return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
@@ -178,7 +178,7 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
178
178
  return [4, initCliIndexFile(templateType)];
179
179
  case 6:
180
180
  _e.sent();
181
- envPath = env === 'dev' ? '' : '.prod/';
181
+ envPath = env === 'dev' ? '.dev/' : '.prod/';
182
182
  entryPath = path_1.default.resolve(projectPath, "./src/.swico/".concat(envPath, "index.js"));
183
183
  templatePath = path_1.default.join(projectPath, '/src/index.ejs');
184
184
  return [2, {
@@ -247,7 +247,7 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
247
247
  }); };
248
248
  var formatRouterConfig = function (_a, templateType, env) {
249
249
  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;
250
- var envPath = env === 'dev' ? '/' : '/.prod/';
250
+ var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
251
251
  return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
252
252
  var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
253
253
  return __generator(this, function (_a) {
@@ -281,83 +281,67 @@ var formatRouterConfig = function (_a, templateType, env) {
281
281
  }); });
282
282
  };
283
283
  var initTemplateConfig = function (routerConfig, templateType, env) {
284
- var envPath = env === 'dev' ? '/' : '/.prod/';
284
+ var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
285
285
  return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
286
- var copyTargetPath, replaceIndexText, envAncPath, e_1, e_2, e_3;
286
+ var copyTargetPath, replaceIndexText, e_1, e_2;
287
287
  return __generator(this, function (_a) {
288
288
  switch (_a.label) {
289
289
  case 0:
290
290
  copyTargetPath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath));
291
291
  return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) {
292
292
  return !fileName.endsWith('.d.ts') &&
293
- (templateType === 'vue' ? fileName !== 'Container.js' : true);
293
+ (templateType === 'vue'
294
+ ? !['Container.js', 'hooks.js'].includes(fileName)
295
+ : !['hooks.js'].includes(fileName));
294
296
  })];
295
297
  case 1:
296
298
  _a.sent();
297
- return [4, formatRouterConfig(routerConfig, templateType, env)];
299
+ return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), path_1.default.resolve(projectPath, './src/.swico'), function (fileName) { return ['hooks.js'].includes(fileName); })];
298
300
  case 2:
299
301
  _a.sent();
300
- replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8');
301
- replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
302
- envAncPath = env === 'dev' ? '..' : '../..';
303
- _a.label = 3;
302
+ return [4, formatRouterConfig(routerConfig, templateType, env)];
304
303
  case 3:
305
- _a.trys.push([3, 5, , 6]);
306
- return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
307
- case 4:
308
304
  _a.sent();
309
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global\");"), '');
310
- replaceIndexText = "require(\"".concat(envAncPath, "/global\");\n") + replaceIndexText;
311
- return [3, 6];
305
+ replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8');
306
+ _a.label = 4;
307
+ case 4:
308
+ _a.trys.push([4, 6, , 7]);
309
+ return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
312
310
  case 5:
313
- e_1 = _a.sent();
314
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global\");"), '');
315
- return [3, 6];
311
+ _a.sent();
312
+ replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
313
+ replaceIndexText = 'require("../../global.less");\n' + replaceIndexText;
314
+ return [3, 7];
316
315
  case 6:
317
- _a.trys.push([6, 8, , 9]);
318
- return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
316
+ e_1 = _a.sent();
317
+ replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
318
+ return [3, 7];
319
319
  case 7:
320
- _a.sent();
321
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global.less\");"), '');
322
- replaceIndexText = "require(\"".concat(envAncPath, "/global.less\");\n") + replaceIndexText;
323
- return [3, 9];
324
- case 8:
325
- e_2 = _a.sent();
326
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global.less\");"), '');
327
- return [3, 9];
328
- case 9:
329
- if (!(templateType === 'vue')) return [3, 11];
320
+ if (!(templateType === 'vue')) return [3, 9];
330
321
  replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
331
- if (env === 'prod') {
332
- replaceIndexText = replaceIndexText.replaceAll('require("../layout/Layout")', 'require("../../layout/Layout")');
333
- }
334
322
  return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
335
- case 10:
323
+ case 8:
336
324
  _a.sent();
337
- return [3, 17];
338
- case 11:
339
- if (!(templateType === 'react')) return [3, 17];
340
- _a.label = 12;
341
- case 12:
342
- _a.trys.push([12, 14, 15, 17]);
325
+ return [3, 15];
326
+ case 9:
327
+ if (!(templateType === 'react')) return [3, 15];
328
+ _a.label = 10;
329
+ case 10:
330
+ _a.trys.push([10, 12, 13, 15]);
343
331
  return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
344
- case 13:
332
+ case 11:
345
333
  _a.sent();
346
334
  replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
347
- return [3, 17];
348
- case 14:
349
- e_3 = _a.sent();
335
+ return [3, 15];
336
+ case 12:
337
+ e_2 = _a.sent();
350
338
  replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
351
- return [3, 17];
352
- case 15:
353
- if (env === 'prod') {
354
- replaceIndexText = replaceIndexText.replaceAll('require("../layout")', 'require("../../layout")');
355
- }
356
- return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
357
- case 16:
339
+ return [3, 15];
340
+ case 13: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
341
+ case 14:
358
342
  _a.sent();
359
343
  return [7];
360
- case 17:
344
+ case 15:
361
345
  resolve(null);
362
346
  return [2];
363
347
  }
@@ -174,9 +174,8 @@ var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, funct
174
174
  fileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, '../index.js'), 'utf8');
175
175
  targetPath = path_1.default.resolve(__dirname, '../index.js');
176
176
  formatHooksPath = path_1.default
177
- .resolve(process.cwd(), './src/.swico/hooks')
177
+ .resolve(process.cwd(), './src/.swico/hooks.js')
178
178
  .replaceAll('\\', '/');
179
- console.log('replace', "require(\"".concat(formatHooksPath, "\");"));
180
179
  fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./template/react/hooks");');
181
180
  return [4, (0, exports.writeFile)(targetPath, fileText)];
182
181
  case 1:
File without changes
File without changes
File without changes
File without changes
File without changes