@hadss/hmrouter-plugin 1.0.0-rc.5 → 1.0.0-rc.9

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/dist/Index.js CHANGED
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.hapPlugin = hapPlugin;
7
7
  exports.hspPlugin = hspPlugin;
8
8
  exports.harPlugin = harPlugin;
9
- const fs_1 = __importDefault(require("fs"));
10
9
  const hvigor_1 = require("@ohos/hvigor");
11
10
  const hvigor_ohos_plugin_1 = require("@ohos/hvigor-ohos-plugin");
12
- const HMRouterPluginHandle_1 = require("./HMRouterPluginHandle");
13
- const Constant_1 = require("./common/Constant");
14
11
  const Logger_1 = require("./common/Logger");
12
+ const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
13
+ const TsAstUtil_1 = require("./utils/TsAstUtil");
14
+ const FileUtil_1 = __importDefault(require("./utils/FileUtil"));
15
+ const HMRouterPluginHandle_1 = require("./HMRouterPluginHandle");
15
16
  class HMRouterPluginMgr {
16
17
  constructor() {
17
18
  this.hmRouterPluginSet = new Set();
@@ -21,8 +22,21 @@ class HMRouterPluginMgr {
21
22
  });
22
23
  });
23
24
  hvigor_1.hvigor.buildFinished(() => {
24
- this.deleteGeneratorFile();
25
+ Logger_1.Logger.info('buildFinished deleteFile exec...');
26
+ this.hmRouterPluginSet.forEach((pluginHandle) => {
27
+ if (pluginHandle.config.saveGeneratedFile) {
28
+ Logger_1.Logger.info(pluginHandle.config.moduleName + ' saveGeneratedFile is true, skip deleting');
29
+ return;
30
+ }
31
+ this.deleteRouterMapFile(pluginHandle);
32
+ this.deleteRawFile(pluginHandle);
33
+ this.deleteGeneratorFile(pluginHandle);
34
+ if (pluginHandle.config.autoObfuscation) {
35
+ this.deleteObfuscationFile(pluginHandle);
36
+ }
37
+ });
25
38
  HMRouterPluginMgrInstance = null;
39
+ TsAstUtil_1.TsAstUtil.clearProject();
26
40
  });
27
41
  }
28
42
  registerHMRouterPlugin(node, pluginId) {
@@ -33,69 +47,73 @@ class HMRouterPluginMgr {
33
47
  }
34
48
  let pluginHandle = new HMRouterPluginHandle_1.HMRouterPluginHandle(node, moduleContext);
35
49
  if (pluginId === hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN) {
36
- let packageJson = hvigor_1.FileUtil.readJson5(hvigor_1.FileUtil.pathResolve(node.getNodePath(), 'oh-package.json5'));
50
+ let packageJson = FileUtil_1.default.readJson5(FileUtil_1.default.pathResolve(node.getNodePath(), 'oh-package.json5'));
37
51
  pluginHandle.config.moduleName = packageJson.name;
38
52
  }
39
53
  this.hmRouterPluginSet.add(pluginHandle);
40
54
  }
