@hadss/hmrouter-plugin 1.0.0-rc.1 → 1.0.0-rc.11

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 (59) hide show
  1. package/README.md +240 -17
  2. package/dist/HMRouterAnalyzer.d.ts +31 -0
  3. package/dist/HMRouterAnalyzer.js +296 -0
  4. package/dist/HMRouterHvigorPlugin.d.ts +15 -0
  5. package/dist/HMRouterHvigorPlugin.js +143 -0
  6. package/dist/HMRouterPluginConfig.d.ts +39 -0
  7. package/dist/HMRouterPluginConfig.js +74 -0
  8. package/dist/HMRouterPluginHandle.d.ts +23 -0
  9. package/dist/HMRouterPluginHandle.js +222 -0
  10. package/dist/Index.d.ts +4 -0
  11. package/dist/Index.js +128 -0
  12. package/dist/common/Constant.d.ts +27 -0
  13. package/{lib → dist}/common/Constant.js +0 -15
  14. package/dist/common/Logger.d.ts +13 -0
  15. package/{lib → dist}/common/Logger.js +17 -24
  16. package/dist/common/PluginModel.d.ts +50 -0
  17. package/{lib → dist}/common/PluginModel.js +2 -16
  18. package/dist/constants/CommonConstants.d.ts +38 -0
  19. package/dist/constants/CommonConstants.js +45 -0
  20. package/dist/constants/ConfigConstants.d.ts +12 -0
  21. package/dist/constants/ConfigConstants.js +16 -0
  22. package/dist/constants/TaskConstants.d.ts +9 -0
  23. package/dist/constants/TaskConstants.js +13 -0
  24. package/dist/store/PluginStore.d.ts +14 -0
  25. package/dist/store/PluginStore.js +20 -0
  26. package/dist/utils/ConfusionUtil.d.ts +4 -0
  27. package/dist/utils/ConfusionUtil.js +27 -0
  28. package/dist/utils/FileUtil.d.ts +11 -0
  29. package/dist/utils/FileUtil.js +20 -0
  30. package/dist/utils/ObfuscationUtil.d.ts +4 -0
  31. package/dist/utils/ObfuscationUtil.js +34 -0
  32. package/dist/utils/StringUtil.d.ts +3 -0
  33. package/dist/utils/StringUtil.js +18 -0
  34. package/dist/utils/TsAstUtil.d.ts +9 -0
  35. package/dist/utils/TsAstUtil.js +89 -0
  36. package/package.json +26 -12
  37. package/{viewBuilder.tpl → viewBuilder.ejs} +18 -11
  38. package/lib/HMRouterAnalyzer.js +0 -351
  39. package/lib/HMRouterAnalyzer.js.map +0 -1
  40. package/lib/HMRouterHvigorPlugin.js +0 -177
  41. package/lib/HMRouterHvigorPlugin.js.map +0 -1
  42. package/lib/HMRouterPluginConfig.js +0 -31
  43. package/lib/HMRouterPluginConfig.js.map +0 -1
  44. package/lib/HMRouterPluginHandle.js +0 -148
  45. package/lib/HMRouterPluginHandle.js.map +0 -1
  46. package/lib/Index.js +0 -143
  47. package/lib/Index.js.map +0 -1
  48. package/lib/common/Constant.js.map +0 -1
  49. package/lib/common/Logger.js.map +0 -1
  50. package/lib/common/PluginModel.js.map +0 -1
  51. package/src/HMRouterAnalyzer.ts +0 -375
  52. package/src/HMRouterHvigorPlugin.ts +0 -199
  53. package/src/HMRouterPluginConfig.ts +0 -44
  54. package/src/HMRouterPluginHandle.ts +0 -188
  55. package/src/Index.ts +0 -151
  56. package/src/common/Constant.ts +0 -49
  57. package/src/common/Logger.ts +0 -73
  58. package/src/common/PluginModel.ts +0 -83
  59. package/tsconfig.json +0 -14
