ohos-router 1.1.6 → 1.1.7
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 +1 -1
- package/router.ts +36 -49
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -168,11 +168,11 @@ export function pluginStart(node: HvigorNode, isExecute: boolean) {
|
|
|
168
168
|
}
|
|
169
169
|
})
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
if (importHaveConfig.indexOf(name + "RouterConfig") == -1) {
|
|
172
|
+
//证明没导入,那就手动再导入一次
|
|
173
|
+
importHaveConfig = importHaveConfig + "\nimport { " + name +
|
|
174
|
+
"RouterConfig } from '" + name.toLowerCase() + "';\n";
|
|
175
|
+
}
|
|
176
176
|
}
|
|
177
177
|
})
|
|
178
178
|
|
|
@@ -232,25 +232,15 @@ function hasTwoOccurrencesIndexOf(str: string, target: string): boolean {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
let moduleSrcEntry: string
|
|
235
|
-
|
|
235
|
+
|
|
236
|
+
function moduleJson5JSONParse(json: string) {
|
|
236
237
|
try {
|
|
238
|
+
let moduleJson5Data = getEndJson(json);
|
|
237
239
|
let moduleJsonBean = JSON.parse(moduleJson5Data)
|
|
238
240
|
let module = moduleJsonBean.module
|
|
239
241
|
moduleSrcEntry = module.srcEntry
|
|
240
242
|
} catch (error) {
|
|
241
|
-
|
|
242
|
-
const repairedJson = moduleJson5Data
|
|
243
|
-
// 修复单引号
|
|
244
|
-
.replace(/'/g, '"')
|
|
245
|
-
// 修复未加引号的键名
|
|
246
|
-
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
247
|
-
// 修复尾随逗号
|
|
248
|
-
.replace(/,\s*}/g, '}')
|
|
249
|
-
.replace(/,\s*]/g, ']')
|
|
250
|
-
// 修复注释(移除单行和多行注释)
|
|
251
|
-
.replace(/\/\/.*$/gm, '')
|
|
252
|
-
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
253
|
-
moduleJson5JSONParse(repairedJson)
|
|
243
|
+
moduleJson5JSONParse(getEndJson(json))
|
|
254
244
|
}
|
|
255
245
|
}
|
|
256
246
|
|
|
@@ -352,8 +342,9 @@ function log(params: string) {
|
|
|
352
342
|
|
|
353
343
|
let dependenciesKey: string[]
|
|
354
344
|
|
|
355
|
-
function dependenciesJSONParse(
|
|
345
|
+
function dependenciesJSONParse(json: string) {
|
|
356
346
|
try {
|
|
347
|
+
let ohPackageData = getEndJson(json);
|
|
357
348
|
dependenciesKey = []
|
|
358
349
|
let ohPackAgeBean = JSON.parse(ohPackageData)
|
|
359
350
|
let dependencies = ohPackAgeBean.dependencies
|
|
@@ -363,24 +354,13 @@ function dependenciesJSONParse(ohPackageData: string) {
|
|
|
363
354
|
}
|
|
364
355
|
}
|
|
365
356
|
} catch (error) {
|
|
366
|
-
|
|
367
|
-
const repairedJson = ohPackageData
|
|
368
|
-
// 修复单引号
|
|
369
|
-
.replace(/'/g, '"')
|
|
370
|
-
// 修复未加引号的键名
|
|
371
|
-
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
372
|
-
// 修复尾随逗号
|
|
373
|
-
.replace(/,\s*}/g, '}')
|
|
374
|
-
.replace(/,\s*]/g, ']')
|
|
375
|
-
// 修复注释(移除单行和多行注释)
|
|
376
|
-
.replace(/\/\/.*$/gm, '')
|
|
377
|
-
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
378
|
-
dependenciesJSONParse(repairedJson)
|
|
357
|
+
dependenciesJSONParse(getEndJson(json))
|
|
379
358
|
}
|
|
380
359
|
}
|
|
381
360
|
|
|
382
|
-
function buildProfileJSONParse(
|
|
361
|
+
function buildProfileJSONParse(json: string) {
|
|
383
362
|
try {
|
|
363
|
+
let buildProfileData = getEndJson(json);
|
|
384
364
|
let buildProfileBean = JSON.parse(buildProfileData)
|
|
385
365
|
let buildOptionBean = buildProfileBean.buildOption
|
|
386
366
|
if (buildOptionBean.arkOptions == undefined) {
|
|
@@ -402,21 +382,25 @@ function buildProfileJSONParse(buildProfileData: string) {
|
|
|
402
382
|
}
|
|
403
383
|
}
|
|
404
384
|
} catch (error) {
|
|
405
|
-
|
|
406
|
-
// 修复单引号
|
|
407
|
-
.replace(/'/g, '"')
|
|
408
|
-
// 修复未加引号的键名
|
|
409
|
-
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
410
|
-
// 修复尾随逗号
|
|
411
|
-
.replace(/,\s*}/g, '}')
|
|
412
|
-
.replace(/,\s*]/g, ']')
|
|
413
|
-
// 修复注释(移除单行和多行注释)
|
|
414
|
-
.replace(/\/\/.*$/gm, '')
|
|
415
|
-
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
416
|
-
buildProfileJSONParse(repairedJson)
|
|
385
|
+
buildProfileJSONParse(getEndJson(json))
|
|
417
386
|
}
|
|
418
387
|
}
|
|
419
388
|
|
|
389
|
+
function getEndJson(json: string) {
|
|
390
|
+
const repairedJson = json
|
|
391
|
+
// 修复单引号
|
|
392
|
+
.replace(/'/g, '"')
|
|
393
|
+
// 修复未加引号的键名
|
|
394
|
+
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
395
|
+
// 修复尾随逗号
|
|
396
|
+
.replace(/,\s*}/g, '}')
|
|
397
|
+
.replace(/,\s*]/g, ']')
|
|
398
|
+
// 修复注释(移除单行和多行注释)
|
|
399
|
+
.replace(/\/\/.*$/gm, '')
|
|
400
|
+
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
401
|
+
return repairedJson;
|
|
402
|
+
}
|
|
403
|
+
|
|
420
404
|
|
|
421
405
|
function printBuildProFile(buildProfileData: string, type: number) {
|
|
422
406
|
let endArray = ""
|
|
@@ -464,13 +448,16 @@ function printBuildProFile(buildProfileData: string, type: number) {
|
|
|
464
448
|
let buildProfilePosition = buildProfileData.indexOf(buildProfileTag) + buildProfileTag.length
|
|
465
449
|
let buildProfileBuilder = "\n \"packages\": [\n" +
|
|
466
450
|
endArray +
|
|
467
|
-
" ]
|
|
451
|
+
" ],\n"
|
|
468
452
|
buildProfileContent = insertString(buildProfileData, buildProfilePosition, buildProfileBuilder)
|
|
469
453
|
} else if (type == 3) {
|
|
454
|
+
let buildProfileBean = JSON.parse(buildProfileData)
|
|
455
|
+
buildProfileBean.buildOption.arkOptions.runtimeOnly.packages = [];
|
|
456
|
+
let endJson = JSON.stringify(buildProfileBean)
|
|
470
457
|
let buildProfileTag = "\"packages\": ["
|
|
471
|
-
let buildProfilePosition =
|
|
458
|
+
let buildProfilePosition = endJson.indexOf(buildProfileTag) + buildProfileTag.length
|
|
472
459
|
let buildProfileBuilder = "\n" + endArray
|
|
473
|
-
buildProfileContent = insertString(
|
|
460
|
+
buildProfileContent = insertString(endJson, buildProfilePosition, buildProfileBuilder)
|
|
474
461
|
}
|
|
475
462
|
|
|
476
463
|
FileUtil.writeFileSync(buildProfilePath, buildProfileContent);
|