41
- deleteGeneratorFile() {
42
- Logger_1.Logger.info('deleteGeneratorFile exec...');
43
- for (let hmRouterPlugin of this.hmRouterPluginSet) {
44
- if (hmRouterPlugin.config.saveGeneratedFile) {
45
- Logger_1.Logger.info(hmRouterPlugin.config.moduleName + ' saveGeneratedFile is true, skip deleting');
46
- continue;
47
- }
48
- let routerMapDirPath = hmRouterPlugin.config.getRouterMapDir();
49
- if (hvigor_1.FileUtil.exist(routerMapDirPath)) {
50
- fs_1.default.unlinkSync(routerMapDirPath);
51
- Logger_1.Logger.info(routerMapDirPath + ' delete hm_router_map.json');
52
- }
53
- let builderDirPath = hmRouterPlugin.config.getBuilderDir();
54
- if (hvigor_1.FileUtil.exist(builderDirPath)) {
55
- fs_1.default.rmSync(builderDirPath, {
56
- recursive: true,
57
- });
58
- Logger_1.Logger.info(hmRouterPlugin.config.modulePath + ' delete builder dir');
59
- }
60
- let rawFilePath = hmRouterPlugin.config.getRawFilePath();
61
- if (hvigor_1.FileUtil.exist(rawFilePath)) {
62
- fs_1.default.unlinkSync(rawFilePath);
63
- Logger_1.Logger.info(hmRouterPlugin.config.modulePath + ' delete rawfile hm_router_map.json');
64
- }
55
+ deleteGeneratorFile(pluginHandle) {
56
+ let builderDirPath = pluginHandle.config.getBuilderDir();
57
+ if (FileUtil_1.default.exist(builderDirPath)) {
58
+ FileUtil_1.default.rmSync(builderDirPath, {
59
+ recursive: true
60
+ });
61
+ Logger_1.Logger.info(pluginHandle.config.modulePath + ' delete builder dir');
62
+ }
63
+ }
64
+ deleteRouterMapFile(pluginHandle) {
65
+ let routerMapDirPath = pluginHandle.config.getRouterMapDir();
66
+ if (FileUtil_1.default.exist(routerMapDirPath)) {
67
+ FileUtil_1.default.unlinkSync(routerMapDirPath);
68
+ Logger_1.Logger.info(routerMapDirPath + ' delete hm_router_map.json');
69
+ }
70
+ }
71
+ deleteRawFile(pluginHandle) {
72
+ let rawFilePath = pluginHandle.config.getRawFilePath();
73
+ if (FileUtil_1.default.exist(rawFilePath)) {
74
+ FileUtil_1.default.unlinkSync(rawFilePath);
75
+ Logger_1.Logger.info(pluginHandle.config.modulePath + ' delete rawfile hm_router_map.json');
76
+ }
77
+ }
78
+ deleteObfuscationFile(pluginHandle) {
79
+ let obfuscationFilePath = pluginHandle.config.getObfuscationFilePath();
80
+ if (FileUtil_1.default.exist(obfuscationFilePath)) {
81
+ FileUtil_1.default.unlinkSync(obfuscationFilePath);
82
+ Logger_1.Logger.info(pluginHandle.config.modulePath + ' delete obfuscation hmrouter_obfuscation_rules.txt');
65
83
  }
66
84
  }
67
85
  }
68
86
  let HMRouterPluginMgrInstance = null;
69
87
  function hapPlugin() {
70
88
  return {
71
- pluginId: Constant_1.HMRouterPluginConstant.HAP_PLUGIN_ID,
89
+ pluginId: CommonConstants_1.default.HAP_PLUGIN_ID,
72
90
  apply(node) {
73
91
  if (!HMRouterPluginMgrInstance) {
74
92
  HMRouterPluginMgrInstance = new HMRouterPluginMgr();
75
93
  }
76
94
  HMRouterPluginMgrInstance.registerHMRouterPlugin(node, hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN);
77
- },
95
+ }
78
96
  };
79
97
  }
80
98
  function hspPlugin() {
81
99
  return {
82
- pluginId: Constant_1.HMRouterPluginConstant.HSP_PLUGIN_ID,
100
+ pluginId: CommonConstants_1.default.HSP_PLUGIN_ID,
83
101
  apply(node) {
84
102
  if (!HMRouterPluginMgrInstance) {
85
103
  HMRouterPluginMgrInstance = new HMRouterPluginMgr();
86
104
  }
87
105
  HMRouterPluginMgrInstance.registerHMRouterPlugin(node, hvigor_ohos_plugin_1.OhosPluginId.OHOS_HSP_PLUGIN);
88
- },
106
+ }
89
107
  };
90
108
  }
