@react-native-oh/react-native-harmony-cli 0.77.18 → 0.77.33
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/assetResolver.js +74 -43
- package/dist/autolinking/Autolinking.js +179 -178
- package/dist/codegen/core/CodegenError.js +23 -3
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
- package/dist/codegen/core/UberSchema.js +97 -55
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
- package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
- package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -18
- package/dist/codegen/generators/UberGeneratorV2.js +36 -28
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
- package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -54
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
- package/dist/codegen/templates/IndexTSTemplate.js +17 -37
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
- package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
- package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
- package/dist/commands/bundle-harmony.js +221 -118
- package/dist/commands/clean-harmony.js +63 -58
- package/dist/commands/codegen-harmony.js +175 -104
- package/dist/commands/codegen-lib-harmony.js +116 -76
- package/dist/commands/init-harmony.js +196 -151
- package/dist/commands/init.js +961 -537
- package/dist/commands/link-harmony.js +82 -35
- package/dist/commands/run-harmony.js +520 -352
- package/dist/commands/verify-package-harmony.js +117 -54
- package/dist/core/AbsolutePath.js +49 -33
- package/dist/core/CodegenConfig.js +22 -24
- package/dist/core/DescriptiveError.js +37 -18
- package/dist/core/FileSystem.js +18 -14
- package/dist/core/OHPackageJSON5.js +23 -17
- package/dist/core/PackageJSON.js +42 -26
- package/dist/core/ProjectDependenciesManager.js +92 -40
- package/dist/core/ValidationError.js +22 -2
- package/dist/core/fs.js +7 -10
- package/dist/index.js +1 -1
- package/dist/init/templates/AppScopeAppJSON5Template.js +8 -21
- package/dist/init/templates/AppScopeStringVarTemplate.js +8 -19
- package/dist/init/templates/EntryIndexTemplate.js +8 -56
- package/dist/init/templates/EntryStringVarTemplate.js +8 -27
- package/dist/init/templates/HvigorConfigJson5Template.js +8 -33
- package/dist/init/templates/MetroConfigTemplate.js +8 -38
- package/dist/init/templates/OhPackageJson5Template.js +8 -28
- package/dist/io/CliExecutor.js +98 -46
- package/dist/io/Logger.js +46 -40
- package/dist/io/RealFS.js +100 -43
- package/dist/io/TarGz.js +8 -11
- package/dist/io/__fixtures__.js +141 -79
- package/dist/io/fsUtils.js +12 -13
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
- package/dist/package-verifier/verify-package.js +133 -56
- package/dist/simulator/LaunchSimulator.js +395 -0
- package/dist/simulator/index.js +23 -0
- package/package.json +2 -11
- package/scripts/sync-hvigor.js +27 -0
- package/src/autolinking/Autolinking.ts +1 -1
- package/src/codegen/generators/UberGeneratorV1.ts +7 -2
- package/src/codegen/generators/UberGeneratorV2.ts +6 -1
- package/src/commands/codegen-harmony.ts +17 -7
- package/src/commands/run-harmony.ts +67 -41
- package/src/init/templates/harmony/entry/src/main/module.json5 +7 -0
- package/src/simulator/LaunchSimulator.ts +359 -0
- package/src/simulator/index.ts +8 -0
- package/dist/init/templates/harmony/AppScope/app.json5 +0 -10
- package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +0 -8
- package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
- package/dist/init/templates/harmony/build-profile.json5 +0 -36
- package/dist/init/templates/harmony/codelinter.json +0 -32
- package/dist/init/templates/harmony/entry/build-profile.json5 +0 -18
- package/dist/init/templates/harmony/entry/gitignore +0 -7
- package/dist/init/templates/harmony/entry/hvigorfile.ts +0 -13
- package/dist/init/templates/harmony/entry/oh-package.json5 +0 -9
- package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +0 -27
- package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +0 -13
- package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +0 -4
- package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +0 -8
- package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +0 -2
- package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +0 -11
- package/dist/init/templates/harmony/entry/src/main/ets/gitignore +0 -1
- package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
- package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +0 -16
- package/dist/init/templates/harmony/entry/src/main/module.json5 +0 -58
- package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +0 -8
- package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +0 -16
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +0 -7
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +0 -5
- package/dist/init/templates/harmony/entry/src/main/resources/gitignore +0 -1
- package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +0 -2
- package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +0 -13
- package/dist/init/templates/harmony/gitignore +0 -16
- package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +0 -22
- package/dist/init/templates/harmony/hvigorfile.ts +0 -7
|
@@ -14,21 +14,57 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
17
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
19
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
+
function step(op) {
|
|
22
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
+
switch (op[0]) {
|
|
27
|
+
case 0: case 1: t = op; break;
|
|
28
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
+
default:
|
|
32
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
+
if (t[2]) _.ops.pop();
|
|
37
|
+
_.trys.pop(); continue;
|
|
38
|
+
}
|
|
39
|
+
op = body.call(thisArg, _);
|
|
40
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
+
if (ar || !(i in from)) {
|
|
47
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
+
ar[i] = from[i];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
19
52
|
};
|
|
20
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
54
|
exports.commandRunHarmony = void 0;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
55
|
+
var core_1 = require("../core");
|
|
56
|
+
var io_1 = require("../io");
|
|
57
|
+
var CliExecutor_1 = require("../io/CliExecutor");
|
|
58
|
+
var fs_extra_1 = require("fs-extra");
|
|
59
|
+
var node_crypto_1 = require("node:crypto");
|
|
60
|
+
var json5_1 = require("json5");
|
|
61
|
+
var inquirer_1 = require("inquirer");
|
|
62
|
+
var path_1 = require("path");
|
|
63
|
+
var cli_tools_1 = require("@react-native-community/cli-tools");
|
|
64
|
+
var simulator_1 = require("../simulator");
|
|
65
|
+
var COMMAND_NAME = 'run-harmony';
|
|
66
|
+
var LOOPBACK_IP = '127.0.0.1';
|
|
67
|
+
var DEFAULT_SIMULATOR_NAME = "".concat(LOOPBACK_IP, ":5555");
|
|
32
68
|
exports.commandRunHarmony = {
|
|
33
69
|
name: COMMAND_NAME,
|
|
34
70
|
description: 'Builds your app and starts it on your phone.',
|
|
@@ -73,366 +109,498 @@ exports.commandRunHarmony = {
|
|
|
73
109
|
description: 'Do not launch packager while running the app.',
|
|
74
110
|
},
|
|
75
111
|
],
|
|
76
|
-
func: (_argv, _config, rawArgs)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
],
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
const fs = new io_1.RealFS();
|
|
91
|
-
const sdkPath = new core_1.AbsolutePath(DEVECO_SDK_HOME);
|
|
92
|
-
const sdkDirectoryNames = fs
|
|
93
|
-
.readDirentsSync(sdkPath)
|
|
94
|
-
.flatMap((dirent) => {
|
|
95
|
-
if (dirent.isDirectory()) {
|
|
96
|
-
return [dirent.name];
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
if (sdkDirectoryNames.length === 0) {
|
|
103
|
-
throw new core_1.DescriptiveError({
|
|
104
|
-
whatHappened: `${sdkPath.toString()} has no directories`,
|
|
105
|
-
unexpected: true,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
const sdkToolchainsPath = sdkPath.copyWithNewSegment(sdkDirectoryNames[0], 'openharmony', 'toolchains');
|
|
109
|
-
const cli = new CliExecutor_1.RealCliExecutor();
|
|
110
|
-
const harmonyProjectPath = new core_1.AbsolutePath(rawArgs.harmonyProjectPath);
|
|
111
|
-
const productName = rawArgs.product;
|
|
112
|
-
const buildMode = rawArgs.buildMode;
|
|
113
|
-
const moduleName = rawArgs.module;
|
|
114
|
-
const abilityName = rawArgs.ability;
|
|
115
|
-
const simulatorName = rawArgs.simulator;
|
|
116
|
-
const defaultPort = rawArgs.port;
|
|
117
|
-
const packager = rawArgs.packager;
|
|
118
|
-
const devEcoStudioToolsPath = new core_1.AbsolutePath(DEVECO_SDK_HOME).copyWithNewSegment('..', 'tools');
|
|
119
|
-
if (!fs.existsSync(devEcoStudioToolsPath)) {
|
|
120
|
-
throw new core_1.DescriptiveError({
|
|
121
|
-
whatHappened: `${devEcoStudioToolsPath.toString()} doesn't exist`,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
const bundleName = json5_1.default.parse(fs.readTextSync(harmonyProjectPath.copyWithNewSegment('AppScope', 'app.json5'))).app.bundleName;
|
|
125
|
-
const selectDevice = (deviceAndSimulatorInfos) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
-
const lines = deviceAndSimulatorInfos.trim().split('\n');
|
|
127
|
-
const availableDevices = lines.map((line) => {
|
|
128
|
-
const parts = line.split(/\s+/);
|
|
129
|
-
return {
|
|
130
|
-
name: parts[0],
|
|
131
|
-
method: parts[1],
|
|
132
|
-
state: parts[2],
|
|
133
|
-
locate: parts[3],
|
|
134
|
-
connectTool: parts[4]
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
if (simulatorName !== 'undefined') {
|
|
138
|
-
const isRequestedDeviceAvailable = availableDevices.some((deviceOrSimulator) => deviceOrSimulator.name === simulatorName);
|
|
139
|
-
if (!isRequestedDeviceAvailable) {
|
|
112
|
+
func: function (_argv, _config, rawArgs) { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
+
var logger, DEVECO_SDK_HOME, fs_1, sdkPath, sdkDirectoryNames, sdkToolchainsPath_1, cli_1, harmonyProjectPath_1, productName_1, buildMode_1, moduleName_1, abilityName_1, simulatorName_1, defaultPort, packager, devEcoStudioToolsPath_1, bundleName_1, currentPort_1, root, reactNativePath, _a, newPort, startPackager, selectDevice, deviceAndSimulatorInfo, deviceOrSimulatorName_1, runJob, err_1;
|
|
114
|
+
return __generator(this, function (_b) {
|
|
115
|
+
switch (_b.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
logger = new io_1.Logger();
|
|
118
|
+
_b.label = 1;
|
|
119
|
+
case 1:
|
|
120
|
+
_b.trys.push([1, 11, , 12]);
|
|
121
|
+
DEVECO_SDK_HOME = process.env.DEVECO_SDK_HOME;
|
|
122
|
+
if (!DEVECO_SDK_HOME) {
|
|
140
123
|
throw new core_1.DescriptiveError({
|
|
141
|
-
whatHappened:
|
|
124
|
+
whatHappened: 'DEVECO_SDK_HOME environment variable is not set',
|
|
142
125
|
whatCanUserDo: [
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
process.platform === 'darwin'
|
|
127
|
+
? 'On MacOS, the contents directory is typically located at: /Applications/DevEco-Studio.app/Contents/sdk. Set this path as the value of DEVECO_SDK_HOME'
|
|
128
|
+
: "Locate the installation directory of DevEco Studio, and set its 'sdk' subdirectory as the value of DEVECO_SDK_HOME environment variable.",
|
|
129
|
+
],
|
|
145
130
|
});
|
|
146
131
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
{
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
132
|
+
fs_1 = new io_1.RealFS();
|
|
133
|
+
sdkPath = new core_1.AbsolutePath(DEVECO_SDK_HOME);
|
|
134
|
+
sdkDirectoryNames = fs_1
|
|
135
|
+
.readDirentsSync(sdkPath)
|
|
136
|
+
.flatMap(function (dirent) {
|
|
137
|
+
if (dirent.isDirectory()) {
|
|
138
|
+
return [dirent.name];
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return [];
|
|
157
142
|
}
|
|
158
|
-
]);
|
|
159
|
-
return connectedDevices[parseInt(answers.selectedDeviceIndex) - 1].name;
|
|
160
|
-
}
|
|
161
|
-
else if (connectedDevices.length === 1) {
|
|
162
|
-
return connectedDevices[0].name;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
throw new core_1.DescriptiveError({
|
|
166
|
-
whatHappened: `No devices are connected in the current environment.`,
|
|
167
|
-
whatCanUserDo: [
|
|
168
|
-
'Please connect your HarmonyOS device or open the simulator.',
|
|
169
|
-
]
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
const deviceAndSimulatorInfo = yield cli.run(sdkToolchainsPath.copyWithNewSegment('hdc').toString(), {
|
|
174
|
-
args: ['list', 'targets', '-v'],
|
|
175
|
-
cwd: harmonyProjectPath,
|
|
176
|
-
});
|
|
177
|
-
const deviceOrSimulatorName = yield selectDevice(deviceAndSimulatorInfo);
|
|
178
|
-
let currentPort = defaultPort;
|
|
179
|
-
if (packager) {
|
|
180
|
-
const root = _config.root || '.';
|
|
181
|
-
const reactNativePath = _config.reactNativePath || path_1.default.dirname(require.resolve('react-native', { paths: [root] }));
|
|
182
|
-
const { port: newPort, startPackager } = yield (0, cli_tools_1.findDevServerPort)(defaultPort, root);
|
|
183
|
-
if (newPort !== 8081) {
|
|
184
|
-
yield trySetMetroPort(harmonyProjectPath.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets').toString(), newPort);
|
|
185
|
-
}
|
|
186
|
-
if (startPackager) {
|
|
187
|
-
(0, cli_tools_1.startServerInNewWindow)(newPort, root, reactNativePath, (0, cli_tools_1.getDefaultUserTerminal)());
|
|
188
|
-
}
|
|
189
|
-
currentPort = newPort;
|
|
190
|
-
}
|
|
191
|
-
const runJob = (name, job) => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
-
const stop = logger.start((s) => s.bold(name));
|
|
193
|
-
logger.info((s) => s.bold(`${name} started`));
|
|
194
|
-
try {
|
|
195
|
-
yield job();
|
|
196
|
-
logger.succeed((s) => s.bold(`${name} finished`));
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
if (err instanceof core_1.DescriptiveError) {
|
|
200
|
-
throw err;
|
|
201
|
-
}
|
|
202
|
-
throw new core_1.DescriptiveError({
|
|
203
|
-
whatHappened: `${name} failed`,
|
|
204
|
-
extraData: err,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
finally {
|
|
208
|
-
stop();
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
yield runJob('[1/3] installing dependencies', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
212
|
-
let ohpmPath = devEcoStudioToolsPath
|
|
213
|
-
.copyWithNewSegment('ohpm', 'bin', 'ohpm');
|
|
214
|
-
if (process.platform === 'win32') {
|
|
215
|
-
ohpmPath = devEcoStudioToolsPath
|
|
216
|
-
.copyWithNewSegment('ohpm', 'bin', 'ohpm.bat');
|
|
217
|
-
}
|
|
218
|
-
yield cli.run(process.platform === 'win32' ? `"${ohpmPath.toString()}"` :
|
|
219
|
-
ohpmPath.toString(), {
|
|
220
|
-
args: [
|
|
221
|
-
'install',
|
|
222
|
-
'--all',
|
|
223
|
-
'--strict_ssl',
|
|
224
|
-
'true',
|
|
225
|
-
],
|
|
226
|
-
cwd: harmonyProjectPath,
|
|
227
|
-
shell: true,
|
|
228
|
-
onArgsStringified: (commandWithArgs) => {
|
|
229
|
-
logger.debug((s) => s.bold(s.gray(commandWithArgs)));
|
|
230
|
-
},
|
|
231
|
-
onStdout: (msg) => {
|
|
232
|
-
logger.debug((s) => s.gray(msg.trimEnd()));
|
|
233
|
-
},
|
|
234
|
-
onStderr(msg) {
|
|
235
|
-
logger.debug(() => msg.trimEnd());
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
}));
|
|
239
|
-
yield runJob('[2/3] building app', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
|
-
let nodePath = devEcoStudioToolsPath
|
|
241
|
-
.copyWithNewSegment('node', 'bin', 'node');
|
|
242
|
-
if (!fs.existsSync(nodePath)) {
|
|
243
|
-
nodePath = devEcoStudioToolsPath.copyWithNewSegment('node', 'node');
|
|
244
|
-
}
|
|
245
|
-
let hvigorPathRaw = devEcoStudioToolsPath.copyWithNewSegment('hvigor', 'bin', 'hvigorw.js').toString();
|
|
246
|
-
const hvigorPath = process.platform === 'win32' ? `"${hvigorPathRaw}"` : hvigorPathRaw;
|
|
247
|
-
yield cli.run(process.platform === 'win32' ? `"${nodePath.toString()}"` :
|
|
248
|
-
nodePath.toString(), {
|
|
249
|
-
args: [
|
|
250
|
-
hvigorPath,
|
|
251
|
-
`-p`,
|
|
252
|
-
`module=${moduleName}@default`,
|
|
253
|
-
`-p`,
|
|
254
|
-
`product=${productName}`,
|
|
255
|
-
`-p`,
|
|
256
|
-
`buildMode=${buildMode}`,
|
|
257
|
-
`-p`,
|
|
258
|
-
`requiredDeviceType=phone`,
|
|
259
|
-
`assembleHap`,
|
|
260
|
-
],
|
|
261
|
-
cwd: harmonyProjectPath,
|
|
262
|
-
shell: true,
|
|
263
|
-
onArgsStringified: (commandWithArgs) => {
|
|
264
|
-
logger.debug((s) => s.bold(s.gray(commandWithArgs)));
|
|
265
|
-
},
|
|
266
|
-
onStdout: (msg) => {
|
|
267
|
-
logger.debug((s) => s.gray(msg.trimEnd()));
|
|
268
|
-
},
|
|
269
|
-
onStderr(msg) {
|
|
270
|
-
logger.debug(() => msg.trimEnd());
|
|
271
|
-
},
|
|
272
|
-
});
|
|
273
|
-
}));
|
|
274
|
-
yield runJob('[3/3] installing and opening app', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
275
|
-
const tmpDirName = generateRandomString();
|
|
276
|
-
const ohosTmpDirPath = `data/local/tmp/${tmpDirName}`;
|
|
277
|
-
const exec = (command, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
278
|
-
const result = yield cli.run(command, {
|
|
279
|
-
args: args,
|
|
280
|
-
shell: true,
|
|
281
|
-
onArgsStringified: (commandWithArgs) => logger.debug((s) => s.bold(s.gray(commandWithArgs))),
|
|
282
143
|
});
|
|
283
|
-
if (
|
|
284
|
-
throw new core_1.DescriptiveError({
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
144
|
+
if (sdkDirectoryNames.length === 0) {
|
|
145
|
+
throw new core_1.DescriptiveError({
|
|
146
|
+
whatHappened: "".concat(sdkPath.toString(), " has no directories"),
|
|
147
|
+
unexpected: true,
|
|
148
|
+
});
|
|
288
149
|
}
|
|
289
|
-
|
|
290
|
-
|
|
150
|
+
sdkToolchainsPath_1 = sdkPath.copyWithNewSegment(sdkDirectoryNames[0], 'openharmony', 'toolchains');
|
|
151
|
+
cli_1 = new CliExecutor_1.RealCliExecutor();
|
|
152
|
+
harmonyProjectPath_1 = new core_1.AbsolutePath(rawArgs.harmonyProjectPath);
|
|
153
|
+
productName_1 = rawArgs.product;
|
|
154
|
+
buildMode_1 = rawArgs.buildMode;
|
|
155
|
+
moduleName_1 = rawArgs.module;
|
|
156
|
+
abilityName_1 = rawArgs.ability;
|
|
157
|
+
simulatorName_1 = rawArgs.simulator;
|
|
158
|
+
defaultPort = rawArgs.port;
|
|
159
|
+
packager = rawArgs.packager;
|
|
160
|
+
devEcoStudioToolsPath_1 = new core_1.AbsolutePath(DEVECO_SDK_HOME).copyWithNewSegment('..', 'tools');
|
|
161
|
+
if (!fs_1.existsSync(devEcoStudioToolsPath_1)) {
|
|
162
|
+
throw new core_1.DescriptiveError({
|
|
163
|
+
whatHappened: "".concat(devEcoStudioToolsPath_1.toString(), " doesn't exist"),
|
|
164
|
+
});
|
|
291
165
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
.
|
|
296
|
-
.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
if (fportInfo.includes(`tcp:${currentPort} tcp:${currentPort}`)) {
|
|
311
|
-
yield exec(hdcPathStr, [
|
|
312
|
-
'fport',
|
|
313
|
-
'rm',
|
|
314
|
-
`tcp:${currentPort}`,
|
|
315
|
-
`tcp:${currentPort}`
|
|
316
|
-
]);
|
|
166
|
+
bundleName_1 = json5_1.default.parse(fs_1.readTextSync(harmonyProjectPath_1.copyWithNewSegment('AppScope', 'app.json5'))).app.bundleName;
|
|
167
|
+
currentPort_1 = defaultPort;
|
|
168
|
+
if (!packager) return [3 /*break*/, 5];
|
|
169
|
+
root = _config.root || '.';
|
|
170
|
+
reactNativePath = _config.reactNativePath || path_1.default.dirname(require.resolve('react-native', { paths: [root] }));
|
|
171
|
+
return [4 /*yield*/, (0, cli_tools_1.findDevServerPort)(defaultPort, root)];
|
|
172
|
+
case 2:
|
|
173
|
+
_a = _b.sent(), newPort = _a.port, startPackager = _a.startPackager;
|
|
174
|
+
if (!(newPort !== 8081)) return [3 /*break*/, 4];
|
|
175
|
+
return [4 /*yield*/, trySetMetroPort(harmonyProjectPath_1.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets').toString(), newPort)];
|
|
176
|
+
case 3:
|
|
177
|
+
_b.sent();
|
|
178
|
+
_b.label = 4;
|
|
179
|
+
case 4:
|
|
180
|
+
if (startPackager) {
|
|
181
|
+
(0, cli_tools_1.startServerInNewWindow)(newPort, root, reactNativePath, (0, cli_tools_1.getDefaultUserTerminal)());
|
|
317
182
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
183
|
+
currentPort_1 = newPort;
|
|
184
|
+
_b.label = 5;
|
|
185
|
+
case 5:
|
|
186
|
+
selectDevice = function (deviceAndSimulatorInfos) { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
|
+
var lines, availableDevices, isRequestedDeviceAvailable, connectedDevices, answers, e_1;
|
|
188
|
+
return __generator(this, function (_a) {
|
|
189
|
+
switch (_a.label) {
|
|
190
|
+
case 0:
|
|
191
|
+
lines = deviceAndSimulatorInfos.trim().split('\n');
|
|
192
|
+
availableDevices = lines.map(function (line) {
|
|
193
|
+
var parts = line.split(/\s+/);
|
|
194
|
+
return {
|
|
195
|
+
name: parts[0],
|
|
196
|
+
method: parts[1],
|
|
197
|
+
state: parts[2],
|
|
198
|
+
locate: parts[3],
|
|
199
|
+
connectTool: parts[4]
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
if (simulatorName_1 !== 'undefined') {
|
|
203
|
+
isRequestedDeviceAvailable = availableDevices.some(function (deviceOrSimulator) { return deviceOrSimulator.name === simulatorName_1; });
|
|
204
|
+
if (!isRequestedDeviceAvailable) {
|
|
205
|
+
throw new core_1.DescriptiveError({
|
|
206
|
+
whatHappened: "Simulator with name \"".concat(simulatorName_1, "\" not found."),
|
|
207
|
+
whatCanUserDo: [
|
|
208
|
+
'Please confirm whether the entered simulator name has been activated.',
|
|
209
|
+
]
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return [2 /*return*/, simulatorName_1];
|
|
213
|
+
}
|
|
214
|
+
connectedDevices = availableDevices.filter(function (deviceOrSimulator) { return deviceOrSimulator.state === 'Connected'; });
|
|
215
|
+
if (connectedDevices.length === 1) {
|
|
216
|
+
return [2 /*return*/, connectedDevices[0].name];
|
|
217
|
+
}
|
|
218
|
+
if (!(connectedDevices.length > 1)) return [3 /*break*/, 2];
|
|
219
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
220
|
+
{
|
|
221
|
+
type: 'list',
|
|
222
|
+
name: 'selectedDeviceIndex',
|
|
223
|
+
message: 'Please select a device:',
|
|
224
|
+
choices: connectedDevices.map(function (deviceOrSimulator, index) { return "".concat(index + 1, ". ").concat(deviceOrSimulator.name); })
|
|
225
|
+
}
|
|
226
|
+
])];
|
|
227
|
+
case 1:
|
|
228
|
+
answers = _a.sent();
|
|
229
|
+
return [2 /*return*/, connectedDevices[parseInt(answers.selectedDeviceIndex) - 1].name];
|
|
230
|
+
case 2:
|
|
231
|
+
_a.trys.push([2, 4, , 5]);
|
|
232
|
+
return [4 /*yield*/, (0, simulator_1.launchHarmonySimulator)({
|
|
233
|
+
devEcoStudioToolsPath: devEcoStudioToolsPath_1,
|
|
234
|
+
sdkToolchainsPath: sdkToolchainsPath_1,
|
|
235
|
+
cli: cli_1,
|
|
236
|
+
logger: logger,
|
|
237
|
+
env: process.env,
|
|
238
|
+
})];
|
|
239
|
+
case 3:
|
|
240
|
+
_a.sent();
|
|
241
|
+
simulatorName_1 = DEFAULT_SIMULATOR_NAME;
|
|
242
|
+
return [2 /*return*/, simulatorName_1];
|
|
243
|
+
case 4:
|
|
244
|
+
e_1 = _a.sent();
|
|
245
|
+
if (e_1 instanceof core_1.DescriptiveError) {
|
|
246
|
+
throw new core_1.DescriptiveError({
|
|
247
|
+
whatHappened: "".concat(e_1.getMessage(), " \n No devices are connected. Failed to auto-launch simulator."),
|
|
248
|
+
whatCanUserDo: __spreadArray([], e_1.getSuggestions(), true),
|
|
249
|
+
extraData: e_1.getRawData().extraData,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
throw new core_1.DescriptiveError({
|
|
253
|
+
whatHappened: "No devices are connected in the current environment (auto-launch attempt failed).",
|
|
254
|
+
whatCanUserDo: [
|
|
255
|
+
'Connect a HarmonyOS device via USB or start the simulator manually.',
|
|
256
|
+
'Re-run the command after a device is listed by: hdc list targets -v',
|
|
257
|
+
],
|
|
258
|
+
extraData: e_1,
|
|
259
|
+
});
|
|
260
|
+
case 5: return [2 /*return*/];
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}); };
|
|
264
|
+
return [4 /*yield*/, cli_1.run(sdkToolchainsPath_1.copyWithNewSegment('hdc').toString(), {
|
|
265
|
+
args: ['list', 'targets', '-v'],
|
|
266
|
+
cwd: harmonyProjectPath_1,
|
|
267
|
+
})];
|
|
268
|
+
case 6:
|
|
269
|
+
deviceAndSimulatorInfo = _b.sent();
|
|
270
|
+
return [4 /*yield*/, selectDevice(deviceAndSimulatorInfo)];
|
|
271
|
+
case 7:
|
|
272
|
+
deviceOrSimulatorName_1 = _b.sent();
|
|
273
|
+
if (deviceOrSimulatorName_1.includes("".concat(LOOPBACK_IP, ":"))) {
|
|
274
|
+
simulatorName_1 = deviceOrSimulatorName_1;
|
|
325
275
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
276
|
+
runJob = function (name, job) { return __awaiter(void 0, void 0, void 0, function () {
|
|
277
|
+
var stop, err_2;
|
|
278
|
+
return __generator(this, function (_a) {
|
|
279
|
+
switch (_a.label) {
|
|
280
|
+
case 0:
|
|
281
|
+
stop = logger.start(function (s) { return s.bold(name); });
|
|
282
|
+
logger.info(function (s) { return s.bold("".concat(name, " started")); });
|
|
283
|
+
_a.label = 1;
|
|
284
|
+
case 1:
|
|
285
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
286
|
+
return [4 /*yield*/, job()];
|
|
287
|
+
case 2:
|
|
288
|
+
_a.sent();
|
|
289
|
+
logger.succeed(function (s) { return s.bold("".concat(name, " finished")); });
|
|
290
|
+
return [3 /*break*/, 5];
|
|
291
|
+
case 3:
|
|
292
|
+
err_2 = _a.sent();
|
|
293
|
+
if (err_2 instanceof core_1.DescriptiveError) {
|
|
294
|
+
throw err_2;
|
|
295
|
+
}
|
|
296
|
+
throw new core_1.DescriptiveError({
|
|
297
|
+
whatHappened: "".concat(name, " failed"),
|
|
298
|
+
extraData: err_2,
|
|
299
|
+
});
|
|
300
|
+
case 4:
|
|
301
|
+
stop();
|
|
302
|
+
return [7 /*endfinally*/];
|
|
303
|
+
case 5: return [2 /*return*/];
|
|
304
|
+
}
|
|
351
305
|
});
|
|
306
|
+
}); };
|
|
307
|
+
return [4 /*yield*/, runJob('[1/3] installing dependencies', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
308
|
+
var ohpmPath;
|
|
309
|
+
return __generator(this, function (_a) {
|
|
310
|
+
switch (_a.label) {
|
|
311
|
+
case 0:
|
|
312
|
+
ohpmPath = devEcoStudioToolsPath_1
|
|
313
|
+
.copyWithNewSegment('ohpm', 'bin', 'ohpm');
|
|
314
|
+
if (process.platform === 'win32') {
|
|
315
|
+
ohpmPath = devEcoStudioToolsPath_1
|
|
316
|
+
.copyWithNewSegment('ohpm', 'bin', 'ohpm.bat');
|
|
317
|
+
}
|
|
318
|
+
return [4 /*yield*/, cli_1.run("\"".concat(ohpmPath.toString(), "\""), {
|
|
319
|
+
args: [
|
|
320
|
+
'install',
|
|
321
|
+
'--all',
|
|
322
|
+
],
|
|
323
|
+
cwd: harmonyProjectPath_1,
|
|
324
|
+
shell: true,
|
|
325
|
+
onArgsStringified: function (commandWithArgs) {
|
|
326
|
+
logger.debug(function (s) { return s.bold(s.gray(commandWithArgs)); });
|
|
327
|
+
},
|
|
328
|
+
onStdout: function (msg) {
|
|
329
|
+
logger.debug(function (s) { return s.gray(msg.trimEnd()); });
|
|
330
|
+
},
|
|
331
|
+
onStderr: function (msg) {
|
|
332
|
+
logger.debug(function () { return msg.trimEnd(); });
|
|
333
|
+
},
|
|
334
|
+
})];
|
|
335
|
+
case 1:
|
|
336
|
+
_a.sent();
|
|
337
|
+
return [2 /*return*/];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}); })];
|
|
341
|
+
case 8:
|
|
342
|
+
_b.sent();
|
|
343
|
+
return [4 /*yield*/, runJob('[2/3] building app', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
344
|
+
var nodePath, hvigorPathRaw, hvigorPath;
|
|
345
|
+
return __generator(this, function (_a) {
|
|
346
|
+
switch (_a.label) {
|
|
347
|
+
case 0:
|
|
348
|
+
nodePath = devEcoStudioToolsPath_1
|
|
349
|
+
.copyWithNewSegment('node', 'bin', 'node');
|
|
350
|
+
if (!fs_1.existsSync(nodePath)) {
|
|
351
|
+
nodePath = devEcoStudioToolsPath_1.copyWithNewSegment('node', 'node');
|
|
352
|
+
}
|
|
353
|
+
hvigorPathRaw = devEcoStudioToolsPath_1.copyWithNewSegment('hvigor', 'bin', 'hvigorw.js').toString();
|
|
354
|
+
hvigorPath = "\"".concat(hvigorPathRaw, "\"");
|
|
355
|
+
return [4 /*yield*/, cli_1.run("\"".concat(nodePath.toString(), "\""), {
|
|
356
|
+
args: [
|
|
357
|
+
hvigorPath,
|
|
358
|
+
"-p",
|
|
359
|
+
"module=".concat(moduleName_1, "@default"),
|
|
360
|
+
"-p",
|
|
361
|
+
"product=".concat(productName_1),
|
|
362
|
+
"-p",
|
|
363
|
+
"buildMode=".concat(buildMode_1),
|
|
364
|
+
"-p",
|
|
365
|
+
"requiredDeviceType=phone",
|
|
366
|
+
"assembleHap",
|
|
367
|
+
],
|
|
368
|
+
cwd: harmonyProjectPath_1,
|
|
369
|
+
shell: true,
|
|
370
|
+
onArgsStringified: function (commandWithArgs) {
|
|
371
|
+
logger.debug(function (s) { return s.bold(s.gray(commandWithArgs)); });
|
|
372
|
+
},
|
|
373
|
+
onStdout: function (msg) {
|
|
374
|
+
logger.debug(function (s) { return s.gray(msg.trimEnd()); });
|
|
375
|
+
},
|
|
376
|
+
onStderr: function (msg) {
|
|
377
|
+
logger.debug(function () { return msg.trimEnd(); });
|
|
378
|
+
},
|
|
379
|
+
})];
|
|
380
|
+
case 1:
|
|
381
|
+
_a.sent();
|
|
382
|
+
return [2 /*return*/];
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}); })];
|
|
386
|
+
case 9:
|
|
387
|
+
_b.sent();
|
|
388
|
+
return [4 /*yield*/, runJob('[3/3] installing and opening app', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
389
|
+
var tmpDirName, ohosTmpDirPath, exec, hdcPathStrRaw, hdcPathStr, tryRemoveForwardPorting, hapName, installationResult;
|
|
390
|
+
return __generator(this, function (_a) {
|
|
391
|
+
switch (_a.label) {
|
|
392
|
+
case 0:
|
|
393
|
+
tmpDirName = generateRandomString();
|
|
394
|
+
ohosTmpDirPath = "data/local/tmp/".concat(tmpDirName);
|
|
395
|
+
exec = function (command, args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
396
|
+
var result;
|
|
397
|
+
return __generator(this, function (_a) {
|
|
398
|
+
switch (_a.label) {
|
|
399
|
+
case 0: return [4 /*yield*/, cli_1.run(command, {
|
|
400
|
+
args: args,
|
|
401
|
+
shell: true,
|
|
402
|
+
onArgsStringified: function (commandWithArgs) {
|
|
403
|
+
return logger.debug(function (s) { return s.bold(s.gray(commandWithArgs)); });
|
|
404
|
+
},
|
|
405
|
+
})];
|
|
406
|
+
case 1:
|
|
407
|
+
result = _a.sent();
|
|
408
|
+
if (result.startsWith('[Fail]')) {
|
|
409
|
+
throw new core_1.DescriptiveError({ whatHappened: result });
|
|
410
|
+
}
|
|
411
|
+
if (result) {
|
|
412
|
+
logger.debug(function (s) { return s.gray(result.trimEnd() + '\n'); });
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
logger.debug(function () { return ''; });
|
|
416
|
+
}
|
|
417
|
+
return [2 /*return*/, result];
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}); };
|
|
421
|
+
hdcPathStrRaw = sdkToolchainsPath_1
|
|
422
|
+
.copyWithNewSegment('hdc')
|
|
423
|
+
.toString();
|
|
424
|
+
hdcPathStr = "\"".concat(hdcPathStrRaw.toString(), "\"");
|
|
425
|
+
tryRemoveForwardPorting = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
426
|
+
var fportInfo;
|
|
427
|
+
return __generator(this, function (_a) {
|
|
428
|
+
switch (_a.label) {
|
|
429
|
+
case 0:
|
|
430
|
+
fportInfo = '';
|
|
431
|
+
return [4 /*yield*/, cli_1.run(hdcPathStrRaw, {
|
|
432
|
+
args: ['fport', 'ls'],
|
|
433
|
+
cwd: harmonyProjectPath_1,
|
|
434
|
+
onStdout: function (msg) {
|
|
435
|
+
fportInfo += msg;
|
|
436
|
+
},
|
|
437
|
+
onStderr: function (msg) {
|
|
438
|
+
logger.debug(function (s) { return s.gray(msg.trimEnd()); });
|
|
439
|
+
},
|
|
440
|
+
})];
|
|
441
|
+
case 1:
|
|
442
|
+
_a.sent();
|
|
443
|
+
if (!fportInfo.includes("tcp:".concat(currentPort_1, " tcp:").concat(currentPort_1))) return [3 /*break*/, 3];
|
|
444
|
+
return [4 /*yield*/, exec(hdcPathStr, [
|
|
445
|
+
'fport',
|
|
446
|
+
'rm',
|
|
447
|
+
"tcp:".concat(currentPort_1),
|
|
448
|
+
"tcp:".concat(currentPort_1)
|
|
449
|
+
])];
|
|
450
|
+
case 2:
|
|
451
|
+
_a.sent();
|
|
452
|
+
_a.label = 3;
|
|
453
|
+
case 3: return [2 /*return*/];
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}); };
|
|
457
|
+
return [4 /*yield*/, exec(hdcPathStr, ['-t', deviceOrSimulatorName_1, 'shell', 'aa', 'force-stop', bundleName_1])];
|
|
458
|
+
case 1:
|
|
459
|
+
_a.sent();
|
|
460
|
+
_a.label = 2;
|
|
461
|
+
case 2:
|
|
462
|
+
_a.trys.push([2, , 6, 8]);
|
|
463
|
+
return [4 /*yield*/, exec(hdcPathStr, ['-t', deviceOrSimulatorName_1, 'shell', 'mkdir', ohosTmpDirPath])];
|
|
464
|
+
case 3:
|
|
465
|
+
_a.sent();
|
|
466
|
+
hapName = "".concat(moduleName_1, "-default-signed.hap");
|
|
467
|
+
if (simulatorName_1 !== 'undefined') {
|
|
468
|
+
hapName = "".concat(moduleName_1, "-default-unsigned.hap");
|
|
469
|
+
}
|
|
470
|
+
return [4 /*yield*/, exec(hdcPathStr, [
|
|
471
|
+
'-t',
|
|
472
|
+
deviceOrSimulatorName_1,
|
|
473
|
+
'file',
|
|
474
|
+
'send',
|
|
475
|
+
harmonyProjectPath_1
|
|
476
|
+
.copyWithNewSegment(moduleName_1, 'build', 'default', 'outputs', 'default', hapName)
|
|
477
|
+
.toString(),
|
|
478
|
+
ohosTmpDirPath,
|
|
479
|
+
])];
|
|
480
|
+
case 4:
|
|
481
|
+
_a.sent();
|
|
482
|
+
return [4 /*yield*/, exec(hdcPathStr, [
|
|
483
|
+
'-t',
|
|
484
|
+
deviceOrSimulatorName_1,
|
|
485
|
+
'shell',
|
|
486
|
+
'bm',
|
|
487
|
+
'install',
|
|
488
|
+
'-p',
|
|
489
|
+
ohosTmpDirPath,
|
|
490
|
+
])];
|
|
491
|
+
case 5:
|
|
492
|
+
installationResult = _a.sent();
|
|
493
|
+
if (installationResult.includes('failed to install')) {
|
|
494
|
+
throw new core_1.DescriptiveError({
|
|
495
|
+
whatHappened: 'Installation failed.',
|
|
496
|
+
whatCanUserDo: [
|
|
497
|
+
"If an application with the same bundle name is already installed, try uninstalling it:\n".concat(hdcPathStr, " shell bm uninstall -n ").concat(bundleName_1),
|
|
498
|
+
],
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
return [3 /*break*/, 8];
|
|
502
|
+
case 6: return [4 /*yield*/, exec(hdcPathStr, ['-t', deviceOrSimulatorName_1, 'shell', 'rm', '-rf', ohosTmpDirPath])];
|
|
503
|
+
case 7:
|
|
504
|
+
_a.sent();
|
|
505
|
+
return [7 /*endfinally*/];
|
|
506
|
+
case 8: return [4 /*yield*/, exec(hdcPathStr, [
|
|
507
|
+
'-t',
|
|
508
|
+
deviceOrSimulatorName_1,
|
|
509
|
+
'shell',
|
|
510
|
+
'aa',
|
|
511
|
+
'start',
|
|
512
|
+
'-a',
|
|
513
|
+
abilityName_1,
|
|
514
|
+
'-b',
|
|
515
|
+
bundleName_1,
|
|
516
|
+
])];
|
|
517
|
+
case 9:
|
|
518
|
+
_a.sent();
|
|
519
|
+
return [4 /*yield*/, tryRemoveForwardPorting()];
|
|
520
|
+
case 10:
|
|
521
|
+
_a.sent();
|
|
522
|
+
return [4 /*yield*/, exec(hdcPathStr, [
|
|
523
|
+
'-t',
|
|
524
|
+
deviceOrSimulatorName_1,
|
|
525
|
+
'rport',
|
|
526
|
+
"tcp:".concat(currentPort_1),
|
|
527
|
+
"tcp:".concat(currentPort_1)
|
|
528
|
+
])];
|
|
529
|
+
case 11:
|
|
530
|
+
_a.sent();
|
|
531
|
+
return [2 /*return*/];
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}); })];
|
|
535
|
+
case 10:
|
|
536
|
+
_b.sent();
|
|
537
|
+
return [3 /*break*/, 12];
|
|
538
|
+
case 11:
|
|
539
|
+
err_1 = _b.sent();
|
|
540
|
+
if (err_1 instanceof core_1.DescriptiveError) {
|
|
541
|
+
logger.descriptiveError(new core_1.DescriptiveError({
|
|
542
|
+
whatHappened: err_1.getMessage(),
|
|
543
|
+
whatCanUserDo: __spreadArray(__spreadArray([], err_1.getSuggestions(), true), [
|
|
544
|
+
'Try building and running the app from DevEco studio.',
|
|
545
|
+
], false),
|
|
546
|
+
extraData: err_1.getRawData().extraData,
|
|
547
|
+
}));
|
|
352
548
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
'-t',
|
|
359
|
-
deviceOrSimulatorName,
|
|
360
|
-
'shell',
|
|
361
|
-
'aa',
|
|
362
|
-
'start',
|
|
363
|
-
'-a',
|
|
364
|
-
abilityName,
|
|
365
|
-
'-b',
|
|
366
|
-
bundleName,
|
|
367
|
-
]);
|
|
368
|
-
yield tryRemoveForwardPorting();
|
|
369
|
-
yield exec(hdcPathStr, [
|
|
370
|
-
'-t',
|
|
371
|
-
deviceOrSimulatorName,
|
|
372
|
-
'rport',
|
|
373
|
-
`tcp:${currentPort}`,
|
|
374
|
-
`tcp:${currentPort}`
|
|
375
|
-
]);
|
|
376
|
-
}));
|
|
377
|
-
}
|
|
378
|
-
catch (err) {
|
|
379
|
-
if (err instanceof core_1.DescriptiveError) {
|
|
380
|
-
logger.descriptiveError(new core_1.DescriptiveError({
|
|
381
|
-
whatHappened: err.getMessage(),
|
|
382
|
-
whatCanUserDo: [
|
|
383
|
-
...err.getSuggestions(),
|
|
384
|
-
'Try building and running the app from DevEco studio.',
|
|
385
|
-
],
|
|
386
|
-
extraData: err.getRawData().extraData,
|
|
387
|
-
}));
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
throw err;
|
|
549
|
+
else {
|
|
550
|
+
throw err_1;
|
|
551
|
+
}
|
|
552
|
+
return [3 /*break*/, 12];
|
|
553
|
+
case 12: return [2 /*return*/];
|
|
391
554
|
}
|
|
392
|
-
}
|
|
393
|
-
}),
|
|
555
|
+
});
|
|
556
|
+
}); },
|
|
394
557
|
};
|
|
395
|
-
function generateRandomString(length
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
558
|
+
function generateRandomString(length) {
|
|
559
|
+
if (length === void 0) { length = 32; }
|
|
560
|
+
var chars = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
561
|
+
var result = '';
|
|
562
|
+
var randomValues = new Uint8Array(length);
|
|
399
563
|
node_crypto_1.default.getRandomValues(randomValues);
|
|
400
|
-
for (
|
|
401
|
-
|
|
564
|
+
for (var i = 0; i < length; i++) {
|
|
565
|
+
var randomIndex = randomValues[i] % chars.length;
|
|
402
566
|
result += chars[randomIndex];
|
|
403
567
|
}
|
|
404
568
|
return result;
|
|
405
569
|
}
|
|
406
570
|
function trySetMetroPort(filePath, port) {
|
|
407
|
-
return __awaiter(this, void 0, void 0, function
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
571
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
572
|
+
var content, reFromServerIp, reNewProvider;
|
|
573
|
+
return __generator(this, function (_a) {
|
|
574
|
+
switch (_a.label) {
|
|
575
|
+
case 0: return [4 /*yield*/, fs_extra_1.default.readFile(filePath, 'utf-8')];
|
|
576
|
+
case 1:
|
|
577
|
+
content = _a.sent();
|
|
578
|
+
reFromServerIp = /MetroJSBundleProvider\.fromServerIp\(\s*"([^"]+)"\s*,\s*(\d+)\s*\)/;
|
|
579
|
+
if (!reFromServerIp.test(content)) return [3 /*break*/, 3];
|
|
580
|
+
content = content.replace(reFromServerIp, function (_match, host) {
|
|
581
|
+
return "MetroJSBundleProvider.fromServerIp(\"".concat(host, "\", ").concat(port, ")");
|
|
582
|
+
});
|
|
583
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, content, 'utf-8')];
|
|
584
|
+
case 2:
|
|
585
|
+
_a.sent();
|
|
586
|
+
return [2 /*return*/];
|
|
587
|
+
case 3:
|
|
588
|
+
reNewProvider = /new\s+MetroJSBundleProvider\s*\(\s*\)/;
|
|
589
|
+
if (!reNewProvider.test(content)) return [3 /*break*/, 5];
|
|
590
|
+
content = content.replace(reNewProvider, function () {
|
|
591
|
+
return "MetroJSBundleProvider.fromServerIp(\"localhost\", ".concat(port, "),\n new MetroJSBundleProvider()");
|
|
592
|
+
});
|
|
593
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, content, 'utf-8')];
|
|
594
|
+
case 4:
|
|
595
|
+
_a.sent();
|
|
596
|
+
return [2 /*return*/];
|
|
597
|
+
case 5: throw new core_1.DescriptiveError({
|
|
598
|
+
whatHappened: "Unable to set the specified port [".concat(port, "] for the Metro server automatically."),
|
|
599
|
+
whatCanUserDo: [
|
|
600
|
+
"Please manually add \"MetroJSBundleProvider.fromServerIp(\"localhost\", ".concat(port, ")\" in the \"new AnyJSBundleProvider\" section of your ").concat(filePath, " file.\ne.g:\n new AnyJSBundleProvider([\n MetroJSBundleProvider.fromServerIp(\"localhost\", ").concat(port, "),\n new MetroJSBundleProvider(),\n new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),\n ])")
|
|
601
|
+
],
|
|
602
|
+
});
|
|
603
|
+
}
|
|
436
604
|
});
|
|
437
605
|
});
|
|
438
606
|
}
|