swico 0.5.0-beta2 → 0.5.0-beta3

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.0-beta2",
3
+ "version": "0.5.0-beta3",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -7,6 +7,8 @@ exports.useLocation = 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("../vue/config");
11
+ var tools_1 = require("../../utils/tools");
10
12
  var useLocation = function () {
11
13
  var route = (0, vue_router_1.useRoute)();
12
14
  var location = (0, vue_1.reactive)({
@@ -23,7 +25,7 @@ var useLocation = function () {
23
25
  var search = query ? qs_1.default.stringify(query) : '';
24
26
  location.name = name;
25
27
  location.path = path;
26
- location.pathname = fullPath;
28
+ location.pathname = (0, tools_1.getFormatRouterBase)(config_1.routerBase) + path;
27
29
  location.search = search;
28
30
  location.query = query;
29
31
  location.hash = hash;
@@ -7,6 +7,7 @@ exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.Hist
7
7
  var routes_1 = __importDefault(require("./routes"));
8
8
  var qs_1 = __importDefault(require("qs"));
9
9
  var history_1 = require("history");
10
+ var tools_1 = require("../../utils/tools");
10
11
  var react_router_dom_1 = require("react-router-dom");
11
12
  Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
12
13
  var interpolatePath = function (pathTemplate, params) {
@@ -47,7 +48,7 @@ var getPathNameList = function () {
47
48
  };
48
49
  exports.pathNameList = getPathNameList();
49
50
  var getLocation = function (originalHistory) {
50
- var pathname = originalHistory.pathname, hash = originalHistory.hash, search = originalHistory.search;
51
+ var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
51
52
  return {
52
53
  hash: hash,
53
54
  search: search,
@@ -84,8 +85,7 @@ var getHistory = function (routerBase, routerType) {
84
85
  var _a;
85
86
  var history;
86
87
  var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
87
- var lastIndexBase = routerBase[routerBase.length - 1];
88
- var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
88
+ var formatRouterBase = (0, tools_1.getFormatRouterBase)(routerBase);
89
89
  history = {
90
90
  go: originalHistory.go,
91
91
  forward: originalHistory.forward,
@@ -81,9 +81,9 @@ var tools_1 = require("./tools");
81
81
  var projectPath = process.cwd();
82
82
  var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0, function () {
83
83
  var configDir, configPath, customConfig, _loop_1, _i, _a, key, templateType, routerConfig, entryPath, templatePath;
84
- var _b, _c, _d, _e, _f;
85
- return __generator(this, function (_g) {
86
- switch (_g.label) {
84
+ var _b, _c, _d;
85
+ return __generator(this, function (_e) {
86
+ switch (_e.label) {
87
87
  case 0:
88
88
  configDir = path_1.default.join(projectPath, '/config');
89
89
  configPath = {
@@ -93,16 +93,16 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
93
93
  };
94
94
  customConfig = {};
95
95
  _loop_1 = function (key) {
96
- var curConfigFilePath, exists, configObj, configFields, supportedFieldList_1, configFileName, unSupportedField, msgText, _h, _j;
97
- return __generator(this, function (_k) {
98
- switch (_k.label) {
96
+ var curConfigFilePath, exists, configObj, configFields, supportedFieldList_1, configFileName, unSupportedField, msgText, _f, _g;
97
+ return __generator(this, function (_h) {
98
+ switch (_h.label) {
99
99
  case 0:
100
100
  curConfigFilePath = configPath[key];
101
101
  exists = fs_extra_1.default.existsSync(curConfigFilePath);
102
102
  if (!exists) return [3, 3];
103
103
  return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
104
104
  case 1:
105
- configObj = (_k.sent()).default;
105
+ configObj = (_h.sent()).default;
106
106
  configFields = Object.keys(configObj);
107
107
  configFileName = void 0;
108
108
  switch (key) {
@@ -147,37 +147,37 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
147
147
  tools_1.toast.error("The field '".concat(chalk_1.default.blue('router.type'), "' does not support the value '").concat(chalk_1.default.red(configObj['router'].type), "',the value can be 'browser' or 'hash' "));
148
148
  process.exit();
149
149
  }
150
- _h = customConfig;
151
- _j = key;
150
+ _f = customConfig;
151
+ _g = key;
152
152
  return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
153
153
  case 2:
154
- _h[_j] = (_k.sent()).default;
155
- _k.label = 3;
154
+ _f[_g] = (_h.sent()).default;
155
+ _h.label = 3;
156
156
  case 3: return [2];
157
157
  }
158
158
  });
159
159
  };
160
160
  _i = 0, _a = Object.keys(configPath);
161
- _g.label = 1;
161
+ _e.label = 1;
162
162
  case 1:
163
163
  if (!(_i < _a.length)) return [3, 4];
164
164
  key = _a[_i];
165
165
  return [5, _loop_1(key)];
166
166
  case 2:
167
- _g.sent();
168
- _g.label = 3;
167
+ _e.sent();
168
+ _e.label = 3;
169
169
  case 3:
170
170
  _i++;
171
171
  return [3, 1];
172
172
  case 4:
173
173
  templateType = customConfig['base'].template;
174
- routerConfig = (_f = (_e = customConfig[env].router) !== null && _e !== void 0 ? _e : customConfig['base'].router) !== null && _f !== void 0 ? _f : exports.initConfig.router;
174
+ routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
175
175
  return [4, initTemplateRouterConfig(routerConfig, templateType)];
176
176
  case 5:
177
- _g.sent();
177
+ _e.sent();
178
178
  return [4, handleCliIndexFile(templateType)];
179
179
  case 6:
180
- _g.sent();
180
+ _e.sent();
181
181
  entryPath = path_1.default.resolve(projectPath, './src/.swico/index.js');
182
182
  templatePath = path_1.default.join(projectPath, '/src/index.ejs');
183
183
  return [2, {
@@ -259,7 +259,7 @@ var formatTemplateFileText = function (_a, templateType) {
259
259
  replaceConfigText = configText;
260
260
  if (base) {
261
261
  replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
262
- return "exports.routerBase = '".concat((templateType === 'react' && type === 'hash') ? '/' : base, "';");
262
+ return "exports.routerBase = '".concat(templateType === 'react' && type === 'hash' ? '/' : base, "';");
263
263
  });
264
264
  }
265
265
  if (type) {
@@ -5,3 +5,4 @@ export declare const toast: {
5
5
  warning: (message: string | string[]) => void;
6
6
  };
7
7
  export declare const writeFile: (sourcePath: any, text: any) => Promise<unknown>;
8
+ export declare const getFormatRouterBase: (routerBase: any) => any;
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
42
+ exports.getFormatRouterBase = exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
43
43
  var portfinder_1 = __importDefault(require("portfinder"));
44
44
  var fs_extra_1 = __importDefault(require("fs-extra"));
45
45
  var path_1 = __importDefault(require("path"));
@@ -139,3 +139,8 @@ var writeFile = function (sourcePath, text) {
139
139
  });
140
140
  };
141
141
  exports.writeFile = writeFile;
142
+ var getFormatRouterBase = function (routerBase) {
143
+ var lastIndexBase = routerBase[routerBase.length - 1];
144
+ return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
145
+ };
146
+ exports.getFormatRouterBase = getFormatRouterBase;