|
|
@@ -2,6 +2,7 @@ import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
|
|
import { HvigorPlugin, HvigorNode } from '@ohos/hvigor';
|
|
|
import fs from 'fs';
|
|
|
import path from 'path';
|
|
|
+import { execSync } from 'child_process';
|
|
|
|
|
|
function customPlugin(): HvigorPlugin {
|
|
|
return {
|
|
|
@@ -478,10 +479,34 @@ function rDBPlugin(): HvigorPlugin {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function forwardingPort(){
|
|
|
+ return {
|
|
|
+ pluginId: 'customPlugin',
|
|
|
+ apply(node: HvigorNode) {
|
|
|
+ try {
|
|
|
+ var connectKeys = execSync('hdc list targets', { encoding: 'utf-8' }).split('\n');
|
|
|
+
|
|
|
+ var targetKey = connectKeys[0].trim();
|
|
|
+
|
|
|
+ var operation = `hdc -t ${targetKey} fport rm tcp:8080 tcp:8080`
|
|
|
+ var result = execSync(operation, { encoding: 'utf-8' })
|
|
|
+ console.log(`执行命令 ${operation}, 删除端口结果:${result.trim()}`);
|
|
|
+
|
|
|
+ operation = `hdc -t ${targetKey} fport tcp:8080 tcp:8080`
|
|
|
+ result = execSync(operation, { encoding: 'utf-8' })
|
|
|
+ console.log(`执行命令 ${operation}, 转发端口结果:${result.trim()}`);
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`执行失败: ${error.message}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export default {
|
|
|
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
|
|
plugins: [
|
|
|
customPlugin(), // 应用自定义Plugin
|
|
|
- rDBPlugin()
|
|
|
+ rDBPlugin(),
|
|
|
+ forwardingPort()
|
|
|
] /* Custom plugin to extend the functionality of Hvigor. */
|
|
|
}
|