swico 0.5.2 → 0.6.0-beta1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "0.5.2",
3
+ "version": "0.6.0-beta1",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -45,6 +45,7 @@ var config_1 = require("../utils/config");
45
45
  var chalk_1 = __importDefault(require("chalk"));
46
46
  var ora_1 = __importDefault(require("ora"));
47
47
  var tools_1 = require("../utils/tools");
48
+ var package_json_1 = __importDefault(require("../../package.json"));
48
49
  var spinner = (0, ora_1.default)();
49
50
  function default_1() {
50
51
  return __awaiter(this, void 0, void 0, function () {
@@ -53,6 +54,7 @@ function default_1() {
53
54
  switch (_a.label) {
54
55
  case 0:
55
56
  process.env.SWICO_ENV = 'prod';
57
+ tools_1.toast.info("Swico V".concat(package_json_1.default.version));
56
58
  return [4, (0, config_1.getProjectConfig)('prod')];
57
59
  case 1:
58
60
  projectConfig = _a.sent();
@@ -59,6 +59,9 @@ var chokidar_1 = __importDefault(require("chokidar"));
59
59
  var path_1 = __importDefault(require("path"));
60
60
  var cross_spawn_1 = __importDefault(require("cross-spawn"));
61
61
  var envPort = process.env.PORT;
62
+ var package_json_1 = __importDefault(require("../../package.json"));
63
+ var ora_1 = __importDefault(require("ora"));
64
+ var spinner = (0, ora_1.default)();
62
65
  var handleWatch = function (projectPath, devServer) {
63
66
  var configFilesWatcher = chokidar_1.default
64
67
  .watch([
@@ -137,6 +140,8 @@ function start() {
137
140
  _b.label = 3;
138
141
  case 3:
139
142
  availablePort = _a;
143
+ tools_1.toast.info("Swico V".concat(package_json_1.default.version));
144
+ spinner.info('initializing Swico config...\n');
140
145
  return [4, (0, config_1.getProjectConfig)('dev')];
141
146
  case 4:
142
147
  projectConfig = _b.sent();
@@ -7,6 +7,8 @@ exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.Hist
7
7
  var qs_1 = __importDefault(require("qs"));
8
8
  var history_1 = require("history");
9
9
  var routes_1 = __importDefault(require("./routes"));
10
+ var config_1 = require("./config");
11
+ var hooks_1 = require("./hooks");
10
12
  var react_router_dom_1 = require("react-router-dom");
11
13
  Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
12
14
  var interpolatePath = function (pathTemplate, params) {
@@ -26,6 +28,22 @@ var interpolatePath = function (pathTemplate, params) {
26
28
  });
27
29
  return interpolatedParts.join('/');
28
30
  };
31
+ var interpolatePathParams = function (pathTemplate, path) {
32
+ if (pathTemplate === void 0) { pathTemplate = ''; }
33
+ var regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
34
+ var regex = new RegExp("^".concat(regexPattern, "$"));
35
+ var match = path.match(regex);
36
+ if (match) {
37
+ var params_1 = match.slice(1);
38
+ var paramNames = pathTemplate.match(/:(\w+)/g).map(function (name) { return name.slice(1); });
39
+ var result_1 = {};
40
+ paramNames.forEach(function (name, index) {
41
+ result_1[name] = params_1[index];
42
+ });
43
+ return result_1;
44
+ }
45
+ return {};
46
+ };
29
47
  var formatAncPath = function (ancPath) {
30
48
  var newAncPath = ancPath.startsWith('/') ? ancPath : '/' + ancPath;
31
49
  newAncPath = newAncPath.endsWith('/') ? newAncPath.slice(0, -1) : newAncPath;
@@ -48,14 +66,19 @@ var getPathNameList = function (routes) {
48
66
  exports.pathNameList = getPathNameList(routes_1.default);
49
67
  var getLocation = function (originalHistory) {
50
68
  var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
69
+ var routerBaseLength = config_1.routerBase.length;
70
+ var path = pathname.slice(routerBaseLength);
71
+ var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, hooks_1.compareURLPatterns)(path, item.path); });
72
+ console.log('matchPathNameItem', matchPathNameItem);
73
+ var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
51
74
  return {
52
75
  hash: hash,
53
76
  search: search,
54
77
  pathname: pathname,
55
78
  query: search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {},
56
- name: '',
57
- params: {},
58
- path: ''
79
+ name: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.name,
80
+ params: params,
81
+ path: path
59
82
  };
60
83
  };
61
84
  var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
@@ -1 +1,2 @@
1
+ export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
1
2
  export declare const useLocation: UseLocationType;
@@ -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.useLocation = void 0;
6
+ exports.useLocation = exports.compareURLPatterns = void 0;
7
7
  var react_router_dom_1 = require("react-router-dom");
8
8
  var history_1 = require("./history");
9
9
  var qs_1 = __importDefault(require("qs"));
@@ -25,13 +25,14 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
25
25
  }
26
26
  return true;
27
27
  };
28
+ exports.compareURLPatterns = compareURLPatterns;
28
29
  var useLocation = function () {
29
30
  var _a, _b;
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
34
  var name = (_a = history_1.pathNameList.find(function (item) {
34
- return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
35
+ return (Object.keys(params).length > 0 && (0, exports.compareURLPatterns)(pathname, item.path)) ||
35
36
  item.path === pathname;
36
37
  })) === null || _a === void 0 ? void 0 : _a.name;
37
38
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
@@ -1,6 +1,7 @@
1
1
  export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<any>;
2
2
  export declare const getPort: () => Promise<number>;
3
3
  export declare const toast: {
4
+ info: (message: string) => void;
4
5
  error: (message: string | string[]) => void;
5
6
  warning: (message: string | string[]) => void;
6
7
  };
@@ -101,6 +101,9 @@ var getPort = function () {
101
101
  };
102
102
  exports.getPort = getPort;
103
103
  exports.toast = {
104
+ info: function (message) {
105
+ console.log("\n".concat(chalk_1.default.hex('#5f72f5')(message), " \n"));
106
+ },
104
107
  error: function (message) {
105
108
  console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
106
109
  if (Array.isArray(message)) {