@atomicservice/ascf-toolkit-hvigor-plugin 1.0.2 → 1.0.3-beta.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomicservice/ascf-toolkit-hvigor-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3-beta.6",
|
|
4
4
|
"title": "ASCF toolkit hvigor plugin for atomicservice",
|
|
5
5
|
"description": "ASCF toolkit hvigor plugin for atomicservice",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"@ohos/hvigor-ohos-plugin": "5.8.9"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@atomicservice/ascf-toolkit": "1.0.
|
|
14
|
+
"@atomicservice/ascf-toolkit": "1.0.3-beta.6"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type DeepPartial<T> = {
|
|
2
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
function deepMerge<T extends object>(target: T, source?: DeepPartial<T>): T {
|
|
6
|
+
if (!source) {
|
|
7
|
+
return target;
|
|
8
|
+
}
|
|
9
|
+
for (const key of Object.keys(source) as Array<keyof T>) {
|
|
10
|
+
const sourceValue = source[key];
|
|
11
|
+
const targetValue = target[key];
|
|
12
|
+
|
|
13
|
+
if (isObject(sourceValue) && key in target && isObject(targetValue)) {
|
|
14
|
+
deepMerge(targetValue as Object, sourceValue as DeepPartial<typeof targetValue>);
|
|
15
|
+
} else {
|
|
16
|
+
target[key] = sourceValue as T[keyof T];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isObject(target: any) {
|
|
23
|
+
return Object.prototype.toString.call(target) === '[object Object]';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { deepMerge };
|
package/src/config.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"ascfHspUrl": "https://h5hosting-drcn.dbankcdn.cn/cch5/wallet/ascf-cn/ascfHsp.html?auto=1"
|
|
2
|
+
"ascfHspUrl": "https://h5hosting-drcn.dbankcdn.cn/cch5/wallet/ascf-cn/ascfHsp.html?auto=1",
|
|
3
|
+
"ascfRuntimeHspUrl": "https://h5hosting-drcn.dbankcdn.cn/cch5/wallet/ascf-cn/ascfRuntimeHsp.html?auto=1"
|
|
3
4
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { OhosAppContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin';
|
|
2
2
|
import { Property } from '@ohos/hvigor-ohos-plugin/src/sdk/lib/property-get';
|
|
3
3
|
import { PropertyConst } from '@ohos/hvigor-ohos-plugin/src/const/property-const';
|
|
4
|
-
import { hvigor, HvigorLogger, HvigorNode, HvigorPlugin } from '@ohos/hvigor';
|
|
4
|
+
import { hvigor, HvigorLogger, HvigorNode, HvigorPlugin, Level } from '@ohos/hvigor';
|
|
5
5
|
import ascf from '@atomicservice/ascf-toolkit';
|
|
6
6
|
import { exec } from 'child_process';
|
|
7
7
|
import path from 'path';
|
|
8
|
+
import fs from 'fs';
|
|
8
9
|
import os from 'os';
|
|
10
|
+
import { LogLevel } from '../common/common-enum';
|
|
11
|
+
import { deepMerge } from '../common/common-utils';
|
|
9
12
|
|
|
10
13
|
import { doModifyShareInfoPlugin } from './modifyShareInfoPlugin';
|
|
11
14
|
import { doInstallAscfHspPlugin } from './installAscfHspPlugin';
|
|
@@ -13,23 +16,29 @@ import { doInstallAscfHspPlugin } from './installAscfHspPlugin';
|
|
|
13
16
|
const logger = HvigorLogger.getLogger('ascfPlugin');
|
|
14
17
|
|
|
15
18
|
export interface AscfPluginOptions {
|
|
16
|
-
fixSharedHsp:
|
|
17
|
-
installAscfHsp:
|
|
18
|
-
debug:
|
|
19
|
+
fixSharedHsp: boolean,
|
|
20
|
+
installAscfHsp: boolean,
|
|
21
|
+
debug: boolean,
|
|
22
|
+
logging?: LogLevel,
|
|
23
|
+
compilerOptions: {
|
|
24
|
+
swc: boolean,
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
const DEFAULT_OPTIONS: AscfPluginOptions = {
|
|
22
29
|
fixSharedHsp: true,
|
|
23
30
|
installAscfHsp: true,
|
|
24
31
|
debug: true,
|
|
32
|
+
compilerOptions: {
|
|
33
|
+
swc: false,
|
|
34
|
+
}
|
|
25
35
|
};
|
|
26
36
|
|
|
27
|
-
export default function ascfToolkitHvigorPlugin(options
|
|
37
|
+
export default function ascfToolkitHvigorPlugin(options?: AscfPluginOptions): HvigorPlugin {
|
|
28
38
|
return {
|
|
29
39
|
pluginId: 'ascfToolkitHvigorPlugin',
|
|
30
40
|
apply(node: HvigorNode) {
|
|
31
|
-
const opts =
|
|
32
|
-
|
|
41
|
+
const opts = deepMerge(DEFAULT_OPTIONS, options);
|
|
33
42
|
hvigor.nodesEvaluated(async () => {
|
|
34
43
|
await execPlugin(opts, node);
|
|
35
44
|
|
|
@@ -47,13 +56,20 @@ export default function ascfToolkitHvigorPlugin(options: AscfPluginOptions): Hvi
|
|
|
47
56
|
const buildMode = appContext.getBuildMode();
|
|
48
57
|
const nodeExe = getNodeExe();
|
|
49
58
|
const ascfScript = getAscfScript();
|
|
50
|
-
let cmd =
|
|
59
|
+
let cmd = `${nodeExe} ${ascfScript} compile -c ${buildMode === 'debug' ? '-m' : ''} ${appContext.getProjectPath()}`;
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
const hvigorLevelStr = (logger.getLevel() as Level).levelStr.toLowerCase();
|
|
62
|
+
if (opts.debug && hvigorLevelStr === LogLevel.DEBUG) {
|
|
53
63
|
cmd += ' --debug';
|
|
54
64
|
}
|
|
65
|
+
if (opts.compilerOptions.swc) {
|
|
66
|
+
cmd += ' --swc';
|
|
67
|
+
}
|
|
55
68
|
|
|
56
|
-
|
|
69
|
+
const logLevel = (opts.logging ? opts.logging : hvigorLevelStr).toLowerCase();
|
|
70
|
+
cmd += ` --logging=${logLevel}`;
|
|
71
|
+
logger.debug(cmd);
|
|
72
|
+
await executeCommand(cmd, hvigorLevelStr);
|
|
57
73
|
logger.debug('ascf compile completed');
|
|
58
74
|
}
|
|
59
75
|
} catch (err: any) {
|
|
@@ -74,33 +90,53 @@ async function execPlugin(opts: AscfPluginOptions, node: HvigorNode) {
|
|
|
74
90
|
}
|
|
75
91
|
}
|
|
76
92
|
|
|
77
|
-
function executeCommand(command: string) {
|
|
93
|
+
function executeCommand(command: string, levelStr: string) {
|
|
78
94
|
return new Promise((resolve, reject) => {
|
|
79
|
-
exec(command, (error: any, stdout:
|
|
95
|
+
exec(command, (error: any, stdout: string, stderr: string) => {
|
|
96
|
+
printLogger(stdout, levelStr);
|
|
80
97
|
if (error) {
|
|
81
98
|
reject(error);
|
|
82
99
|
} else {
|
|
83
|
-
|
|
84
|
-
logger.debug(stdout);
|
|
85
|
-
resolve(stderr);
|
|
100
|
+
resolve(stdout);
|
|
86
101
|
}
|
|
87
102
|
});
|
|
88
103
|
});
|
|
89
104
|
}
|
|
90
105
|
|
|
106
|
+
function printLogger(stdout: string, levelStr: string) {
|
|
107
|
+
if (stdout.length === 0) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (levelStr === LogLevel.INFO) {
|
|
111
|
+
logger.info(stdout);
|
|
112
|
+
} else if (levelStr === LogLevel.WARN) {
|
|
113
|
+
logger.warn(stdout);
|
|
114
|
+
} else if (levelStr === LogLevel.ERROR) {
|
|
115
|
+
logger.error(stdout);
|
|
116
|
+
} else {
|
|
117
|
+
logger.debug(stdout);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
91
121
|
function getNodeExe() {
|
|
92
122
|
const property: Property = new Property();
|
|
93
123
|
const nodeDir = property.getProperty(PropertyConst.NPM_DIR);
|
|
94
124
|
const platform = os.platform();
|
|
125
|
+
let got = 'node';
|
|
126
|
+
|
|
95
127
|
if (platform === 'win32') {
|
|
96
|
-
|
|
128
|
+
got = path.join(nodeDir, 'node.exe');
|
|
97
129
|
} else if (platform === 'darwin' || platform === 'linux') {
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
return 'node';
|
|
130
|
+
got = path.join(nodeDir, 'node');
|
|
101
131
|
}
|
|
132
|
+
|
|
133
|
+
return fs.existsSync(got) ? adjustPathByPlatform(got) : 'node';
|
|
102
134
|
}
|
|
103
135
|
|
|
104
136
|
function getAscfScript() {
|
|
105
|
-
return path.join(ascf.getAscfToolkitDirname(), 'bin', 'ascf.js');
|
|
137
|
+
return adjustPathByPlatform(path.join(ascf.getAscfToolkitDirname(), 'bin', 'ascf.js'));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function adjustPathByPlatform(path: string) {
|
|
141
|
+
return os.platform() === 'win32' ? `\"${path}\"` : path;
|
|
106
142
|
}
|
|
@@ -5,7 +5,7 @@ import { execSync } from 'child_process';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
|
|
8
|
-
const logger = HvigorLogger.getLogger('
|
|
8
|
+
const logger = HvigorLogger.getLogger('installAscfHspPlugin');
|
|
9
9
|
|
|
10
10
|
function execSafe(cmd: string) {
|
|
11
11
|
try {
|
|
@@ -15,7 +15,7 @@ function execSafe(cmd: string) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const BUNDLE_NAME_ASCF = 'com.huawei.hms.
|
|
18
|
+
const BUNDLE_NAME_ASCF = 'com.huawei.hms.ascfruntime';
|
|
19
19
|
const ERR_MSG = `${BUNDLE_NAME_ASCF} install failed, please open helloUniapp manually.`;
|
|
20
20
|
|
|
21
21
|
function checkAscfHsp() {
|
|
@@ -38,7 +38,7 @@ function doInstallAscfHsp(resolve: any, reject: any) {
|
|
|
38
38
|
logger.debug(`trying to install ${BUNDLE_NAME_ASCF}`);
|
|
39
39
|
const configJsonPath = path.resolve(__dirname, '../config.json');
|
|
40
40
|
const configJson = JSON.parse(fs.readFileSync(configJsonPath).toString());
|
|
41
|
-
const startInfo = execSafe(`hdc shell aa start -b com.huawei.hmos.browser -a MainAbility -A ohos.want.action.viewData -U "${configJson.
|
|
41
|
+
const startInfo = execSafe(`hdc shell aa start -b com.huawei.hmos.browser -a MainAbility -A ohos.want.action.viewData -U "${configJson.ascfRuntimeHspUrl}"`);
|
|
42
42
|
if (!startInfo?.includes('successfully')) {
|
|
43
43
|
logger.warn(`${ERR_MSG} errorInfo=${startInfo}`);
|
|
44
44
|
reject(ERR_MSG);
|