ohos-router 1.2.2 → 1.2.4

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": "ohos-router",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "鸿蒙路由管理插件",
5
5
  "main": "main.js",
6
6
  "scripts": {
package/router-plugin.ts CHANGED
@@ -5,7 +5,19 @@ export function abnerRouter(isExecute: boolean = true): HvigorPlugin {
5
5
  return {
6
6
  pluginId: 'abnerRouter',
7
7
  apply(node: HvigorNode) {
8
- pluginStart(node, isExecute)
8
+ pluginStart(node, isExecute, [])
9
9
  }
10
10
  }
11
11
  }
12
+
13
+ //路由过滤
14
+ export function abnerRouterFilter(isExecute: boolean = true, filterModule: string[] = []): HvigorPlugin {
15
+ return {
16
+ pluginId: 'abnerRouter',
17
+ apply(node: HvigorNode) {
18
+ pluginStart(node, isExecute, filterModule)
19
+ }
20
+ }
21
+ }
22
+
23
+
package/router.ts CHANGED
@@ -4,7 +4,7 @@ let entryModulePath = ""
4
4
  let entryUpperCaseNameArray: string[] = []
5
5
  let entryIsHsp: boolean[] = []
6
6
 
7
- export function pluginStart(node: HvigorNode, isExecute: boolean) {
7
+ export function pluginStart(node: HvigorNode, isExecute: boolean, filterModule: string[]) {
8
8
  if (!isExecute) {
9
9
  return
10
10
  }
@@ -25,7 +25,9 @@ export function pluginStart(node: HvigorNode, isExecute: boolean) {
25
25
  }
26
26
  let configPath = FileUtil.pathResolve(childNode.getNodePath(), upperCaseName + "RouterConfig.ets")
27
27
 
28
- if (!FileUtil.exist(configPath)) {
28
+ let isFilter = filterModule.includes(nodeName)//是否包含
29
+
30
+ if (!FileUtil.exist(configPath) && !isFilter) {
29
31
  FileUtil.ensureFileSync(configPath)
30
32
  FileUtil.writeFileSync(configPath, getRouterConfig(upperCaseName, nodeName, isHsp))
31
33
  if (!isHap) {
@@ -41,7 +43,7 @@ export function pluginStart(node: HvigorNode, isExecute: boolean) {
41
43
  }
42
44
  }
43
45
 
44
- if (isHap) {
46
+ if (isHap && !isFilter) {
45
47
  entryModulePath = childNode.getNodePath()
46
48
  writeBuildProfile(childNode)
47
49
  }
@@ -158,12 +160,17 @@ export function pluginStart(node: HvigorNode, isExecute: boolean) {
158
160
  endHsp = "getARouter()"
159
161
  }
160
162
 
161
- if(appFileDataString.indexOf("new "+name+"RouterConfig(") == -1){
162
- isHaveConfig=true;
163
+ if (appFileDataString.indexOf("new " + name + "RouterConfig(") == -1) {
164
+ isHaveConfig = true;
163
165
  initHaveConfig = initHaveConfig + (" new " + name + "RouterConfig(" + endHsp + "),\n")
164
166
  }
165
- if(appFileDataString.indexOf("import { "+name+"RouterConfig }") == -1){
166
- isHaveConfig=true;
167
+
168
+ //这个必须要带
169
+ let exportClassIndex = appFileDataString.indexOf("export class");
170
+ let exportContent = appFileDataString.substring(0, exportClassIndex);
171
+
172
+ if (exportContent.indexOf(name + "RouterConfig") == -1) {
173
+ isHaveConfig = true;
167
174
  importHaveConfig = importHaveConfig + "\nimport { " + name + "RouterConfig } from '" + name.toLowerCase() + "';\n"
168
175
  }
169
176
  })
@@ -219,7 +226,7 @@ function moduleJson5JSONParse(json: string) {
219
226
  let module = moduleJsonBean.module
220
227
  moduleSrcEntry = module.srcEntry
221
228
  } catch (error) {
222
- console.log("moduleJson5JSONParse:"+error)
229
+ console.log("moduleJson5JSONParse:" + error)
223
230
  }
224
231
  }
225
232
 
@@ -333,7 +340,7 @@ function dependenciesJSONParse(json: string) {
333
340
  }
334
341
  }
335
342
  } catch (error) {
336
- console.log("dependenciesJSONParse:"+error)
343
+ console.log("dependenciesJSONParse:" + error)
337
344
  }
338
345
  }
339
346
 
@@ -361,7 +368,7 @@ function buildProfileJSONParse(json: string) {
361
368
  }
362
369
  }
363
370
  } catch (error) {
364
- console.log("buildProfileJSONParse:"+error)
371
+ console.log("buildProfileJSONParse:" + error)
365
372
  }
366
373
  }
367
374
 
@@ -412,7 +419,7 @@ function printBuildProFile(buildProfileData: string, type: number) {
412
419
  endArray +
413
420
  " ]\n" +
414
421
  " }\n" +
415
- " }"
422
+ " }\n,"
416
423
 
417
424
  buildProfileContent = insertString(buildProfileData, buildProfilePosition, buildProfileBuilder)
418
425
  } else if (type == 1) {