91
109
  function harPlugin() {
92
110
  return {
93
- pluginId: Constant_1.HMRouterPluginConstant.HAR_PLUGIN_ID,
111
+ pluginId: CommonConstants_1.default.HAR_PLUGIN_ID,
94
112
  apply(node) {
95
113
  if (!HMRouterPluginMgrInstance) {
96
114
  HMRouterPluginMgrInstance = new HMRouterPluginMgr();
97
115
  }
98
116
  HMRouterPluginMgrInstance.registerHMRouterPlugin(node, hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAR_PLUGIN);
99
- },
117
+ }
100
118
  };
101
119
  }
@@ -1,6 +1,7 @@
1
1
  export declare class Logger {
2
2
  static error(format: string, ...args: string[]): void;
3
3
  static info(msg: string, ...args: unknown[]): void;
4
+ static warn(msg: string, ...args: unknown[]): void;
4
5
  }
5
6
  export declare enum PluginError {
6
7
  ERR_DUPLICATE_NAME = "ERR_DUPLICATE_NAME",
@@ -14,6 +14,9 @@ class Logger {
14
14
  static info(msg, ...args) {
15
15
  hvigor_1.HvigorLogger.getLogger().info('[HMRouterPlugin] ' + msg, ...args);
16
16
  }
17
+ static warn(msg, ...args) {
18
+ hvigor_1.HvigorLogger.getLogger().warn('[HMRouterPlugin] ' + msg, ...args);
19
+ }
17
20
  }
18
21
  exports.Logger = Logger;
19
22
  var PluginError;
@@ -28,25 +31,25 @@ var PluginError;
28
31
  const DEFINED_ERROR = new Map();
29
32
  DEFINED_ERROR.set(PluginError.ERR_DUPLICATE_NAME, {
30
33
  errorCode: 40000001,
31
- errorMsg: '重复的pageUrl、拦截器、生命周期、动画、服务 - %s'
34
+ errorMsg: 'Duplicate pageUrl/interceptor/service/animator/lifecycle - %s'
32
35
  });
33
36
  DEFINED_ERROR.set(PluginError.ERR_WRONG_DECORATION, {
34
37
  errorCode: 40000002,
35
- errorMsg: '@HMRouter修饰的组件不能包含NavDestination - %s'
38
+ errorMsg: 'Struct with @HMRouter annotation could not contain NavDestination component - %s'
36
39
  });
37
40
  DEFINED_ERROR.set(PluginError.ERR_REPEAT_ANNOTATION, {
38
41
  errorCode: 40000003,
39
- errorMsg: '文件 %s 中存在多个HMRouter注解'
42
+ errorMsg: 'File: %s contains multiple annotations'
40
43
  });
41
44
  DEFINED_ERROR.set(PluginError.ERR_ERROR_CONFIG, {
42
45
  errorCode: 40000004,
43
- errorMsg: 'moduleContext is null 请检查插件的hvigorfile配置 - %s'
46
+ errorMsg: 'moduleContext is null, Please check hvigorfile.ts file in module directory - %s'
44
47
  });
45
48
  DEFINED_ERROR.set(PluginError.ERR_NOT_EMPTY_STRING, {
46
49
  errorCode: 40000005,
47
- errorMsg: '%s 常量值不能为空字符串 - %s'
50
+ errorMsg: '%s constant value cannot be empty string - %s'
48
51
  });
49
52
  DEFINED_ERROR.set(PluginError.ERR_INVALID_STRING_VALUE, {
50
53
  errorCode: 40000006,
51
- errorMsg: '%s 无效的字符串常量值'
54
+ errorMsg: 'invalid string value: %s'
52
55
  });
@@ -3,6 +3,7 @@ export interface BaseAnalyzeResult {
3
3
  name?: string;
4
4
  module?: string;
5
5
  annotation?: string;
6
+ pageSourceFile?: string;
6
7
  }
7
8
  export interface HMRouterResult extends BaseAnalyzeResult {
8
9
  pageUrl?: any;
@@ -0,0 +1,34 @@
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 VARIABLE_SEPARATOR = "__";
9
+ static readonly PAGE_URL = "pageUrl";
10
+ static readonly ROUTER_MAP_KEY = "routerMap";
11
+ static readonly FILE_SEPARATOR: "\\" | "/";
12
+ static readonly DELIMITER = "/";
13
+ static readonly MODULE_ROUTER_MAP_NAME = "$profile:hm_router_map";
14
+ static readonly ROUTER_MAP_NAME = "hm_router_map.json";
15
+ static readonly TEMP_ROUTER_MAP_PATH = "../../intermediates/router_map";
16
+ static readonly RAWFILE_DIR = "src/main/resources/rawfile/hm_router_map.json";
17
+ static readonly VIEW_NAME_PREFIX = "HM";
18
+ static readonly VIEW_NAME_SUFFIX = ".ets";
19
+ static readonly JSON_SUFFIX = ".json";
20
+ static readonly HAP_PLUGIN_ID = "HAP_HMROUTER_PLUGIN";
21
+ static readonly HSP_PLUGIN_ID = "HSP_HMROUTER_PLUGIN";
22
+ static readonly HAR_PLUGIN_ID = "HAR_HMROUTER_PLUGIN";
23
+ static readonly ROUTER_ANNOTATION = "HMRouter";
24
+ static readonly ANIMATOR_ANNOTATION = "HMAnimator";
25
+ static readonly INTERCEPTOR_ANNOTATION = "HMInterceptor";
26
+ static readonly LIFECYCLE_ANNOTATION = "HMLifecycle";
27
+ static readonly SERVICE_ANNOTATION = "HMService";
28
+ static readonly CONFIG_FILE_NAME = "hmrouter_config.json";
29
+ static readonly PARENT_DELIMITER = "../";
30
+ static readonly CURRENT_DELIMITER = "./";
31
+ static readonly LINE_BREAK = "\n";
32
+ static readonly KEEP_FILE_NAME = "-keep-file-name";
33
+ static readonly KEEP_PROPERTY_NAME = "-keep-property-name";
34
+ }
@@ -0,0 +1,41 @@
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.VARIABLE_SEPARATOR = '__';
16
+ HMRouterPluginConstant.PAGE_URL = 'pageUrl';
17
+ HMRouterPluginConstant.ROUTER_MAP_KEY = 'routerMap';
18
+ HMRouterPluginConstant.FILE_SEPARATOR = path_1.default.sep;
19
+ HMRouterPluginConstant.DELIMITER = '/';
20
+ HMRouterPluginConstant.MODULE_ROUTER_MAP_NAME = '$profile:hm_router_map';
21
+ HMRouterPluginConstant.ROUTER_MAP_NAME = 'hm_router_map.json';
22
+ HMRouterPluginConstant.TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map';
23
+ HMRouterPluginConstant.RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json';
24
+ HMRouterPluginConstant.VIEW_NAME_PREFIX = 'HM';
25
+ HMRouterPluginConstant.VIEW_NAME_SUFFIX = '.ets';
26
+ HMRouterPluginConstant.JSON_SUFFIX = '.json';
27
+ HMRouterPluginConstant.HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN';
28
+ HMRouterPluginConstant.HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN';
29
+ HMRouterPluginConstant.HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN';
30
+ HMRouterPluginConstant.ROUTER_ANNOTATION = 'HMRouter';
31
+ HMRouterPluginConstant.ANIMATOR_ANNOTATION = 'HMAnimator';
32
+ HMRouterPluginConstant.INTERCEPTOR_ANNOTATION = 'HMInterceptor';
33
+ HMRouterPluginConstant.LIFECYCLE_ANNOTATION = 'HMLifecycle';
34
+ HMRouterPluginConstant.SERVICE_ANNOTATION = 'HMService';
35
+ HMRouterPluginConstant.CONFIG_FILE_NAME = 'hmrouter_config.json';
36
+ HMRouterPluginConstant.PARENT_DELIMITER = '../';
37
+ HMRouterPluginConstant.CURRENT_DELIMITER = './';
38
+ HMRouterPluginConstant.LINE_BREAK = '\n';
39
+ HMRouterPluginConstant.KEEP_FILE_NAME = '-keep-file-name';
40
+ HMRouterPluginConstant.KEEP_PROPERTY_NAME = '-keep-property-name';
41
+ 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,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,28 @@
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
+ 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 = ObfuscationUtil;
28
+ ;
@@ -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,8 @@
1
+ import { Project, SourceFile } from 'ts-morph';
2
+ export declare let project: Project | null;
3
+ export declare const importVariableCache: Map<string, string>;
4
+ export declare class TsAstUtil {
5
+ static getSourceFile(filePath: string): SourceFile | null;
6
+ static clearProject(): void;
7
+ static parseConstantValue(sourceFile: SourceFile, variableName: string, propertyName?: string): string;
8
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TsAstUtil = exports.importVariableCache = 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
+ exports.importVariableCache = new Map();
9
+ class TsAstUtil {
10
+ static getSourceFile(filePath) {
11
+ if (!hvigor_1.FileUtil.exist(filePath)) {
12
+ return null;
13
+ }
14
+ if (!exports.project) {
15
+ exports.project = new ts_morph_1.Project({
16
+ compilerOptions: { target: ts_morph_1.ScriptTarget.ES2021 }
17
+ });
18
+ }
19
+ return exports.project.addSourceFileAtPath(filePath);
20
+ }
21
+ static clearProject() {
22
+ exports.project = null;
23
+ }
24
+ static parseConstantValue(sourceFile, variableName, propertyName) {
25
+ let result;
26
+ if (propertyName) {
27
+ let classInstance = sourceFile.getClasses().filter((classes) => {
28
+ return classes.getName() === variableName;
29
+ });
30
+ if (classInstance.length === 0) {
31
+ throw new Error(`Unknown class '${variableName}'`);
32
+ }
33
+ let property = classInstance[0].getProperties().filter((properties) => {
34
+ return properties.getName() === propertyName;
35
+ });
36
+ if (property.length === 0) {
37
+ throw new Error(`Unknown property '${propertyName}'`);
38
+ }
39
+ result = property[0].getInitializer();
40
+ }
41
+ else {
42
+ let constant = sourceFile.getVariableDeclarations().filter(declaration => {
43
+ return declaration.getName() === variableName;
44
+ })[0];
45
+ if (!constant) {
46
+ throw new Error(`Unknown constant '${variableName}'`);
47
+ }
48
+ result = constant.getInitializer();
49
+ }
50
+ if (result.getKind() !== ts_morph_1.SyntaxKind.StringLiteral) {
51
+ Logger_1.Logger.error(Logger_1.PluginError.ERR_INVALID_STRING_VALUE, variableName);
52
+ throw new Error('Invalid constant value');
53
+ }
54
+ return result.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue();
55
+ }
56
+ }
57
+ exports.TsAstUtil = TsAstUtil;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@hadss/hmrouter-plugin",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.9",
4
4
  "description": "HMRouter Compiler Plugin",
5
- "main": "dist/index.js",
5
+ "main": "dist/Index.js",
6
6
  "scripts": {
7
- "test:unit": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha 'tests/**/Unit.test.ts'",
8
- "test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha 'tests/**/*.test.ts'",
7
+ "test:unit": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' TEST_ENV='unit' mocha",
8
+ "test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha",
9
9
  "dev": "tsc && node dist/index.js",
10
10
  "build": "tsc",
11
11
  "package": "tsc && npm pack && mv hadss*.tgz ../libs",
12
- "publish": "tsc && npm publish --access public"
12
+ "release": "tsc && npm publish --access public"
13
13
  },
14
14
  "keywords": [
15
15
  "hmrouter",
@@ -19,15 +19,18 @@
19
19
  "author": "DTSE",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "handlebars": "^4.7.8",
23
- "typescript": "^5.5.3"
22
+ "ejs": "^3.1.10",
23
+ "micromatch": "^4.0.8",
24
+ "ts-morph": "^23.0.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@ohos/hvigor": "latest",
27
- "@ohos/hvigor-ohos-plugin": "latest",
27
+ "@ohos/hvigor": "5.7.4",
28
+ "@ohos/hvigor-ohos-plugin": "5.7.4",
28
29
  "@types/chai": "^4.3.19",
29
- "@types/mocha": "^10.0.7",
30
- "@types/node": "^20.14.10",
30
+ "@types/ejs": "^3.1.5",
31
+ "@types/micromatch": "^4.0.9",
32
+ "@types/mocha": "^10.0.8",
33
+ "@types/node": "^20.16.6",
31
34
  "chai": "^4.5.0",
32
35
  "cross-env": "^7.0.3",
33
36
  "mocha": "^10.7.3",
@@ -4,7 +4,7 @@
4
4
  * you may not use this file except in compliance with the License.
5
5
  * You may obtain a copy of the License at
6
6
  *
7
- * http://www.apache.org/licenses/LICENSE-2.0
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
8
  *
9
9
  * Unless required by applicable law or agreed to in writing, software
10
10
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,27 +13,27 @@
13
13
  * limitations under the License.
14
14
  */
15
15
 
16
- // auto-generated {{componentName}}Builder.ets by HMRouter
17
- import { {{componentName}} } from '{{importPath}}'
16
+ // auto-generated <%= componentName %>Builder.ets by HMRouter
17
+ import { <%= componentName %> } from '<%= importPath %>'
18
18
  import { TemplateService, TranslateOption, ScaleOption, OpacityOption } from '@hadss/hmrouter'
19
19
 
20
20
  @Builder
21
- export function {{componentName}}Builder(name: string, param: Object) {
22
- {{componentName}}Generated()
21
+ export function <%= componentName %>Builder(name: string, param: Object) {
22
+ <%= componentName %>Generated()
23
23
  }
24
24
 
25
25
  @Component
26
- export struct {{componentName}}Generated {
26
+ export struct <%= componentName %>Generated {
27
27
  @State translateOption: TranslateOption = new TranslateOption()
28
28
  @State scaleOption: ScaleOption = new ScaleOption()
29
29
  @State opacityOption: OpacityOption = new OpacityOption()
30
- private pageUrl: string = '{{pageUrl}}'
30
+ private pageUrl: string = '<%= pageUrl %>'
31
31
  private ndId: string = ''
32
32
  private navigationId: string = ''
33
33
 
34
34
  aboutToAppear(): void {
35
35
  this.navigationId = this.queryNavigationInfo()!.navigationId;
36
- TemplateService.aboutToAppear(this.navigationId, this.pageUrl, {{ dialog }},
36
+ TemplateService.aboutToAppear(this.navigationId, this.pageUrl, <%= dialog %>,
37
37
  this.translateOption, this.scaleOption, this.opacityOption)
38
38
  }
39
39
 
@@ -43,10 +43,11 @@ export struct {{componentName}}Generated {
43
43
 
44
44
  build() {
45
45
  NavDestination() {
46
- {{componentName}}()
46
+ <%= componentName %>()
47
47
  }
48
- .mode({{dialog}}?NavDestinationMode.DIALOG:NavDestinationMode.STANDARD)
48
+ <% if(dialog){ %>.mode(NavDestinationMode.DIALOG)<% } %>
49
49
  .hideTitleBar(true)
50
+ .hitTestBehavior(HitTestMode.Transparent)
50
51
  .gesture(PanGesture()
51
52
  .onActionStart((event: GestureEvent) => {
52
53
  TemplateService.interactiveStart(this.navigationId, this.ndId, event)