@hadss/hmrouter-plugin 1.0.0-rc.5 → 1.0.0-rc.6
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/.mocharc.js +23 -0
- package/README.md +13 -2
- package/dist/HMRouterAnalyzer.d.ts +4 -36
- package/dist/HMRouterAnalyzer.js +203 -295
- package/dist/HMRouterHvigorPlugin.d.ts +2 -2
- package/dist/HMRouterHvigorPlugin.js +58 -65
- package/dist/HMRouterPluginConfig.d.ts +3 -0
- package/dist/HMRouterPluginConfig.js +26 -15
- package/dist/HMRouterPluginHandle.d.ts +5 -0
- package/dist/HMRouterPluginHandle.js +108 -21
- package/dist/Index.js +52 -34
- package/dist/common/PluginModel.d.ts +1 -0
- package/dist/constants/CommonConstants.d.ts +34 -0
- package/dist/constants/CommonConstants.js +41 -0
- package/dist/constants/ConfigConstants.d.ts +11 -0
- package/dist/constants/ConfigConstants.js +14 -0
- package/dist/constants/TaskConstants.d.ts +9 -0
- package/dist/constants/TaskConstants.js +12 -0
- package/dist/utils/ConfusionUtil.d.ts +4 -0
- package/dist/utils/ConfusionUtil.js +27 -0
- package/dist/utils/FileUtil.d.ts +11 -0
- package/dist/utils/FileUtil.js +19 -0
- package/dist/utils/TsAstUtil.d.ts +8 -0
- package/dist/utils/TsAstUtil.js +57 -0
- package/package.json +7 -7
- package/viewBuilder.tpl +1 -0
|
@@ -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.tpl";
|
|
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,14 @@
|
|
|
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.tpl';
|
|
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;
|
|
@@ -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_CONFUSION_TASK = "@HMRouterGenerateConfusionFileTask";
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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_CONFUSION_TASK = '@HMRouterGenerateConfusionFileTask';
|
|
12
|
+
exports.default = TaskConstants;
|
|
@@ -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,19 @@
|
|
|
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;
|
|
@@ -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,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadss/hmrouter-plugin",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.6",
|
|
4
4
|
"description": "HMRouter Compiler Plugin",
|
|
5
|
-
"main": "dist/
|
|
5
|
+
"main": "dist/Index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test:unit": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }'
|
|
8
|
-
"test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha
|
|
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",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"handlebars": "^4.7.8",
|
|
23
|
-
"
|
|
23
|
+
"ts-morph": "^23.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@ohos/hvigor": "latest",
|
|
27
27
|
"@ohos/hvigor-ohos-plugin": "latest",
|
|
28
28
|
"@types/chai": "^4.3.19",
|
|
29
|
-
"@types/mocha": "^10.0.
|
|
30
|
-
"@types/node": "^20.
|
|
29
|
+
"@types/mocha": "^10.0.8",
|
|
30
|
+
"@types/node": "^20.16.6",
|
|
31
31
|
"chai": "^4.5.0",
|
|
32
32
|
"cross-env": "^7.0.3",
|
|
33
33
|
"mocha": "^10.7.3",
|
package/viewBuilder.tpl
CHANGED
|
@@ -47,6 +47,7 @@ export struct {{componentName}}Generated {
|
|
|
47
47
|
}
|
|
48
48
|
.mode({{dialog}}?NavDestinationMode.DIALOG:NavDestinationMode.STANDARD)
|
|
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)
|