@hadss/hmrouter-plugin 1.0.0-rc.0 → 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.
- package/LICENSE +77 -77
- package/README.md +260 -37
- package/dist/HMRouterAnalyzer.d.ts +31 -0
- package/dist/HMRouterAnalyzer.js +293 -0
- package/dist/HMRouterHvigorPlugin.d.ts +15 -0
- package/dist/HMRouterHvigorPlugin.js +139 -0
- package/dist/HMRouterPluginConfig.d.ts +39 -0
- package/dist/HMRouterPluginConfig.js +73 -0
- package/dist/HMRouterPluginHandle.d.ts +23 -0
- package/dist/HMRouterPluginHandle.js +231 -0
- package/dist/Index.d.ts +4 -0
- package/dist/Index.js +124 -0
- package/dist/common/Constant.d.ts +27 -0
- package/dist/common/Constant.js +35 -0
- package/dist/common/Logger.d.ts +13 -0
- package/dist/common/Logger.js +55 -0
- package/dist/common/PluginModel.d.ts +50 -0
- package/dist/common/PluginModel.js +23 -0
- package/dist/constants/CommonConstants.d.ts +39 -0
- package/dist/constants/CommonConstants.js +46 -0
- package/dist/constants/ConfigConstants.d.ts +11 -0
- package/dist/constants/ConfigConstants.js +15 -0
- package/dist/constants/TaskConstants.d.ts +9 -0
- package/dist/constants/TaskConstants.js +13 -0
- package/dist/store/PluginStore.d.ts +12 -0
- package/dist/store/PluginStore.js +19 -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 +20 -0
- package/dist/utils/ObfuscationUtil.d.ts +4 -0
- package/dist/utils/ObfuscationUtil.js +34 -0
- package/dist/utils/StringUtil.d.ts +3 -0
- package/dist/utils/StringUtil.js +18 -0
- package/dist/utils/TsAstUtil.d.ts +9 -0
- package/dist/utils/TsAstUtil.js +89 -0
- package/package.json +46 -27
- package/viewBuilder.ejs +103 -0
- package/lib/HMRouterAnalyzer.js +0 -223
- package/lib/HMRouterHvigorPlugin.js +0 -175
- package/lib/HMRouterPluginConfig.js +0 -31
- package/lib/Index.js +0 -201
- package/lib/PluginModel.js +0 -33
- package/src/HMRouterAnalyzer.ts +0 -253
- package/src/HMRouterHvigorPlugin.ts +0 -246
- package/src/HMRouterPluginConfig.ts +0 -44
- package/src/Index.ts +0 -218
- package/src/PluginModel.ts +0 -50
- package/tsconfig.json +0 -14
- package/viewBuilder.tpl +0 -97
|
@@ -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,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,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,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;
|
package/package.json
CHANGED
|
@@ -1,27 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hadss/hmrouter-plugin",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
4
|
-
"description": "HMRouter Compiler Plugin",
|
|
5
|
-
"main": "
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@hadss/hmrouter-plugin",
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
|
+
"description": "HMRouter Compiler Plugin",
|
|
5
|
+
"main": "dist/Index.js",
|
|
6
|
+
"scripts": {
|
|
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
|
+
"dev": "tsc && node dist/index.js",
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"release": "tsc && npm publish --access public"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"hmrouter",
|
|
15
|
+
"harmonyos",
|
|
16
|
+
"openharmony"
|
|
17
|
+
],
|
|
18
|
+
"author": "DTSE",
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"ejs": "^3.1.10",
|
|
22
|
+
"micromatch": "^4.0.8",
|
|
23
|
+
"ts-morph": "^23.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@ohos/hvigor": "^5.8.9",
|
|
27
|
+
"@ohos/hvigor-ohos-plugin": "^5.8.9",
|
|
28
|
+
"@types/chai": "^4.3.19",
|
|
29
|
+
"@types/ejs": "^3.1.5",
|
|
30
|
+
"@types/micromatch": "^4.0.9",
|
|
31
|
+
"@types/mocha": "^10.0.8",
|
|
32
|
+
"@types/node": "^20.16.6",
|
|
33
|
+
"chai": "^4.5.0",
|
|
34
|
+
"cross-env": "^7.0.3",
|
|
35
|
+
"mocha": "^10.7.3",
|
|
36
|
+
"ts-node": "^10.9.2"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"registry": "https://registry.npmjs.org"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://gitee.com/hadss/hmrouter",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://gitee.com/hadss/hmrouter"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/viewBuilder.ejs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
// auto-generated <%= componentName %>Builder.ets by HMRouter
|
|
17
|
+
import <%if(isDefaultExport) {%> <%= componentName %> <% } else {%> { <%= componentName %> } <% } %> from '<%= importPath %>'
|
|
18
|
+
import { TemplateService, TranslateOption, ScaleOption, OpacityOption, HMRouterMgr } from '@hadss/hmrouter'
|
|
19
|
+
|
|
20
|
+
@Builder
|
|
21
|
+
export function <%= componentName %>Builder(name: string, param: Object) {
|
|
22
|
+
<%= componentName %>Generated()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const <%= componentName %>BuilderWrapBuilder = wrapBuilder(<%= componentName %>Builder)
|
|
26
|
+
|
|
27
|
+
@Component
|
|
28
|
+
export struct <%= componentName %>Generated {
|
|
29
|
+
@State translateOption: TranslateOption = new TranslateOption()
|
|
30
|
+
@State scaleOption: ScaleOption = new ScaleOption()
|
|
31
|
+
@State opacityOption: OpacityOption = new OpacityOption()
|
|
32
|
+
private pageUrl: string = ''
|
|
33
|
+
private ndId: string = ''
|
|
34
|
+
private navigationId: string = ''
|
|
35
|
+
|
|
36
|
+
aboutToAppear(): void {
|
|
37
|
+
this.navigationId = this.queryNavigationInfo()!.navigationId;
|
|
38
|
+
const allPathName = HMRouterMgr.getPathStack(this.navigationId)?.getAllPathName();
|
|
39
|
+
this.pageUrl = allPathName ? allPathName[allPathName.length - 1] : '';
|
|
40
|
+
TemplateService.aboutToAppear(this.navigationId, this.pageUrl, <%= dialog %>,
|
|
41
|
+
this.translateOption, this.scaleOption, this.opacityOption)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
aboutToDisappear(): void {
|
|
45
|
+
TemplateService.aboutToDisappear(this.navigationId, this.pageUrl, this.ndId)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
build() {
|
|
49
|
+
NavDestination() {
|
|
50
|
+
<%= componentName %>()
|
|
51
|
+
}
|
|
52
|
+
<% if(dialog){ %>.mode(NavDestinationMode.DIALOG)<% } %>
|
|
53
|
+
.hideTitleBar(true)
|
|
54
|
+
.gesture(PanGesture()
|
|
55
|
+
.onActionStart((event: GestureEvent) => {
|
|
56
|
+
TemplateService.interactiveStart(this.navigationId, this.ndId, event)
|
|
57
|
+
})
|
|
58
|
+
.onActionUpdate((event: GestureEvent) =>{
|
|
59
|
+
TemplateService.interactiveProgress(this.navigationId, this.ndId, event)
|
|
60
|
+
})
|
|
61
|
+
.onActionEnd((event: GestureEvent) =>{
|
|
62
|
+
TemplateService.interactiveFinish(this.navigationId, this.ndId, event)
|
|
63
|
+
})
|
|
64
|
+
.onActionCancel(() =>{
|
|
65
|
+
TemplateService.interactiveCancel(this.navigationId, this.ndId)
|
|
66
|
+
})
|
|
67
|
+
)
|
|
68
|
+
.translate(this.translateOption)
|
|
69
|
+
.scale(this.scaleOption)
|
|
70
|
+
.opacity(this.opacityOption.opacity)
|
|
71
|
+
.onAppear(() => {
|
|
72
|
+
TemplateService.onAppear(this.navigationId, this.pageUrl, this.ndId)
|
|
73
|
+
})
|
|
74
|
+
.onDisAppear(() => {
|
|
75
|
+
TemplateService.onDisAppear(this.navigationId, this.pageUrl, this.ndId)
|
|
76
|
+
})
|
|
77
|
+
.onShown(() => {
|
|
78
|
+
TemplateService.onShown(this.navigationId, this.pageUrl, this.ndId)
|
|
79
|
+
})
|
|
80
|
+
.onHidden(() => {
|
|
81
|
+
TemplateService.onHidden(this.navigationId, this.pageUrl, this.ndId)
|
|
82
|
+
})
|
|
83
|
+
.onWillAppear(() => {
|
|
84
|
+
TemplateService.onWillAppear(this.navigationId, this.pageUrl)
|
|
85
|
+
})
|
|
86
|
+
.onWillDisappear(() => {
|
|
87
|
+
TemplateService.onWillDisappear(this.navigationId, this.pageUrl, this.ndId)
|
|
88
|
+
})
|
|
89
|
+
.onWillShow(() => {
|
|
90
|
+
TemplateService.onWillShow(this.navigationId, this.pageUrl, this.ndId)
|
|
91
|
+
})
|
|
92
|
+
.onWillHide(() => {
|
|
93
|
+
TemplateService.onWillHide(this.navigationId, this.pageUrl, this.ndId)
|
|
94
|
+
})
|
|
95
|
+
.onReady((navContext: NavDestinationContext) => {
|
|
96
|
+
this.ndId = navContext.navDestinationId!
|
|
97
|
+
TemplateService.onReady(this.navigationId, this.pageUrl, navContext)
|
|
98
|
+
})
|
|
99
|
+
.onBackPressed(() => {
|
|
100
|
+
return TemplateService.onBackPressed(this.navigationId, this.pageUrl, this.ndId)
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
}
|