@ray-js/build-plugin-router 0.6.22-beta-1 → 0.6.22-beta-2
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/lib/index.js +26 -7
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -72,8 +72,17 @@ const standardAppConfigFieldMap = [
|
|
|
72
72
|
'backgroundColor',
|
|
73
73
|
];
|
|
74
74
|
function normalizeTabBarConfig(config, routes, fields) {
|
|
75
|
-
|
|
75
|
+
let _a = config || {}, { list } = _a, rest = __rest(_a, ["list"]);
|
|
76
76
|
let cfg;
|
|
77
|
+
list = list.map((tab) => {
|
|
78
|
+
for (const r of routes) {
|
|
79
|
+
// 兼容老项目
|
|
80
|
+
if (tab.id === r.id) {
|
|
81
|
+
return Object.assign(Object.assign({}, tab), { pagePath: r.path });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return tab;
|
|
85
|
+
});
|
|
77
86
|
if (list && list.length) {
|
|
78
87
|
const _cfg = {};
|
|
79
88
|
// tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
|
|
@@ -84,7 +93,11 @@ function normalizeTabBarConfig(config, routes, fields) {
|
|
|
84
93
|
const tabs = list
|
|
85
94
|
.map((tab, index) => {
|
|
86
95
|
var _a;
|
|
87
|
-
const m = routes.find((i) =>
|
|
96
|
+
const m = routes.find((i) => {
|
|
97
|
+
return (tab.pagePath === i.path ||
|
|
98
|
+
// 兼容老项目
|
|
99
|
+
tab.id === i.id);
|
|
100
|
+
});
|
|
88
101
|
if (!m) {
|
|
89
102
|
printError(`tabBar.list[${index}].pagePath: ${tab.pagePath} 需要在路由配置中: \n${JSON.stringify(routes, null, 2)}`.red);
|
|
90
103
|
return;
|
|
@@ -115,6 +128,10 @@ function normalizeTabBarConfig(config, routes, fields) {
|
|
|
115
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);
|
|
116
129
|
return;
|
|
117
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
|
+
}
|
|
118
135
|
return {
|
|
119
136
|
pagePath,
|
|
120
137
|
text: tab.text,
|
|
@@ -145,6 +162,7 @@ function normalizeTabBarConfig(config, routes, fields) {
|
|
|
145
162
|
}
|
|
146
163
|
function PluginRouter(api) {
|
|
147
164
|
let cacheThemeLocation = {};
|
|
165
|
+
let timerId;
|
|
148
166
|
return {
|
|
149
167
|
name: '@ray-js/build-plugin-router',
|
|
150
168
|
setup() {
|
|
@@ -175,6 +193,7 @@ function PluginRouter(api) {
|
|
|
175
193
|
return { routesConfig, globalConfig };
|
|
176
194
|
},
|
|
177
195
|
buildRoutesConfig(immediate) {
|
|
196
|
+
clearTimeout(timerId);
|
|
178
197
|
const { routesConfig, globalConfig } = this.readConfigFromConfigFile();
|
|
179
198
|
// target 在入口处已经统一处理,tuya 会转成 thing
|
|
180
199
|
const { target } = api.options;
|
|
@@ -188,14 +207,14 @@ function PluginRouter(api) {
|
|
|
188
207
|
// FIX: 修复初始化时找不到配置文件
|
|
189
208
|
// 初始化时,需要立即生成配置文件
|
|
190
209
|
if (immediate) {
|
|
191
|
-
return this.generateAppConfig(
|
|
210
|
+
return this.generateAppConfig(target, appConfig);
|
|
192
211
|
}
|
|
193
212
|
// FIX: 修复间接(更新routes.config.ts)更新app.config.ts文件,无法触发重新编译,导致小程序app.json未更新
|
|
194
213
|
// 原因:/node_modules/@ray-core/cli/lib/build/watch.js 中的变量isRunning为true
|
|
195
214
|
// 在更新routes.config.ts触发的编译未完成,又因间接更新app.config.ts的触发重新编译被remax忽略导致
|
|
196
215
|
// TODO: 此为临时方案,无法确定第一次更新什么时候完成,默认延时1s
|
|
197
|
-
setTimeout(() => {
|
|
198
|
-
this.generateAppConfig(
|
|
216
|
+
timerId = setTimeout(() => {
|
|
217
|
+
this.generateAppConfig(target, appConfig);
|
|
199
218
|
}, 1000);
|
|
200
219
|
},
|
|
201
220
|
/**
|
|
@@ -234,9 +253,9 @@ function PluginRouter(api) {
|
|
|
234
253
|
* 生成小程序app.config.{js|ts}文件
|
|
235
254
|
* @param data
|
|
236
255
|
*/
|
|
237
|
-
generateAppConfig(data) {
|
|
256
|
+
generateAppConfig(target, data) {
|
|
238
257
|
const templateFile = path_1.default.join(__dirname, '../templates/app.config.ejs');
|
|
239
|
-
const context = ejsRender(templateFile, { appConfig: data });
|
|
258
|
+
const context = ejsRender(templateFile, { appConfig: { [target]: data } });
|
|
240
259
|
api.writeFile('src/app.config.ts', context);
|
|
241
260
|
shared_1.log.verbose(LOG_PREFIX, `generate`, 'src/app.config.ts'.underline.green, `for wechat platform`);
|
|
242
261
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/build-plugin-router",
|
|
3
|
-
"version": "0.6.22-beta-
|
|
3
|
+
"version": "0.6.22-beta-2",
|
|
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-
|
|
24
|
+
"@ray-js/shared": "^0.6.22-beta-2",
|
|
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-
|
|
33
|
+
"@ray-js/types": "^0.6.22-beta-2"
|
|
34
34
|
},
|
|
35
35
|
"maintainers": [
|
|
36
36
|
{
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"email": "tuyafe@tuya.com"
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "5d621bf1561047175b967cdf3aa35446f7d7198a",
|
|
42
42
|
"repository": {}
|
|
43
43
|
}
|