@ray-js/build-plugin-router 0.6.22-beta-2 → 0.6.25

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 (2) hide show
  1. package/lib/index.js +78 -74
  2. package/package.json +4 -4
package/lib/index.js CHANGED
@@ -72,92 +72,96 @@ const standardAppConfigFieldMap = [
72
72
  'backgroundColor',
73
73
  ];
74
74
  function normalizeTabBarConfig(config, routes, fields) {
75
- let _a = config || {}, { list } = _a, rest = __rest(_a, ["list"]);
75
+ if (!config) {
76
+ return;
77
+ }
78
+ let { list } = config, rest = __rest(config, ["list"]);
76
79
  let cfg;
80
+ if (!lodash_1.default.isArray(list)) {
81
+ printError(`tabBar.list 数据结构不对`.red);
82
+ return cfg;
83
+ }
77
84
  list = list.map((tab) => {
85
+ if (tab.id === undefined) {
86
+ return tab;
87
+ }
78
88
  for (const r of routes) {
79
- // 兼容老项目
89
+ // 兼容老项目,将老数据格式到新数据
80
90
  if (tab.id === r.id) {
81
91
  return Object.assign(Object.assign({}, tab), { pagePath: r.path });
82
92
  }
83
93
  }
84
94
  return tab;
85
95
  });
86
- if (list && list.length) {
87
- const _cfg = {};
88
- // tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
89
- // tabBar.list[number].route 可不配置
90
- // tabBar.list[number].route 若未配置,则设置 tabBar.list[number].route = routes[number].page(非模式匹配)或tabBar.list[number].pagePath
91
- // tabBar.list[number].route 不能用模式,如不能用/xxx/:id等,必须是明确的 如/xxx/123
92
- // tabBar.list[number].route 必须要能命中对应routes[number].route 路由规则,规则详见 path-to-regexp 模块
93
- const tabs = list
94
- .map((tab, index) => {
95
- var _a;
96
- const m = routes.find((i) => {
97
- return (tab.pagePath === i.path ||
98
- // 兼容老项目
99
- tab.id === i.id);
100
- });
101
- if (!m) {
102
- printError(`tabBar.list[${index}].pagePath: ${tab.pagePath} 需要在路由配置中: \n${JSON.stringify(routes, null, 2)}`.red);
103
- return;
104
- }
105
- let pagePath = tab.pagePath.replace(/^\//, '');
106
- const urlObj = url_1.default.parse(pagePath);
107
- if (urlObj.hash || urlObj.search) {
108
- printError(`tabBar.list[${index}]: ${tab.pagePath} 不能携带参数`.red);
109
- return;
110
- }
111
- pagePath = urlObj.pathname;
112
- if (!tab.route) {
113
- // 判断 routes[number].route 是否为模式匹配规则
114
- tab.route = m.route && (0, path_to_regexp_1.parse)(m.route).length === 1 ? m.route : m.path;
115
- }
116
- // 判断是否能被路由命中
117
- const matched = (0, path_to_regexp_1.match)((_a = m.route) !== null && _a !== void 0 ? _a : m.path)(tab.route);
118
- if (!matched) {
119
- printError(`tabBar.list[${index}]\n.route: ${tab.route}\n.pagePath: ${tab.pagePath}\n无法被路由命中: \n${JSON.stringify(m, null, 2)}`.red);
120
- return;
121
- }
122
- // 判断是否还被其他路由命中
123
- const otherMatched = routes
124
- .filter((r) => tab.pagePath !== r.path)
125
- .filter((r) => { var _a; return (0, path_to_regexp_1.match)((_a = r.route) !== null && _a !== void 0 ? _a : r.path)(tab.route); });
126
- const unusable = otherMatched.filter((r) => r.path !== tab.pagePath);
127
- if (unusable.length) {
128
- printError(`tabBar.list[${index}]\n.route: ${tab.route}\n.pagePath: ${tab.pagePath}\n应被路由命中:\n${JSON.stringify(m, null, 2)}\n但同时又被其它路由命中:\n${JSON.stringify(unusable, null, 2)}`.red);
129
- return;
130
- }
131
- // tab中配置的页面.route 匹配的页面为模式匹配,需给出告警
132
- if (!lodash_1.default.isEmpty(matched.params)) {
133
- console.warn(LOG_PREFIX, `tabBar.list[${index}].route: ${tab.route} 命中的路由 \n${JSON.stringify(m, null, 2)}.route: ${m.route} 为模式匹配\ntab页不能携带参数`.yellow);
134
- }
135
- return {
136
- pagePath,
137
- text: tab.text,
138
- iconPath: tab.icon,
139
- selectedIconPath: tab.activeIcon,
140
- };
141
- })
142
- .filter((tab) => !!tab);
143
- if (tabs.length < 2 || tabs.length > 5) {
144
- printError(`tabBar.list 最少 2 个、最多 5 个 tab`.red);
145
- return cfg;
96
+ const _cfg = {};
97
+ // tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
98
+ // tabBar.list[number].route 可不配置
99
+ // tabBar.list[number].route 若未配置,则设置 tabBar.list[number].route = routes[number].page(非模式匹配)或tabBar.list[number].pagePath
100
+ // tabBar.list[number].route 不能用模式,如不能用/xxx/:id等,必须是明确的 如/xxx/123
101
+ // tabBar.list[number].route 必须要能命中对应routes[number].route 路由规则,规则详见 path-to-regexp 模块
102
+ const tabs = list
103
+ .map((tab, index) => {
104
+ var _a;
105
+ const m = routes.find((i) => tab.pagePath === i.path);
106
+ if (!m) {
107
+ printError(`tabBar.list[${index}].pagePath: ${tab.pagePath} 需要在路由配置中: \n${JSON.stringify(routes, null, 2)}`.red);
108
+ return;
146
109
  }
147
- _cfg.list = tabs;
148
- // 找出 tabBar.list[number].pagePath 重复的配置
149
- const _list = duplicates(tabs, (a, b) => (a.pagePath > b.pagePath ? 1 : a.pagePath == b.pagePath ? 0 : -1), 'pagePath');
150
- if (_list.length) {
151
- console.error(LOG_PREFIX, `tabBar.list不能有重复的页面: \n${JSON.stringify(_list, null, 2)}`.red);
110
+ let pagePath = tab.pagePath.replace(/^\//, '');
111
+ const urlObj = url_1.default.parse(pagePath);
112
+ if (urlObj.hash || urlObj.search) {
113
+ printError(`tabBar.list[${index}]: ${tab.pagePath} 不能携带参数`.red);
114
+ return;
152
115
  }
153
- cfg = fields.reduce((o, next) => {
154
- const [src, t] = typeof next === 'string' ? [next] : next;
155
- if (rest[src]) {
156
- o[t || src] = rest[src];
157
- }
158
- return o;
159
- }, _cfg);
116
+ pagePath = urlObj.pathname;
117
+ if (!tab.route) {
118
+ // 判断 routes[number].route 是否为模式匹配规则
119
+ tab.route = m.route && (0, path_to_regexp_1.parse)(m.route).length === 1 ? m.route : m.path;
120
+ }
121
+ // 判断是否能被路由命中
122
+ const matched = (0, path_to_regexp_1.match)((_a = m.route) !== null && _a !== void 0 ? _a : m.path)(tab.route);
123
+ if (!matched) {
124
+ printError(`tabBar.list[${index}]\n.route: ${tab.route}\n.pagePath: ${tab.pagePath}\n无法被路由命中: \n${JSON.stringify(m, null, 2)}`.red);
125
+ return;
126
+ }
127
+ // 判断是否还被其他路由命中
128
+ const otherMatched = routes
129
+ .filter((r) => tab.pagePath !== r.path)
130
+ .filter((r) => { var _a; return (0, path_to_regexp_1.match)((_a = r.route) !== null && _a !== void 0 ? _a : r.path)(tab.route); });
131
+ const unusable = otherMatched.filter((r) => r.path !== tab.pagePath);
132
+ if (unusable.length) {
133
+ printError(`tabBar.list[${index}]\n.route: ${tab.route}\n.pagePath: ${tab.pagePath}\n应被路由命中:\n${JSON.stringify(m, null, 2)}\n但同时又被其它路由命中:\n${JSON.stringify(unusable, null, 2)}`.red);
134
+ return;
135
+ }
136
+ // tab中配置的页面.route 匹配的页面为模式匹配,需给出告警
137
+ if (!lodash_1.default.isEmpty(matched.params)) {
138
+ console.warn(LOG_PREFIX, `tabBar.list[${index}].route: ${tab.route} 命中的路由 \n${JSON.stringify(m, null, 2)}.route: ${m.route} 为模式匹配\ntab页不能携带参数`.yellow);
139
+ }
140
+ return {
141
+ pagePath,
142
+ text: tab.text,
143
+ iconPath: tab.icon,
144
+ selectedIconPath: tab.activeIcon,
145
+ };
146
+ })
147
+ .filter((tab) => !!tab);
148
+ if (tabs.length < 2 || tabs.length > 5) {
149
+ printError(`tabBar.list 最少 2 个、最多 5 个 tab`.red);
150
+ return cfg;
160
151
  }
152
+ _cfg.list = tabs;
153
+ // 找出 tabBar.list[number].pagePath 重复的配置
154
+ const _list = duplicates(tabs, (a, b) => (a.pagePath > b.pagePath ? 1 : a.pagePath == b.pagePath ? 0 : -1), 'pagePath');
155
+ if (_list.length) {
156
+ console.error(LOG_PREFIX, `tabBar.list不能有重复的页面: \n${JSON.stringify(_list, null, 2)}`.red);
157
+ }
158
+ cfg = fields.reduce((o, next) => {
159
+ const [src, t] = typeof next === 'string' ? [next] : next;
160
+ if (rest[src]) {
161
+ o[t || src] = rest[src];
162
+ }
163
+ return o;
164
+ }, _cfg);
161
165
  return cfg;
162
166
  }
163
167
  function PluginRouter(api) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/build-plugin-router",
3
- "version": "0.6.22-beta-2",
3
+ "version": "0.6.25",
4
4
  "description": "Ray build plugin for router",
5
5
  "keywords": [
6
6
  "ray"
@@ -21,7 +21,7 @@
21
21
  "watch": "tsc -p ./tsconfig.build.json --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@ray-js/shared": "^0.6.22-beta-2",
24
+ "@ray-js/shared": "^0.6.25",
25
25
  "chokidar": "^3.5.2",
26
26
  "colors": "1.4.0",
27
27
  "ejs": "^3.1.6",
@@ -30,7 +30,7 @@
30
30
  "url": "^0.11.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@ray-js/types": "^0.6.22-beta-2"
33
+ "@ray-js/types": "^0.6.25"
34
34
  },
35
35
  "maintainers": [
36
36
  {
@@ -38,6 +38,6 @@
38
38
  "email": "tuyafe@tuya.com"
39
39
  }
40
40
  ],
41
- "gitHead": "5d621bf1561047175b967cdf3aa35446f7d7198a",
41
+ "gitHead": "410b4714bc5f496978ddd642ee092f0fe3d8bf8d",
42
42
  "repository": {}
43
43
  }