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

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 +293 -0
  4. package/dist/HMRouterHvigorPlugin.d.ts +15 -0
  5. package/dist/HMRouterHvigorPlugin.js +139 -0
  6. package/dist/HMRouterPluginConfig.d.ts +39 -0
  7. package/dist/HMRouterPluginConfig.js +73 -0
  8. package/dist/HMRouterPluginHandle.d.ts +23 -0
  9. package/dist/HMRouterPluginHandle.js +231 -0
  10. package/dist/Index.d.ts +4 -0
  11. package/dist/Index.js +124 -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 +39 -0
  19. package/dist/constants/CommonConstants.js +46 -0
  20. package/dist/constants/ConfigConstants.d.ts +11 -0
  21. package/dist/constants/ConfigConstants.js +15 -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 +12 -0
  25. package/dist/store/PluginStore.js +19 -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 +27 -13
  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,18 +1,4 @@
1
1
  "use strict";
2
- /*
3
- * Copyright (c) 2024 Huawei Device Co., Ltd.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
4
  };
@@ -47,4 +33,3 @@ HMRouterPluginConstant.SERVICE_ANNOTATION = 'HMService';
47
33
  HMRouterPluginConstant.CLASS_ANNOTATION_ARR = ['HMAnimator', 'HMInterceptor', 'HMLifecycle'];
48
34
  HMRouterPluginConstant.CONFIG_FILE_NAME = 'hmrouter_config.json';
49
35
  HMRouterPluginConstant.PARENT_DELIMITER = '../';
50
- //# sourceMappingURL=Constant.js.map
@@ -0,0 +1,13 @@
1
+ export declare class Logger {
2
+ static error(format: string, ...args: string[]): void;
3
+ static info(msg: string, ...args: unknown[]): void;
4
+ static warn(msg: string, ...args: unknown[]): void;
5
+ }
6
+ export declare enum PluginError {
7
+ ERR_DUPLICATE_NAME = "ERR_DUPLICATE_NAME",
8
+ ERR_WRONG_DECORATION = "ERR_DUPLICATE_",
9
+ ERR_REPEAT_ANNOTATION = "ERR_INIT_FRAMEWORK",
10
+ ERR_ERROR_CONFIG = "ERR_INIT_COMPONENT",
11
+ ERR_NOT_EMPTY_STRING = "ERR_INIT_NOT_READY",
12
+ ERR_INVALID_STRING_VALUE = "ERR_INVALID_STRING_VALUE"
13
+ }
@@ -1,32 +1,21 @@
1
1
  "use strict";
2
- /*
3
- * Copyright (c) 2024 Huawei Device Co., Ltd.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
3
  exports.PluginError = exports.Logger = void 0;
18
4
  const hvigor_1 = require("@ohos/hvigor");
19
5
  class Logger {
20
- static e(format, ...args) {
6
+ static error(format, ...args) {
21
7
  let formatStr = format;
22
8
  if (DEFINED_ERROR.has(format)) {
23
9
  formatStr = `errorCode ${DEFINED_ERROR.get(format)?.errorCode}, errorMsg: ${DEFINED_ERROR.get(format)?.errorMsg}`;
24
10
  }
25
- const publicFormat = `[HMRouterPlugin ERROR]${formatStr.replace('%s', args[0])}`;
11
+ const publicFormat = `[HMRouterPlugin] ERROR: ${formatStr.replace('%s', args[0])}`;
26
12
  hvigor_1.HvigorLogger.getLogger().error(publicFormat);
27
13
  }
28
- static i(msg, ...args) {
29
- hvigor_1.HvigorLogger.getLogger().info(msg, ...args);
14
+ static info(msg, ...args) {
15
+ hvigor_1.HvigorLogger.getLogger().info('[HMRouterPlugin] ' + msg, ...args);
16
+ }
17
+ static warn(msg, ...args) {
18
+ hvigor_1.HvigorLogger.getLogger().warn('[HMRouterPlugin] ' + msg, ...args);
30
19
  }
31
20
  }
32
21
  exports.Logger = Logger;
@@ -37,26 +26,30 @@ var PluginError;
37
26
  PluginError["ERR_REPEAT_ANNOTATION"] = "ERR_INIT_FRAMEWORK";
38
27
  PluginError["ERR_ERROR_CONFIG"] = "ERR_INIT_COMPONENT";
39
28
  PluginError["ERR_NOT_EMPTY_STRING"] = "ERR_INIT_NOT_READY";
29
+ PluginError["ERR_INVALID_STRING_VALUE"] = "ERR_INVALID_STRING_VALUE";
40
30
  })(PluginError || (exports.PluginError = PluginError = {}));
41
31
  const DEFINED_ERROR = new Map();
42
32
  DEFINED_ERROR.set(PluginError.ERR_DUPLICATE_NAME, {
43
33
  errorCode: 40000001,
44
- errorMsg: '重复的pageUrl、拦截器、生命周期、动画、服务 - %s',
34
+ errorMsg: 'Duplicate pageUrl/interceptor/service/animator/lifecycle - %s'
45
35
  });
46
36
  DEFINED_ERROR.set(PluginError.ERR_WRONG_DECORATION, {
47
37
  errorCode: 40000002,
48
- errorMsg: '@HMRouter修饰的组件不能包含NavDestination - %s',
38
+ errorMsg: 'Struct with @HMRouter annotation could not contain NavDestination component - %s'
49
39
  });
50
40
  DEFINED_ERROR.set(PluginError.ERR_REPEAT_ANNOTATION, {
51
41
  errorCode: 40000003,
52
- errorMsg: '文件 %s 中存在多个HMRouter注解',
42
+ errorMsg: 'File: %s contains multiple annotations'
53
43
  });
54
44
  DEFINED_ERROR.set(PluginError.ERR_ERROR_CONFIG, {
55
45
  errorCode: 40000004,
56
- errorMsg: 'moduleContext is null 请检查插件的hvigorfile配置 - %s',
46
+ errorMsg: 'moduleContext is null, Please check hvigorfile.ts file in module directory - %s'
57
47
  });
58
48
  DEFINED_ERROR.set(PluginError.ERR_NOT_EMPTY_STRING, {
59
49
  errorCode: 40000005,
60
- errorMsg: '%s 常量值不能为空字符串 - %s',
50
+ errorMsg: '%s constant value cannot be empty string - %s'
51
+ });
52
+ DEFINED_ERROR.set(PluginError.ERR_INVALID_STRING_VALUE, {
53
+ errorCode: 40000006,
54
+ errorMsg: 'invalid string value: %s'
61
55
  });
62
- //# sourceMappingURL=Logger.js.map
@@ -0,0 +1,50 @@
1
+ export type AnalyzerResultLike = HMRouterResult | HMAnimatorResult | HMInterceptorResult | HMLifecycleResult | HMServiceResult;
2
+ export interface BaseAnalyzeResult {
3
+ name?: string;
4
+ module?: string;
5
+ annotation?: string;
6
+ pageSourceFile?: string;
7
+ isDefaultExport?: boolean;
8
+ }
9
+ export interface HMRouterResult extends BaseAnalyzeResult {
10
+ pageUrl?: any;
11
+ dialog?: boolean;
12
+ singleton?: boolean;
13
+ interceptors?: string[];
14
+ animator?: string;
15
+ lifecycle?: string;
16
+ }
17
+ export interface HMAnimatorResult extends BaseAnalyzeResult {
18
+ animatorName?: string;
19
+ }
20
+ export interface HMInterceptorResult extends BaseAnalyzeResult {
21
+ interceptorName?: string;
22
+ priority?: number;
23
+ global?: boolean;
24
+ }
25
+ export interface HMLifecycleResult extends BaseAnalyzeResult {
26
+ lifecycleName?: string;
27
+ priority?: number;
28
+ global?: boolean;
29
+ }
30
+ export interface HMServiceResult extends BaseAnalyzeResult {
31
+ serviceName?: string;
32
+ functionName?: string;
33
+ singleton?: boolean;
34
+ }
35
+ export declare class TemplateModel {
36
+ pageUrl: string;
37
+ importPath: string;
38
+ componentName: string;
39
+ dialog: boolean;
40
+ generatorViewName: string;
41
+ isDefaultExport?: boolean;
42
+ constructor(pageUrl: string, importPath: string, componentName: string, dialog: boolean, generatorViewName: string, isDefaultExport?: boolean);
43
+ }
44
+ export declare class RouterInfo {
45
+ name: string;
46
+ pageSourceFile: string;
47
+ buildFunction: string;
48
+ customData: AnalyzerResultLike;
49
+ constructor(name: string, pageSourceFile: string, buildFunction: string, data?: AnalyzerResultLike);
50
+ }
@@ -1,22 +1,9 @@
1
1
  "use strict";
2
- /*
3
- * Copyright (c) 2024 Huawei Device Co., Ltd.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
3
  exports.RouterInfo = exports.TemplateModel = void 0;
18
4
  class TemplateModel {
19
- constructor(pageUrl, importPath, componentName, dialog, generatorViewName) {
5
+ constructor(pageUrl, importPath, componentName, dialog, generatorViewName, isDefaultExport) {
6
+ this.isDefaultExport = isDefaultExport;
20
7
  this.pageUrl = pageUrl;
21
8
  this.importPath = importPath;
22
9
  this.componentName = componentName;
@@ -34,4 +21,3 @@ class RouterInfo {
34
21
  }
35
22
  }
36
23
  exports.RouterInfo = RouterInfo;
37
- //# sourceMappingURL=PluginModel.js.map
@@ -0,0 +1,39 @@
1
+ export default class HMRouterPluginConstant {
2
+ static readonly ANIMATOR_PREFIX = "__animator__";
3
+ static readonly INTERCEPTOR_PREFIX = "__interceptor__";
4
+ static readonly LIFECYCLE_PREFIX = "__lifecycle__";
5
+ static readonly SERVICE_PREFIX = "__service__";
6
+ static readonly PAGE_URL_PREFIX = "";
7
+ static readonly OBFUSCATION_FILE_NAME = "hmrouter-obfuscation-rules.txt";
8
+ static readonly CONSUMER_FILE_NAME = "hmrouter-consumer-rules.txt";
9
+ static readonly VARIABLE_SEPARATOR = "__";
10
+ static readonly PAGE_URL = "pageUrl";
11
+ static readonly ROUTER_MAP_KEY = "routerMap";
12
+ static readonly FILE_SEPARATOR: "\\" | "/";
13
+ static readonly DELIMITER = "/";
14
+ static readonly MODULE_ROUTER_MAP_NAME = "$profile:hm_router_map";
15
+ static readonly ROUTER_MAP_NAME = "hm_router_map.json";
16
+ static readonly TEMP_ROUTER_MAP_PATH = "../../intermediates/router_map";
17
+ static readonly RAWFILE_DIR = "src/main/resources/rawfile/hm_router_map.json";
18
+ static readonly VIEW_NAME_PREFIX = "HM";
19
+ static readonly ETS_SUFFIX = ".ets";
20
+ static readonly JSON_SUFFIX = ".json";
21
+ static readonly HAP_PLUGIN_ID = "HAP_HMROUTER_PLUGIN";
22
+ static readonly HSP_PLUGIN_ID = "HSP_HMROUTER_PLUGIN";
23
+ static readonly HAR_PLUGIN_ID = "HAR_HMROUTER_PLUGIN";
24
+ static readonly HAR_MODULE_NAME = "har";
25
+ static readonly ROUTER_ANNOTATION = "HMRouter";
26
+ static readonly ANIMATOR_ANNOTATION = "HMAnimator";
27
+ static readonly INTERCEPTOR_ANNOTATION = "HMInterceptor";
28
+ static readonly LIFECYCLE_ANNOTATION = "HMLifecycle";
29
+ static readonly SERVICE_ANNOTATION = "HMService";
30
+ static readonly CONFIG_FILE_NAME = "hmrouter_config.json";
31
+ static readonly PARENT_DELIMITER = "../";
32
+ static readonly CURRENT_DELIMITER = "./";
33
+ static readonly LINE_BREAK = "\n";
34
+ static readonly KEEP_FILE_NAME = "-keep-file-name";
35
+ static readonly KEEP_PROPERTY_NAME = "-keep-property-name";
36
+ static readonly KEEP_GLOBAL_NAME = "-keep-global-name";
37
+ static readonly OH_MODULE_PATH = "oh_modules";
38
+ static readonly WARP_BUILDER = "WrapBuilder";
39
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ class HMRouterPluginConstant {
8
+ }
9
+ HMRouterPluginConstant.ANIMATOR_PREFIX = '__animator__';
10
+ HMRouterPluginConstant.INTERCEPTOR_PREFIX = '__interceptor__';
11
+ HMRouterPluginConstant.LIFECYCLE_PREFIX = '__lifecycle__';
12
+ HMRouterPluginConstant.SERVICE_PREFIX = '__service__';
13
+ HMRouterPluginConstant.PAGE_URL_PREFIX = '';
14
+ HMRouterPluginConstant.OBFUSCATION_FILE_NAME = 'hmrouter-obfuscation-rules.txt';
15
+ HMRouterPluginConstant.CONSUMER_FILE_NAME = 'hmrouter-consumer-rules.txt';
16
+ HMRouterPluginConstant.VARIABLE_SEPARATOR = '__';
17
+ HMRouterPluginConstant.PAGE_URL = 'pageUrl';
18
+ HMRouterPluginConstant.ROUTER_MAP_KEY = 'routerMap';
19
+ HMRouterPluginConstant.FILE_SEPARATOR = path_1.default.sep;
20
+ HMRouterPluginConstant.DELIMITER = '/';
21
+ HMRouterPluginConstant.MODULE_ROUTER_MAP_NAME = '$profile:hm_router_map';
22
+ HMRouterPluginConstant.ROUTER_MAP_NAME = 'hm_router_map.json';
23
+ HMRouterPluginConstant.TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map';
24
+ HMRouterPluginConstant.RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json';
25
+ HMRouterPluginConstant.VIEW_NAME_PREFIX = 'HM';
26
+ HMRouterPluginConstant.ETS_SUFFIX = '.ets';
27
+ HMRouterPluginConstant.JSON_SUFFIX = '.json';
28
+ HMRouterPluginConstant.HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN';
29
+ HMRouterPluginConstant.HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN';
30
+ HMRouterPluginConstant.HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN';
31
+ HMRouterPluginConstant.HAR_MODULE_NAME = 'har';
32
+ HMRouterPluginConstant.ROUTER_ANNOTATION = 'HMRouter';
33
+ HMRouterPluginConstant.ANIMATOR_ANNOTATION = 'HMAnimator';
34
+ HMRouterPluginConstant.INTERCEPTOR_ANNOTATION = 'HMInterceptor';
35
+ HMRouterPluginConstant.LIFECYCLE_ANNOTATION = 'HMLifecycle';
36
+ HMRouterPluginConstant.SERVICE_ANNOTATION = 'HMService';
37
+ HMRouterPluginConstant.CONFIG_FILE_NAME = 'hmrouter_config.json';
38
+ HMRouterPluginConstant.PARENT_DELIMITER = '../';
39
+ HMRouterPluginConstant.CURRENT_DELIMITER = './';
40
+ HMRouterPluginConstant.LINE_BREAK = '\n';
41
+ HMRouterPluginConstant.KEEP_FILE_NAME = '-keep-file-name';
42
+ HMRouterPluginConstant.KEEP_PROPERTY_NAME = '-keep-property-name';
43
+ HMRouterPluginConstant.KEEP_GLOBAL_NAME = '-keep-global-name';
44
+ HMRouterPluginConstant.OH_MODULE_PATH = 'oh_modules';
45
+ HMRouterPluginConstant.WARP_BUILDER = 'WrapBuilder';
46
+ exports.default = HMRouterPluginConstant;
@@ -0,0 +1,11 @@
1
+ export default class ConfigConstants {
2
+ static readonly DEFAULT_SCAN_DIR = "src/main/ets";
3
+ static readonly DEFAULT_ROUTER_MAP_DIR = "src/main/resources/base/profile";
4
+ static readonly DEFAULT_BUILD_DIR = "src/main/ets/generated";
5
+ static readonly DEFAULT_BUILD_TPL = "viewBuilder.ejs";
6
+ static readonly ROUTER_ANNOTATION = "HMRouter";
7
+ static readonly ANIMATOR_ANNOTATION = "HMAnimator";
8
+ static readonly INTERCEPTOR_ANNOTATION = "HMInterceptor";
9
+ static readonly LIFECYCLE_ANNOTATION = "HMLifecycle";
10
+ static readonly SERVICE_ANNOTATION = "HMService";
11
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ConfigConstants {
4
+ }
5
+ ConfigConstants.DEFAULT_SCAN_DIR = 'src/main/ets';
6
+ ConfigConstants.DEFAULT_ROUTER_MAP_DIR = 'src/main/resources/base/profile';
7
+ ConfigConstants.DEFAULT_BUILD_DIR = 'src/main/ets/generated';
8
+ ConfigConstants.DEFAULT_BUILD_TPL = 'viewBuilder.ejs';
9
+ ConfigConstants.ROUTER_ANNOTATION = 'HMRouter';
10
+ ConfigConstants.ANIMATOR_ANNOTATION = 'HMAnimator';
11
+ ConfigConstants.INTERCEPTOR_ANNOTATION = 'HMInterceptor';
12
+ ConfigConstants.LIFECYCLE_ANNOTATION = 'HMLifecycle';
13
+ ConfigConstants.SERVICE_ANNOTATION = 'HMService';
14
+ exports.default = ConfigConstants;
15
+ ;
@@ -0,0 +1,9 @@
1
+ export default class TaskConstants {
2
+ static readonly PRE_BUILD = "@PreBuild";
3
+ static readonly MERGE_PROFILE = "@MergeProfile";
4
+ static readonly PROCESS_ROUTER_MAP = "@ProcessRouterMap";
5
+ static readonly PROCESS_RESOURCE = "@ProcessResource";
6
+ static readonly PLUGIN_TASK = "@HMRouterPluginTask";
7
+ static readonly COPY_ROUTER_MAP_TASK = "@HMRouterCopyRouterMapToRawFileTask";
8
+ static readonly GENERATE_OBFUSCATION_TASK = "@HMRouterGenerateObfuscationFileTask";
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class TaskConstants {
4
+ }
5
+ TaskConstants.PRE_BUILD = '@PreBuild';
6
+ TaskConstants.MERGE_PROFILE = '@MergeProfile';
7
+ TaskConstants.PROCESS_ROUTER_MAP = '@ProcessRouterMap';
8
+ TaskConstants.PROCESS_RESOURCE = '@ProcessResource';
9
+ TaskConstants.PLUGIN_TASK = '@HMRouterPluginTask';
10
+ TaskConstants.COPY_ROUTER_MAP_TASK = '@HMRouterCopyRouterMapToRawFileTask';
11
+ TaskConstants.GENERATE_OBFUSCATION_TASK = '@HMRouterGenerateObfuscationFileTask';
12
+ exports.default = TaskConstants;
13
+ ;
@@ -0,0 +1,12 @@
1
+ export default class PluginStore implements IPluginStore {
2
+ private static instance;
3
+ variableCache: Map<string, Map<string, string[]>>;
4
+ projectFilePath: string;
5
+ static clear(): void;
6
+ static getInstance(): IPluginStore;
7
+ }
8
+ interface IPluginStore {
9
+ variableCache: Map<string, Map<string, string[]>>;
10
+ projectFilePath: string;
11
+ }
12
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PluginStore {
4
+ constructor() {
5
+ this.variableCache = new Map();
6
+ this.projectFilePath = '';
7
+ }
8
+ static clear() {
9
+ this.instance = null;
10
+ }
11
+ static getInstance() {
12
+ if (!this.instance) {
13
+ this.instance = new PluginStore();
14
+ }
15
+ return this.instance;
16
+ }
17
+ }
18
+ PluginStore.instance = null;
19
+ exports.default = PluginStore;
@@ -0,0 +1,4 @@
1
+ import { RouterInfo } from '../common/PluginModel';
2
+ export default class ConfusionUtil {
3
+ static buildObfuscatedStrings(routerMap: RouterInfo[]): string;
4
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const CommonConstants_1 = __importDefault(require("../constants/CommonConstants"));
7
+ class ConfusionUtil {
8
+ static buildObfuscatedStrings(routerMap) {
9
+ let srcPathArr = [...new Set(routerMap.map((routerInfo) => {
10
+ return CommonConstants_1.default.CURRENT_DELIMITER + routerInfo.pageSourceFile;
11
+ }))];
12
+ let classNameArr = [...new Set(routerMap.filter((routerInfo) => {
13
+ return routerInfo.name.includes('__');
14
+ }).map((routerInfo) => {
15
+ return routerInfo.customData.name;
16
+ }))];
17
+ let functionName = [...new Set(routerMap.filter((routerInfo) => {
18
+ return routerInfo.name.includes(CommonConstants_1.default.SERVICE_PREFIX);
19
+ }).map((routerInfo) => {
20
+ return routerInfo.customData.functionName;
21
+ }))];
22
+ return CommonConstants_1.default.KEEP_FILE_NAME + CommonConstants_1.default.LINE_BREAK +
23
+ srcPathArr.concat(CommonConstants_1.default.KEEP_PROPERTY_NAME, classNameArr, functionName)
24
+ .join(CommonConstants_1.default.LINE_BREAK);
25
+ }
26
+ }
27
+ exports.default = ConfusionUtil;
@@ -0,0 +1,11 @@
1
+ import { FileUtil } from '@ohos/hvigor';
2
+ import fs from 'fs';
3
+ export default class HMFileUtil extends FileUtil {
4
+ static rmSync(path: fs.PathLike, options?: fs.RmOptions): void;
5
+ static unlinkSync(path: fs.PathLike): void;
6
+ static readdirSync(path: fs.PathLike, options?: {
7
+ encoding: BufferEncoding | null;
8
+ withFileTypes?: false | undefined;
9
+ recursive?: boolean | undefined;
10
+ }): string[];
11
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const hvigor_1 = require("@ohos/hvigor");
7
+ const fs_1 = __importDefault(require("fs"));
8
+ class HMFileUtil extends hvigor_1.FileUtil {
9
+ static rmSync(path, options) {
10
+ return fs_1.default.rmSync(path, options);
11
+ }
12
+ static unlinkSync(path) {
13
+ return fs_1.default.unlinkSync(path);
14
+ }
15
+ static readdirSync(path, options) {
16
+ return fs_1.default.readdirSync(path, options);
17
+ }
18
+ }
19
+ exports.default = HMFileUtil;
20
+ ;
@@ -0,0 +1,4 @@
1
+ import { RouterInfo } from '../common/PluginModel';
2
+ export default class ObfuscationUtil {
3
+ static buildObfuscatedStrings(routerMap: RouterInfo[]): string;
4
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const CommonConstants_1 = __importDefault(require("../constants/CommonConstants"));
7
+ class ObfuscationUtil {
8
+ static buildObfuscatedStrings(routerMap) {
9
+ let srcPathArr = [...new Set(routerMap.map((routerInfo) => {
10
+ return CommonConstants_1.default.CURRENT_DELIMITER + routerInfo.pageSourceFile;
11
+ }))];
12
+ let classNameArr = [...new Set(routerMap.filter((routerInfo) => {
13
+ return routerInfo.name.includes('__');
14
+ }).map((routerInfo) => {
15
+ return routerInfo.customData.name;
16
+ }))];
17
+ let functionName = [...new Set(routerMap.filter((routerInfo) => {
18
+ return routerInfo.name.includes(CommonConstants_1.default.SERVICE_PREFIX);
19
+ }).map((routerInfo) => {
20
+ return routerInfo.customData.functionName;
21
+ }))];
22
+ let watchFunctionName = [...new Set(routerMap.filter((routerInfo) => {
23
+ return routerInfo.buildFunction;
24
+ }).map((routerInfo) => {
25
+ return routerInfo.buildFunction + CommonConstants_1.default.WARP_BUILDER;
26
+ }))];
27
+ return CommonConstants_1.default.KEEP_FILE_NAME + CommonConstants_1.default.LINE_BREAK +
28
+ srcPathArr.concat(CommonConstants_1.default.KEEP_PROPERTY_NAME, functionName)
29
+ .concat(CommonConstants_1.default.KEEP_GLOBAL_NAME, classNameArr, watchFunctionName)
30
+ .join(CommonConstants_1.default.LINE_BREAK);
31
+ }
32
+ }
33
+ exports.default = ObfuscationUtil;
34
+ ;
@@ -0,0 +1,3 @@
1
+ export declare class StringUtil {
2
+ static stringToHashCode(str: string): number;
3
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringUtil = void 0;
4
+ class StringUtil {
5
+ static stringToHashCode(str) {
6
+ let hash = 0;
7
+ if (str.length === 0) {
8
+ return hash;
9
+ }
10
+ for (let i = 0; i < str.length; i++) {
11
+ const char = str.charCodeAt(i);
12
+ hash = (hash << 5) - hash + char;
13
+ hash |= 0;
14
+ }
15
+ return hash;
16
+ }
17
+ }
18
+ exports.StringUtil = StringUtil;
@@ -0,0 +1,9 @@
1
+ import { Project, SourceFile } from 'ts-morph';
2
+ export declare let project: Project | null;
3
+ export declare class TsAstUtil {
4
+ static getSourceFile(filePath: string): SourceFile;
5
+ static clearProject(): void;
6
+ static parseConstantValue(sourceFile: SourceFile, variableName: string, propertyName?: string): string;
7
+ static parseCrossModuleVariable(scanDir: string): Map<string, string[]>;
8
+ private static getExportedVariables;
9
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TsAstUtil = exports.project = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ const hvigor_1 = require("@ohos/hvigor");
6
+ const Logger_1 = require("../common/Logger");
7
+ exports.project = null;
8
+ class TsAstUtil {
9
+ static getSourceFile(filePath) {
10
+ if (!hvigor_1.FileUtil.exist(filePath)) {
11
+ throw new Error(`File not found: ${filePath}`);
12
+ }
13
+ if (!exports.project) {
14
+ exports.project = new ts_morph_1.Project({
15
+ compilerOptions: { target: ts_morph_1.ScriptTarget.ES2021 }
16
+ });
17
+ }
18
+ return exports.project.addSourceFileAtPath(filePath);
19
+ }
20
+ static clearProject() {
21
+ exports.project = null;
22
+ }
23
+ static parseConstantValue(sourceFile, variableName, propertyName) {
24
+ let result;
25
+ if (propertyName) {
26
+ let classInstance = sourceFile.getClasses().find((classes) => {
27
+ return classes.getName() === variableName;
28
+ });
29
+ if (!classInstance) {
30
+ throw new Error(`Unknown class '${variableName}'`);
31
+ }
32
+ let property = classInstance.getProperties().find((properties) => {
33
+ return properties.getName() === propertyName;
34
+ });
35
+ if (!property) {
36
+ throw new Error(`Unknown property '${propertyName}'`);
37
+ }
38
+ result = property.getInitializer();
39
+ }
40
+ else {
41
+ let constant = sourceFile.getVariableDeclarations().find(declaration => {
42
+ return declaration.getName() === variableName;
43
+ });
44
+ if (!constant) {
45
+ throw new Error(`Unknown constant '${variableName}'`);
46
+ }
47
+ result = constant.getInitializer();
48
+ }
49
+ if (result.getKind() !== ts_morph_1.SyntaxKind.StringLiteral) {
50
+ Logger_1.Logger.error(Logger_1.PluginError.ERR_INVALID_STRING_VALUE, variableName);
51
+ throw new Error('Invalid constants value, only string literal is supported, variableName:' + variableName);
52
+ }
53
+ return result.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue();
54
+ }
55
+ static parseCrossModuleVariable(scanDir) {
56
+ let sourceFiles = exports.project.addSourceFilesAtPaths(`${scanDir}/**/*.ets`);
57
+ const exportMap = new Map();
58
+ for (let sourceFile of sourceFiles) {
59
+ const exportedNames = this.getExportedVariables(sourceFile);
60
+ if (exportedNames.length > 0) {
61
+ exportMap.set(sourceFile.getFilePath(), exportedNames);
62
+ }
63
+ }
64
+ return exportMap;
65
+ }
66
+ static getExportedVariables(sourceFile) {
67
+ const exportSymbols = [];
68
+ let exportKeywordNodes = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ExportKeyword);
69
+ exportKeywordNodes.forEach((node) => {
70
+ let parentNodeKind = node.getParent()?.getKind();
71
+ switch (parentNodeKind) {
72
+ case ts_morph_1.SyntaxKind.VariableStatement:
73
+ let variableStatement = node.getParent()?.asKind(ts_morph_1.SyntaxKind.VariableStatement);
74
+ let variableNames = variableStatement.getDeclarationList().getDeclarations().map((declaration) => {
75
+ return declaration.getName();
76
+ });
77
+ exportSymbols.push(...variableNames);
78
+ break;
79
+ case ts_morph_1.SyntaxKind.ClassDeclaration:
80
+ let classDeclaration = node.getParent();
81
+ let className = classDeclaration?.asKind(ts_morph_1.SyntaxKind.ClassDeclaration)?.getName();
82
+ exportSymbols.push(className);
83
+ break;
84
+ }
85
+ });
86
+ return exportSymbols;
87
+ }
88
+ }
89
+ exports.TsAstUtil = TsAstUtil;