swico 0.6.0-beta25 → 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 (29) hide show
  1. package/package.json +1 -1
  2. package/src/command/build.js +1 -1
  3. package/src/command/start.js +1 -1
  4. package/src/task.js +2 -2
  5. package/src/template/react/{config.d.ts → env/config.d.ts} +1 -1
  6. package/src/template/react/{history.d.ts → env/history.d.ts} +1 -1
  7. package/src/template/react/{history.js → env/history.js} +19 -3
  8. package/src/template/react/{index.d.ts → env/index.d.ts} +1 -1
  9. package/src/template/react/{index.js → env/index.js} +2 -2
  10. package/src/template/react/hooks.d.ts +0 -1
  11. package/src/template/react/hooks.js +3 -4
  12. package/src/template/vue/{config.d.ts → env/config.d.ts} +1 -1
  13. package/src/template/vue/{index.js → env/index.js} +2 -2
  14. package/src/template/vue/hooks.js +1 -1
  15. package/src/utils/config.js +37 -53
  16. package/src/utils/tools.d.ts +1 -2
  17. package/src/utils/tools.js +3 -5
  18. /package/src/template/react/{config.js → env/config.js} +0 -0
  19. /package/src/template/react/{loading.d.ts → env/loading.d.ts} +0 -0
  20. /package/src/template/react/{loading.js → env/loading.js} +0 -0
  21. /package/src/template/react/{routes.d.ts → env/routes.d.ts} +0 -0
  22. /package/src/template/react/{routes.js → env/routes.js} +0 -0
  23. /package/src/template/vue/{Container.d.ts → env/Container.d.ts} +0 -0
  24. /package/src/template/vue/{Container.js → env/Container.js} +0 -0
  25. /package/src/template/vue/{Container.vue → env/Container.vue} +0 -0
  26. /package/src/template/vue/{config.js → env/config.js} +0 -0
  27. /package/src/template/vue/{index.d.ts → env/index.d.ts} +0 -0
  28. /package/src/template/vue/{routes.d.ts → env/routes.d.ts} +0 -0
  29. /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-beta25",
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",
@@ -56,7 +56,7 @@ function default_1() {
56
56
  process.env.SWICO_ENV = 'prod';
57
57
  tools_1.toast.info("Swico v".concat(package_json_1.default.version));
58
58
  tools_1.toast.info('Initializing Swico production config...');
59
- return [4, (0, tools_1.initIndexFile)('prod')];
59
+ return [4, (0, tools_1.initIndexFile)()];
60
60
  case 1:
61
61
  _a.sent();
62
62
  return [4, (0, config_1.getProjectConfig)('prod')];
@@ -133,7 +133,7 @@ function start() {
133
133
  process.env.SWICO_ENV = 'dev';
134
134
  tools_1.toast.info("Swico v".concat(package_json_1.default.version));
135
135
  tools_1.toast.info('Initializing Swico development config...\n');
136
- return [4, (0, tools_1.initIndexFile)('dev')];
136
+ return [4, (0, tools_1.initIndexFile)()];
137
137
  case 1:
138
138
  _b.sent();
139
139
  if (!(envPort !== null && envPort !== void 0)) return [3, 2];
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
  }
@@ -1,4 +1,3 @@
1
- import { GlobalData } from './config';
2
1
  export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<any>;
3
2
  export declare const getPort: () => Promise<number>;
4
3
  export declare const toast: {
@@ -7,4 +6,4 @@ export declare const toast: {
7
6
  warning: (message: string | string[]) => void;
8
7
  };
9
8
  export declare const writeFile: (sourcePath: any, text: any) => Promise<unknown>;
10
- export declare const initIndexFile: (env: GlobalData['env']) => Promise<void>;
9
+ export declare const initIndexFile: () => Promise<void>;
@@ -166,18 +166,16 @@ var writeFile = function (sourcePath, text) {
166
166
  });
167
167
  };
168
168
  exports.writeFile = writeFile;
169
- var initIndexFile = function (env) { return __awaiter(void 0, void 0, void 0, function () {
170
- var envPath, fileText, targetPath, formatHooksPath;
169
+ var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, function () {
170
+ var fileText, targetPath, formatHooksPath;
171
171
  return __generator(this, function (_a) {
172
172
  switch (_a.label) {
173
173
  case 0:
174
- envPath = env === 'dev' ? '/' : '/.prod/';
175
174
  fileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, '../index.js'), 'utf8');
176
175
  targetPath = path_1.default.resolve(__dirname, '../index.js');
177
176
  formatHooksPath = path_1.default
178
- .resolve(process.cwd(), "./src/.swico".concat(envPath, "hooks.js"))
177
+ .resolve(process.cwd(), './src/.swico/hooks.js')
179
178
  .replaceAll('\\', '/');
180
- console.log('replace', "require(\"".concat(formatHooksPath, "\");"));
181
179
  fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./template/react/hooks");');
182
180
  return [4, (0, exports.writeFile)(targetPath, fileText)];
183
181
  case 1:
File without changes
File without changes
File without changes
File without changes
File without changes