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

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 +75 -73
  2. package/package.json +4 -4
package/lib/index.js CHANGED
@@ -72,8 +72,12 @@ 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
+ let _a = config || {}, { list = [] } = _a, rest = __rest(_a, ["list"]);
76
76
  let cfg;
77
+ if (!lodash_1.default.isArray(list)) {
78
+ printError(`tabBar.list 数据结构不对`.red);
79
+ return cfg;
80
+ }
77
81
  list = list.map((tab) => {
78
82
  for (const r of routes) {
79
83
  // 兼容老项目
@@ -83,81 +87,79 @@ function normalizeTabBarConfig(config, routes, fields) {
83
87
  }
84
88
  return tab;
85
89
  });
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;
90
+ const _cfg = {};
91
+ // tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
92
+ // tabBar.list[number].route 可不配置
93
+ // tabBar.list[number].route 若未配置,则设置 tabBar.list[number].route = routes[number].page(非模式匹配)或tabBar.list[number].pagePath
94
+ // tabBar.list[number].route 不能用模式,如不能用/xxx/:id等,必须是明确的 如/xxx/123
95
+ // tabBar.list[number].route 必须要能命中对应routes[number].route 路由规则,规则详见 path-to-regexp 模块
96
+ const tabs = list
97
+ .map((tab, index) => {
98
+ var _a;
99
+ const m = routes.find((i) => {
100
+ return (tab.pagePath === i.path ||
101
+ // 兼容老项目
102
+ tab.id === i.id);
103
+ });
104
+ if (!m) {
105
+ printError(`tabBar.list[${index}].pagePath: ${tab.pagePath} 需要在路由配置中: \n${JSON.stringify(routes, null, 2)}`.red);
106
+ return;
146
107
  }
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);
108
+ let pagePath = tab.pagePath.replace(/^\//, '');
109
+ const urlObj = url_1.default.parse(pagePath);
110
+ if (urlObj.hash || urlObj.search) {
111
+ printError(`tabBar.list[${index}]: ${tab.pagePath} 不能携带参数`.red);
112
+ return;
152
113
  }
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);
114
+ pagePath = urlObj.pathname;
115
+ if (!tab.route) {
116
+ // 判断 routes[number].route 是否为模式匹配规则
117
+ tab.route = m.route && (0, path_to_regexp_1.parse)(m.route).length === 1 ? m.route : m.path;
118
+ }
119
+ // 判断是否能被路由命中
120
+ const matched = (0, path_to_regexp_1.match)((_a = m.route) !== null && _a !== void 0 ? _a : m.path)(tab.route);
121
+ if (!matched) {
122
+ printError(`tabBar.list[${index}]\n.route: ${tab.route}\n.pagePath: ${tab.pagePath}\n无法被路由命中: \n${JSON.stringify(m, null, 2)}`.red);
123
+ return;
124
+ }
125
+ // 判断是否还被其他路由命中
126
+ const otherMatched = routes
127
+ .filter((r) => tab.pagePath !== r.path)
128
+ .filter((r) => { var _a; return (0, path_to_regexp_1.match)((_a = r.route) !== null && _a !== void 0 ? _a : r.path)(tab.route); });
129
+ const unusable = otherMatched.filter((r) => r.path !== tab.pagePath);
130
+ if (unusable.length) {
131
+ 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);
132
+ return;
133
+ }
134
+ // tab中配置的页面.route 匹配的页面为模式匹配,需给出告警
135
+ if (!lodash_1.default.isEmpty(matched.params)) {
136
+ console.warn(LOG_PREFIX, `tabBar.list[${index}].route: ${tab.route} 命中的路由 \n${JSON.stringify(m, null, 2)}.route: ${m.route} 为模式匹配\ntab页不能携带参数`.yellow);
137
+ }
138
+ return {
139
+ pagePath,
140
+ text: tab.text,
141
+ iconPath: tab.icon,
142
+ selectedIconPath: tab.activeIcon,
143
+ };
144
+ })
145
+ .filter((tab) => !!tab);
146
+ if (tabs.length < 2 || tabs.length > 5) {
147
+ printError(`tabBar.list 最少 2 个、最多 5 个 tab`.red);
148
+ return cfg;
160
149
  }
150
+ _cfg.list = tabs;
151
+ // 找出 tabBar.list[number].pagePath 重复的配置
152
+ const _list = duplicates(tabs, (a, b) => (a.pagePath > b.pagePath ? 1 : a.pagePath == b.pagePath ? 0 : -1), 'pagePath');
153
+ if (_list.length) {
154
+ console.error(LOG_PREFIX, `tabBar.list不能有重复的页面: \n${JSON.stringify(_list, null, 2)}`.red);
155
+ }
156
+ cfg = fields.reduce((o, next) => {
157
+ const [src, t] = typeof next === 'string' ? [next] : next;
158
+ if (rest[src]) {
159
+ o[t || src] = rest[src];
160
+ }
161
+ return o;
162
+ }, _cfg);
161
163
  return cfg;
162
164
  }
163
165
  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.23",
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.23",
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.23"
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": "e60b0be5d086d6d24238c12b29eebc3cbbd3f0dd",
42
42
  "repository": {}
43
43
  }