@@ -1,188 +0,0 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import { FileUtil, HvigorNode } from '@ohos/hvigor'
17
- import { OhosHapContext, OhosHarContext, OhosHspContext, Target } from '@ohos/hvigor-ohos-plugin'
18
- import { HMRouterPluginConfig } from './HMRouterPluginConfig'
19
- import { HMRouterHvigorPlugin } from './HMRouterHvigorPlugin'
20
- import { Logger } from './common/Logger'
21
- import { HMRouterPluginConstant } from './common/Constant'
22
- import { RouterInfo } from './common/PluginModel'
23
-
24
- // HMRouterPluginHandle类,用于处理HMRouter插件
25
- export class HMRouterPluginHandle {
26
- // 节点
27
- private readonly node: HvigorNode
28
- // 模块上下文
29
- private readonly moduleContext: OhosHapContext | OhosHarContext | OhosHspContext
30
- // 配置
31
- public readonly config: HMRouterPluginConfig
32
- // 插件
33
- private readonly plugin: HMRouterHvigorPlugin
34
-
35
- // 构造函数,初始化节点、模块上下文、配置和插件
36
- constructor(node: HvigorNode, moduleContext: OhosHapContext | OhosHarContext | OhosHspContext) {
37
- this.node = node
38
- this.moduleContext = moduleContext
39
- this.config = this.readConfig()
40
- this.plugin = new HMRouterHvigorPlugin(this.config)
41
- }
42
-
43
- // 启动插件
44
- public start() {
45
- Logger.i(`Exec ${this.moduleContext.getModuleType()}Plugin..., node:${this.node.getNodeName()}, nodePath:${this.node.getNodePath()}`)
46
- this.moduleContext.targets((target: Target) => {
47
- const targetName = target.getTargetName()
48
- this.node.registerTask({
49
- name: `${targetName}@HMRouterPluginTask`,
50
- run: () => {
51
- this.taskExec()
52
- },
53
- dependencies: [`${targetName}@PreBuild`],
54
- postDependencies: [`${targetName}@MergeProfile`]
55
- })
56
-
57
- this.node.registerTask({
58
- name: `${targetName}@CopyRouterMapToRawFileTask`,
59
- run: () => {
60
- this.copyRouterMapToRawFileTask(target.getBuildTargetOutputPath(), targetName)
61
- },
62
- dependencies: [`${targetName}@ProcessRouterMap`],
63
- postDependencies: [`${targetName}@ProcessResource`]
64
- })
65
- })
66
- }
67
-
68
- // 拷贝routerMap到raw文件
69
- private copyRouterMapToRawFileTask(buildOutputPath: string, targetName: string) {
70
- let routerMapFilePath = FileUtil.pathResolve(
71
- buildOutputPath,
72
- HMRouterPluginConstant.TEMP_ROUTER_MAP_PATH,
73
- targetName,
74
- HMRouterPluginConstant.ROUTER_MAP_NAME
75
- )
76
- let rawFilePath = FileUtil.pathResolve(this.config.modulePath, HMRouterPluginConstant.RAWFILE_DIR)
77
- FileUtil.ensureFileSync(rawFilePath)
78
- FileUtil.copyFileSync(routerMapFilePath, rawFilePath)
79
- }
80
-
81
- // 执行任务
82
- private taskExec() {
83
- let startTime = Date.now()
84
- Logger.i(this.node.getNodeName() + ' :HMRouterPluginTask start---' + startTime)
85
-
86
- // 分析注解
87
- this.plugin.analyzeAnnotation()
88
- // 更新module.json
89
- this.updateModuleJsonOpt()
90
- // 更新profile
91
- this.updateBuildProfileOpt()
92
-
93
- let endTime = Date.now()
94
- Logger.i(this.config.moduleName + ' :HMRouterPluginTask end---' + endTime)
95
- Logger.i(this.config.moduleName + ' :HMRouterPluginTask cost---' + (endTime - startTime) + 'ms')
96
- }
97
-
98
- // 更新module.json
99
- private updateModuleJsonOpt() {
100
- // 获取模块的json配置
101
- const moduleJsonOpt = this.moduleContext.getModuleJsonOpt()
102
- // 如果模块的json配置中有routerMap
103
- if (moduleJsonOpt.module.routerMap) {
104
- // 获取routerMap的文件名
105
- let routerMapFileName = moduleJsonOpt.module.routerMap.split(':')[1]
106
- // 获取routerMap的文件路径
107
- let routerMapFilePath = FileUtil.pathResolve(
108
- this.config.modulePath,
109
- this.config.routerMapDir,
110
- routerMapFileName + HMRouterPluginConstant.JSON_SUFFIX
111
- )
112
- // 读取routerMap的json文件
113
- let routerMapObj = FileUtil.readJson5(routerMapFilePath)
114
- // 将routerMap添加到plugin的routerMap中
115
- this.plugin.routerMap.unshift(...((routerMapObj as any)['routerMap'] as Array<RouterInfo>))
116
- }
117
- // 生成routerMap
118
- this.plugin.generateRouterMap()
119
- // 将routerMap的名称设置为MODULE_ROUTER_MAP_NAME
120
- moduleJsonOpt.module.routerMap = HMRouterPluginConstant.MODULE_ROUTER_MAP_NAME
121
- // 将修改后的moduleJsonOpt设置到moduleContext中
122
- this.moduleContext.setModuleJsonOpt(moduleJsonOpt)
123
- }
124
-
125
- private updateBuildProfileOpt() {
126
- // 获取构建配置选项
127
- const buildProfileOpt = this.moduleContext.getBuildProfileOpt()
128
-
129
- // 初始化 arkOptions 和 runtimeOnly 配置
130
- if (!buildProfileOpt.buildOption) {
131
- buildProfileOpt.buildOption = {}
132
- }
133
-
134
- if (!buildProfileOpt.buildOption.arkOptions) {
135
- buildProfileOpt.buildOption.arkOptions = {}
136
- }
137
-
138
- if (!buildProfileOpt.buildOption.arkOptions.runtimeOnly) {
139
- buildProfileOpt.buildOption.arkOptions.runtimeOnly = {}
140
- }
141
-
142
- if (!buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources) {
143
- buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources = []
144
- }
145
-
146
- // 将路由信息推送到构建配置选项中
147
- this.pushRouterInfo(buildProfileOpt, this.plugin.routerMap)
148
-
149
- // 将构建配置选项设置到moduleContext中
150
- this.moduleContext.setBuildProfileOpt(buildProfileOpt)
151
- }
152
-
153
- // 将路由信息添加到 buildProfileOpt 中
154
- private pushRouterInfo(buildProfileOpt: any, routerMap: Array<RouterInfo>) {
155
- const sources = buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources
156
-
157
- routerMap.forEach((item: RouterInfo) => {
158
- const name = item.name
159
- if (
160
- name.includes(HMRouterPluginConstant.LIFECYCLE_PREFIX) ||
161
- name.includes(HMRouterPluginConstant.INTERCEPTOR_PREFIX) ||
162
- name.includes(HMRouterPluginConstant.ANIMATOR_PREFIX) ||
163
- name.includes(HMRouterPluginConstant.SERVICE_PREFIX)
164
- ) {
165
- sources.push('./' + item.pageSourceFile)
166
- }
167
- })
168
- }
169
-
170
- // 读取配置
171
- private readConfig(): HMRouterPluginConfig {
172
- let levels = 0
173
- let configParam = {}
174
- while (levels < 4) {
175
- let configFilePath = FileUtil.pathResolve(
176
- this.node.getNodePath(),
177
- HMRouterPluginConstant.PARENT_DELIMITER.repeat(levels) + HMRouterPluginConstant.CONFIG_FILE_NAME
178
- )
179
- if (FileUtil.exist(configFilePath)) {
180
- configParam = FileUtil.readJson5(configFilePath)
181
- break
182
- }
183
- levels++
184
- }
185
-
186
- return new HMRouterPluginConfig(this.node.getNodeName(), this.node.getNodePath(), configParam)
187
- }
188
- }
package/src/Index.ts DELETED
@@ -1,151 +0,0 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import {FileUtil, hvigor, HvigorNode, HvigorPlugin} from '@ohos/hvigor'
17
- import {OhosHapContext, OhosHarContext, OhosHspContext, OhosPluginId} from '@ohos/hvigor-ohos-plugin'
18
- import {HMRouterPluginHandle} from './HMRouterPluginHandle'
19
- import {HMRouterPluginConstant} from './common/Constant'
20
- import {Logger, PluginError} from './common/Logger'
21
- import fs from 'fs'
22
-
23
- // HMRouterPluginMgr类,用于管理HMRouterPluginHandle实例
24
- class HMRouterPluginMgr {
25
- // HMRouterPluginHandle实例集合
26
- hmRouterPluginSet: Set<HMRouterPluginHandle> = new Set()
27
-
28
- // 构造函数,在hvigor节点评估后启动所有HMRouterPluginHandle实例,在hvigor构建完成后删除生成的文件
29
- constructor() {
30
- hvigor.nodesEvaluated(() => {
31
- this.hmRouterPluginSet.forEach(pluginHandle => {
32
- pluginHandle.start()
33
- })
34
- })
35
-
36
- hvigor.buildFinished(() => {
37
- this.deleteGeneratorFile()
38
- HMRouterPluginMgrInstance = null
39
- })
40
- }
41
-
42
- // 注册HMRouterPluginHandle实例
43
- public registerHMRouterPlugin(node: HvigorNode, pluginId: string) {
44
- // 获取节点上下文
45
- const moduleContext = node.getContext(pluginId) as OhosHapContext | OhosHarContext | OhosHspContext
46
-
47
- // 如果节点上下文为空,抛出错误
48
- if (!moduleContext) {
49
- Logger.e(PluginError.ERR_ERROR_CONFIG, node.getNodePath())
50
- throw new Error('moduleContext is null')
51
- }
52
-
53
- // 创建HMRouterPluginHandle实例
54
- let pluginHandle = new HMRouterPluginHandle(node, moduleContext)
55
- // 如果插件ID为OHOS_HAP_PLUGIN,设置模块名称
56
- if (pluginId === OhosPluginId.OHOS_HAP_PLUGIN) {
57
- let packageJson: any = FileUtil.readJson5(FileUtil.pathResolve(node.getNodePath(), 'oh-package.json5'))
58
- pluginHandle.config.moduleName = packageJson.name
59
- }
60
-
61
- // 将HMRouterPluginHandle实例添加到集合中
62
- this.hmRouterPluginSet.add(pluginHandle)
63
- }
64
-
65
- // 删除生成的文件
66
- private deleteGeneratorFile() {
67
- Logger.i('deleteGeneratorFile exec...')
68
- for (let hmRouterPlugin of this.hmRouterPluginSet) {
69
- // 如果saveGeneratedFile为true,跳过删除
70
- if (hmRouterPlugin.config.saveGeneratedFile) {
71
- Logger.i(hmRouterPlugin.config.moduleName + ' saveGeneratedFile is true, skip delete')
72
- continue
73
- }
74
- // 获取routerMapDirPath路径
75
- let routerMapDirPath = FileUtil.pathResolve(
76
- hmRouterPlugin.config.modulePath,
77
- hmRouterPlugin.config.routerMapDir,
78
- HMRouterPluginConstant.ROUTER_MAP_NAME
79
- )
80
- // 如果路径存在,删除hm_router_map.json文件
81
- if (FileUtil.exist(routerMapDirPath)) {
82
- fs.unlinkSync(routerMapDirPath)
83
- Logger.i(routerMapDirPath + ' delete hm_router_map.json')
84
- }
85
- // 获取builderDirPath路径
86
- let builderDirPath = FileUtil.pathResolve(hmRouterPlugin.config.modulePath, hmRouterPlugin.config.builderDir)
87
- // 如果路径存在,删除builder目录
88
- if (FileUtil.exist(builderDirPath)) {
89
- fs.rmSync(builderDirPath, {
90
- recursive: true
91
- })
92
- Logger.i(hmRouterPlugin.config.modulePath + ' delete builder dir')
93
- }
94
- // 获取rawFile路径
95
- let rawFilePath = FileUtil.pathResolve(hmRouterPlugin.config.modulePath, HMRouterPluginConstant.RAWFILE_DIR)
96
- // 如果路径存在,删除builder目录
97
- if (FileUtil.exist(rawFilePath)) {
98
- fs.unlinkSync(rawFilePath)
99
- Logger.i(hmRouterPlugin.config.modulePath + ' delete rawfile hm_router_map.json')
100
- }
101
- }
102
- }
103
- }
104
-
105
- // HMRouterPluginMgr实例
106
- let HMRouterPluginMgrInstance: HMRouterPluginMgr | null = null
107
-
108
- // hap插件
109
- export function hapPlugin(): HvigorPlugin {
110
- return {
111
- pluginId: HMRouterPluginConstant.HAP_PLUGIN_ID,
112
- apply(node: HvigorNode) {
113
- // 如果HMRouterPluginMgr实例为空,创建新的实例
114
- if (!HMRouterPluginMgrInstance) {
115
- HMRouterPluginMgrInstance = new HMRouterPluginMgr()
116
- }
117
- // 注册HMRouterPluginHandle实例
118
- HMRouterPluginMgrInstance.registerHMRouterPlugin(node, OhosPluginId.OHOS_HAP_PLUGIN)
119
- }
120
- }
121
- }
122
-
123
- // hsp插件
124
- export function hspPlugin(): HvigorPlugin {
125
- return {
126
- pluginId: HMRouterPluginConstant.HSP_PLUGIN_ID,
127
- apply(node: HvigorNode) {
128
- // 如果HMRouterPluginMgr实例为空,创建新的实例
129
- if (!HMRouterPluginMgrInstance) {
130
- HMRouterPluginMgrInstance = new HMRouterPluginMgr()
131
- }
132
- // 注册HMRouterPluginHandle实例
133
- HMRouterPluginMgrInstance.registerHMRouterPlugin(node, OhosPluginId.OHOS_HSP_PLUGIN)
134
- }
135
- }
136
- }
137
-
138
- // har插件
139
- export function harPlugin(): HvigorPlugin {
140
- return {
141
- pluginId: HMRouterPluginConstant.HAR_PLUGIN_ID,
142
- apply(node: HvigorNode) {
143
- // 如果HMRouterPluginMgr实例为空,创建新的实例
144
- if (!HMRouterPluginMgrInstance) {
145
- HMRouterPluginMgrInstance = new HMRouterPluginMgr()
146
- }
147
- // 注册HMRouterPluginHandle实例
148
- HMRouterPluginMgrInstance.registerHMRouterPlugin(node, OhosPluginId.OHOS_HAR_PLUGIN)
149
- }
150
- }
151
- }
@@ -1,49 +0,0 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import path from 'path'
17
-
18
- export class HMRouterPluginConstant {
19
- static readonly ANIMATOR_PREFIX = '__animator__'
20
- static readonly INTERCEPTOR_PREFIX = '__interceptor__'
21
- static readonly LIFECYCLE_PREFIX = '__lifecycle__'
22
- static readonly SERVICE_PREFIX = '__service__'
23
- static readonly PAGE_URL_PREFIX = ''
24
-
25
- static readonly FILE_SEPARATOR = path.sep
26
- static readonly DELIMITER = '/'
27
-
28
- static readonly MODULE_ROUTER_MAP_NAME = '$profile:hm_router_map'
29
- static readonly ROUTER_MAP_NAME = 'hm_router_map.json'
30
- static readonly TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map'
31
- static readonly RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json'
32
- static readonly VIEW_NAME_PREFIX = 'HM'
33
- static readonly VIEW_NAME_SUFFIX = '.ets'
34
- static readonly JSON_SUFFIX = '.json'
35
-
36
- static readonly HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN'
37
- static readonly HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN'
38
- static readonly HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN'
39
-
40
- static readonly ROUTER_ANNOTATION = 'HMRouter'
41
- static readonly ANIMATOR_ANNOTATION = 'HMAnimator'
42
- static readonly INTERCEPTOR_ANNOTATION = 'HMInterceptor'
43
- static readonly LIFECYCLE_ANNOTATION = 'HMLifecycle'
44
- static readonly SERVICE_ANNOTATION = 'HMService'
45
- static readonly CLASS_ANNOTATION_ARR = ['HMAnimator', 'HMInterceptor', 'HMLifecycle']
46
-
47
- static readonly CONFIG_FILE_NAME = 'hmrouter_config.json'
48
- static readonly PARENT_DELIMITER = '../'
49
- }
@@ -1,73 +0,0 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import {HvigorLogger} from "@ohos/hvigor";
17
-
18
- export class Logger {
19
- static e(format: string, ...args: string[]) {
20
- let formatStr: string = format
21
- if (DEFINED_ERROR.has(format)) {
22
- formatStr = `errorCode ${DEFINED_ERROR.get(format)?.errorCode}, errorMsg: ${DEFINED_ERROR.get(format)?.errorMsg}`
23
- }
24
-
25
- const publicFormat =
26
- `[HMRouterPlugin ERROR]${formatStr.replace('%s', args[0])}`
27
- HvigorLogger.getLogger().error(publicFormat)
28
- }
29
-
30
- static i(msg: string, ...args: unknown[]) {
31
- HvigorLogger.getLogger().info(msg, ...args)
32
- }
33
- }
34
-
35
- export enum PluginError {
36
- ERR_DUPLICATE_NAME = 'ERR_DUPLICATE_NAME',
37
- ERR_WRONG_DECORATION = 'ERR_DUPLICATE_',
38
- ERR_REPEAT_ANNOTATION = 'ERR_INIT_FRAMEWORK',
39
- ERR_ERROR_CONFIG = 'ERR_INIT_COMPONENT',
40
- ERR_NOT_EMPTY_STRING = 'ERR_INIT_NOT_READY'
41
- }
42
-
43
- interface PluginErrorInfo {
44
- errorCode: number
45
- errorMsg: string
46
- }
47
-
48
- const DEFINED_ERROR: Map<string, PluginErrorInfo> = new Map()
49
-
50
- DEFINED_ERROR.set(PluginError.ERR_DUPLICATE_NAME, {
51
- errorCode: 40000001,
52
- errorMsg: '重复的pageUrl、拦截器、生命周期、动画、服务 - %s',
53
- })
54
-
55
- DEFINED_ERROR.set(PluginError.ERR_WRONG_DECORATION, {
56
- errorCode: 40000002,
57
- errorMsg: '@HMRouter修饰的组件不能包含NavDestination - %s',
58
- })
59
-
60
- DEFINED_ERROR.set(PluginError.ERR_REPEAT_ANNOTATION, {
61
- errorCode: 40000003,
62
- errorMsg: '文件 %s 中存在多个HMRouter注解',
63
- })
64
-
65
- DEFINED_ERROR.set(PluginError.ERR_ERROR_CONFIG, {
66
- errorCode: 40000004,
67
- errorMsg: 'moduleContext is null 请检查插件的hvigorfile配置 - %s',
68
- })
69
-
70
- DEFINED_ERROR.set(PluginError.ERR_NOT_EMPTY_STRING, {
71
- errorCode: 40000005,
72
- errorMsg: '%s 常量值不能为空字符串 - %s',
73
- })
@@ -1,83 +0,0 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- export type AnalyzerResultLike = HMRouterResult | HMAnimatorResult | HMInterceptorResult | HMLifecycleResult | HMServiceResult
17
-
18
- export interface BaseAnalyzeResult {
19
- name?: string // 类名
20
- module?: string // 模块名
21
- annotation?: string // 注解
22
- }
23
-
24
- export interface HMRouterResult extends BaseAnalyzeResult {
25
- pageUrl?: any // 跳转路径
26
- dialog?: boolean // 是否弹窗
27
- singleton?: boolean // 是否单例
28
- interceptors?: string[] // 拦截器
29
- animator?: string // 动画
30
- lifecycle?: string // 生命周期
31
- }
32
-
33
- export interface HMAnimatorResult extends BaseAnalyzeResult {
34
- animatorName?: string // 动画名称
35
- }
36
-
37
- export interface HMInterceptorResult extends BaseAnalyzeResult {
38
- interceptorName?: string // 拦截器名称
39
- priority?: number // 优先级
40
- global?: boolean // 是否全局
41
- }
42
-
43
- export interface HMLifecycleResult extends BaseAnalyzeResult {
44
- lifecycleName?: string // 生命周期名称
45
- priority?: number // 优先级
46
- global?: boolean // 是否全局
47
- }
48
-
49
- export interface HMServiceResult extends BaseAnalyzeResult {
50
- serviceName?: string // 服务名称
51
- functionName?: string // 函数名称
52
- singleton?: boolean // 是否单例
53
- }
54
-
55
- export class TemplateModel {
56
- pageUrl: string
57
- importPath: string
58
- componentName: string
59
- dialog: boolean
60
- generatorViewName: string
61
-
62
- constructor(pageUrl: string, importPath: string, componentName: string, dialog: boolean, generatorViewName: string) {
63
- this.pageUrl = pageUrl
64
- this.importPath = importPath
65
- this.componentName = componentName
66
- this.dialog = dialog
67
- this.generatorViewName = generatorViewName
68
- }
69
- }
70
-
71
- export class RouterInfo {
72
- name: string
73
- pageSourceFile: string
74
- buildFunction: string
75
- customData: AnalyzerResultLike
76
-
77
- constructor(name: string, pageSourceFile: string, buildFunction: string, data: AnalyzerResultLike = {}) {
78
- this.name = name
79
- this.pageSourceFile = pageSourceFile
80
- this.buildFunction = buildFunction
81
- this.customData = data
82
- }
83
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2021",
4
- "module": "commonjs",
5
- "strict": true,
6
- "esModuleInterop": true,
7
- "skipLibCheck": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "sourceMap": true,
10
- "outDir": "./lib"
11
- },
12
- "include": [".eslintrc.js","src/**/*"],
13
- "exclude": ["node_modules", "lib/**/*"]
14
- }