@react-native-oh/react-native-harmony-cli 0.0.36 → 0.0.40-1
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/autolinking/Autolinking.js +14 -11
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -1
- package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -2
- package/dist/codegen/generators/UberGeneratorV1.js +9 -2
- package/dist/codegen/generators/UberGeneratorV2.js +8 -1
- package/dist/codegen/templates/BasePackageHTemplate.js +12 -1
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -1
- package/dist/commands/codegen-harmony.js +16 -5
- package/dist/commands/run-harmony.js +49 -27
- package/dist/core/ProjectDependenciesManager.js +5 -7
- package/dist/simulator/LaunchSimulator.js +318 -0
- package/dist/simulator/index.js +23 -0
- package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
- package/package.json +13 -5
- package/.prettierrc +0 -6
- package/src/assetResolver.ts +0 -134
- package/src/autolinking/Autolinking.test.ts +0 -483
- package/src/autolinking/Autolinking.ts +0 -382
- package/src/autolinking/index.ts +0 -8
- package/src/codegen/core/CodeGenerator.ts +0 -16
- package/src/codegen/core/CodegenError.ts +0 -10
- package/src/codegen/core/EventUtils.ts +0 -23
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
- package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
- package/src/codegen/core/UberSchema.ts +0 -152
- package/src/codegen/core/index.ts +0 -12
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -120
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
- package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
- package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
- package/src/codegen/generators/UberGeneratorV1.ts +0 -75
- package/src/codegen/generators/UberGeneratorV2.ts +0 -114
- package/src/codegen/generators/index.ts +0 -15
- package/src/codegen/index.ts +0 -9
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
- package/src/codegen/templates/BasePackageHTemplate.ts +0 -147
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
- package/src/codegen/templates/IndexTSTemplate.ts +0 -62
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -138
- package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
- package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
- package/src/codegen/templates/index.ts +0 -16
- package/src/commands/bundle-harmony.ts +0 -134
- package/src/commands/codegen-harmony.ts +0 -297
- package/src/commands/codegen-lib-harmony.ts +0 -389
- package/src/commands/create-metro-host-constants.ts +0 -55
- package/src/commands/index.ts +0 -16
- package/src/commands/init.ts +0 -755
- package/src/commands/link-harmony.ts +0 -102
- package/src/commands/pack-harmony.ts +0 -128
- package/src/commands/run-harmony.ts +0 -478
- package/src/commands/types.ts +0 -21
- package/src/commands/unpack-harmony.ts +0 -238
- package/src/commands/verify-package-harmony.ts +0 -113
- package/src/core/AbsolutePath.ts +0 -66
- package/src/core/CodegenConfig.ts +0 -67
- package/src/core/DescriptiveError.ts +0 -68
- package/src/core/FileSystem.ts +0 -57
- package/src/core/OHPackageJSON5.ts +0 -30
- package/src/core/PackageJSON.ts +0 -104
- package/src/core/ProjectDependenciesManager.ts +0 -103
- package/src/core/ValidationError.ts +0 -8
- package/src/core/ValueObject.ts +0 -9
- package/src/core/fs.ts +0 -38
- package/src/core/index.ts +0 -17
- package/src/index.ts +0 -33
- package/src/io/CliExecutor.ts +0 -69
- package/src/io/Logger.ts +0 -112
- package/src/io/RealFS.ts +0 -62
- package/src/io/TarGz.ts +0 -33
- package/src/io/__fixtures__.ts +0 -139
- package/src/io/fsUtils.ts +0 -44
- package/src/io/index.ts +0 -11
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
- package/src/package-verifier/checks/index.ts +0 -11
- package/src/package-verifier/index.ts +0 -9
- package/src/package-verifier/types.ts +0 -19
- package/src/package-verifier/verify-package.ts +0 -123
|
@@ -23,6 +23,7 @@ const json5_1 = __importDefault(require("json5"));
|
|
|
23
23
|
const core_1 = require("../core");
|
|
24
24
|
const mustache_1 = __importDefault(require("mustache"));
|
|
25
25
|
const case_1 = __importDefault(require("case"));
|
|
26
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
26
27
|
const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
27
28
|
/*
|
|
28
29
|
* This file was generated by RNOH autolinking.
|
|
@@ -50,7 +51,7 @@ const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
|
50
51
|
#pragma once
|
|
51
52
|
#include "RNOH/Package.h"
|
|
52
53
|
{{#libraries}}
|
|
53
|
-
#include "{{
|
|
54
|
+
#include "{{cppRNOHPackageClassName}}.h"
|
|
54
55
|
{{/libraries}}
|
|
55
56
|
|
|
56
57
|
std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
|
|
@@ -66,7 +67,7 @@ const CMAKE_AUTOLINKING_TEMPLATE = `
|
|
|
66
67
|
# DO NOT modify it manually, your changes WILL be overwritten.
|
|
67
68
|
cmake_minimum_required(VERSION 3.5)
|
|
68
69
|
|
|
69
|
-
# @
|
|
70
|
+
# @actor RNOH_APP
|
|
70
71
|
function(autolink_libraries target)
|
|
71
72
|
{{#libraries}}
|
|
72
73
|
add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
|
|
@@ -111,11 +112,11 @@ class Autolinking {
|
|
|
111
112
|
const skippedLibraryNpmPackageNames = [];
|
|
112
113
|
yield new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync((dependency) => {
|
|
113
114
|
var _a;
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
115
|
+
const harFilePaths = dependency.getHarFilePaths();
|
|
116
|
+
if (harFilePaths.length === 0) {
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
118
|
-
nodeModuleHarPaths.push(
|
|
119
|
+
nodeModuleHarPaths.push(...harFilePaths);
|
|
119
120
|
const packageJson = dependency.readPackageJSON();
|
|
120
121
|
const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
|
|
121
122
|
if (providedAutolinkingConfig === undefined ||
|
|
@@ -123,7 +124,8 @@ class Autolinking {
|
|
|
123
124
|
(config.excludedNpmPackageNames.has(packageJson.name) &&
|
|
124
125
|
config.excludedNpmPackageNames.size > 0) ||
|
|
125
126
|
(!config.includedNpmPackageNames.has(packageJson.name) &&
|
|
126
|
-
config.includedNpmPackageNames.size > 0)
|
|
127
|
+
config.includedNpmPackageNames.size > 0) ||
|
|
128
|
+
harFilePaths.length !== 1) {
|
|
127
129
|
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
@@ -134,7 +136,7 @@ class Autolinking {
|
|
|
134
136
|
cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
|
|
135
137
|
cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
|
|
136
138
|
ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
|
|
137
|
-
harFilePathRelativeToHarmony:
|
|
139
|
+
harFilePathRelativeToHarmony: harFilePaths[0]
|
|
138
140
|
.relativeTo(harmonyProjectPath)
|
|
139
141
|
.toString(),
|
|
140
142
|
});
|
|
@@ -171,13 +173,14 @@ class Autolinking {
|
|
|
171
173
|
const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map((lib) => lib.harFilePathRelativeToHarmony);
|
|
172
174
|
const unmanagedNativeDependencySpecifierByName = {};
|
|
173
175
|
Object.entries(ohPackage.dependencies).forEach(([name, dependencySpecifier]) => {
|
|
174
|
-
if (!dependencySpecifier.includes('file:')
|
|
176
|
+
if (!(dependencySpecifier.includes('file:') &&
|
|
177
|
+
dependencySpecifier.includes('node_modules'))) {
|
|
175
178
|
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
176
179
|
}
|
|
177
180
|
else {
|
|
178
181
|
const harFilePathRelativeToHarmony = dependencySpecifier.replace('file:', '');
|
|
179
|
-
if (!autolinkableHarFilePathsRelativeToHarmony.includes(harFilePathRelativeToHarmony) &&
|
|
180
|
-
input.nodeModuleHarFilePathsRelativeToHarmony.includes(harFilePathRelativeToHarmony)) {
|
|
182
|
+
if (!autolinkableHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony)) &&
|
|
183
|
+
input.nodeModuleHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony))) {
|
|
181
184
|
unmanagedNativeDependencySpecifierByName[name] =
|
|
182
185
|
dependencySpecifier;
|
|
183
186
|
}
|
|
@@ -186,7 +189,7 @@ class Autolinking {
|
|
|
186
189
|
const managedNativeDependencySpecifierByName = {};
|
|
187
190
|
for (const library of autolinkableLibraries) {
|
|
188
191
|
managedNativeDependencySpecifierByName[library.ohPackageName] =
|
|
189
|
-
|
|
192
|
+
`file:${library.harFilePathRelativeToHarmony}`.split(node_path_1.default.sep).join('/');
|
|
190
193
|
}
|
|
191
194
|
return {
|
|
192
195
|
skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
|
|
@@ -35,6 +35,7 @@ class AppBuildTimeGlueCodeGenerator {
|
|
|
35
35
|
generatedPackageH_v1.addComponent({
|
|
36
36
|
name,
|
|
37
37
|
supportedEventNames: eventNames,
|
|
38
|
+
isArkTSComponent: true,
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
v1.turboModules.forEach((turboModule) => {
|
|
@@ -45,7 +46,7 @@ class AppBuildTimeGlueCodeGenerator {
|
|
|
45
46
|
const basePackageClassName = `Base${case_1.default.pascal(libraryName)}Package`;
|
|
46
47
|
const generatedPackageH_v2 = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
|
|
47
48
|
components.forEach((component) => {
|
|
48
|
-
generatedPackageH_v2.addComponent(component);
|
|
49
|
+
generatedPackageH_v2.addComponent(Object.assign(Object.assign({}, component), { isArkTSComponent: false }));
|
|
49
50
|
});
|
|
50
51
|
turboModules.forEach((turboModule) => {
|
|
51
52
|
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
@@ -35,11 +35,11 @@ class LibGlueCodeGenerator {
|
|
|
35
35
|
});
|
|
36
36
|
arkTSComponents.forEach(({ componentName, eventNames }) => {
|
|
37
37
|
components_indexTS.addReexport({ from: `./${componentName}` });
|
|
38
|
-
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
38
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: true });
|
|
39
39
|
eventNames.forEach((eventName) => basePackageTemplate.addArkTSEvent({ name: eventName }));
|
|
40
40
|
});
|
|
41
41
|
cppComponents.forEach(({ componentName }) => {
|
|
42
|
-
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
42
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: false });
|
|
43
43
|
});
|
|
44
44
|
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', `${basePackageClassName}.h`), basePackageTemplate.build());
|
|
45
45
|
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
@@ -5,11 +5,17 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.UberGeneratorV1 = void 0;
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
10
14
|
const core_1 = require("../core");
|
|
11
15
|
const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
|
|
12
16
|
const ArkTSComponentCodeGeneratorArkTS_1 = require("./ArkTSComponentCodeGeneratorArkTS");
|
|
17
|
+
// The name of rnoh OHOS module
|
|
18
|
+
const RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
|
|
13
19
|
/**
|
|
14
20
|
* Generates code for libraries built on top of RNOH's ArkTS architecture.
|
|
15
21
|
*/
|
|
@@ -25,8 +31,9 @@ class UberGeneratorV1 {
|
|
|
25
31
|
}
|
|
26
32
|
generate(uberSchema) {
|
|
27
33
|
const fileContentByPath = new Map();
|
|
28
|
-
const
|
|
29
|
-
const
|
|
34
|
+
const isRNOHModulePath = this.etsOutputPath.getValue().endsWith(`${RNOH_OHOS_NAME}/generated`.replace(/\//g, path_1.default.sep));
|
|
35
|
+
const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS_1.ArkTSComponentCodeGeneratorArkTS(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('components'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
|
|
36
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
|
|
30
37
|
const generatorBySpecType = {
|
|
31
38
|
Component: componentCodeGenerator,
|
|
32
39
|
NativeModule: nativeModuleCodeGenerator,
|
|
@@ -5,11 +5,17 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.UberGeneratorV2 = void 0;
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
10
14
|
const CppComponentCodeGenerator_1 = require("./CppComponentCodeGenerator");
|
|
11
15
|
const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
|
|
12
16
|
const SharedComponentCodeGenerator_1 = require("./SharedComponentCodeGenerator");
|
|
17
|
+
// The name of rnoh OHOS module
|
|
18
|
+
const RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
|
|
13
19
|
/**
|
|
14
20
|
* Generates code for libraries built on top of RNOH's C-API architecture.
|
|
15
21
|
*/
|
|
@@ -57,7 +63,8 @@ class UberGeneratorV2 {
|
|
|
57
63
|
.getSpecSchemaByFilenameMap()
|
|
58
64
|
.entries()) {
|
|
59
65
|
if (specSchema.type === 'NativeModule') {
|
|
60
|
-
const
|
|
66
|
+
const isRNOHModulePath = this.etsOutputPath.getValue().endsWith(`${RNOH_OHOS_NAME}/generated`.replace(/\//g, path_1.default.sep));
|
|
67
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
|
|
61
68
|
nativeModuleCodeGenerator
|
|
62
69
|
.generate(specSchema)
|
|
63
70
|
.forEach((fileContent, filePath) => {
|
|
@@ -50,16 +50,26 @@ class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
|
|
|
50
50
|
public:
|
|
51
51
|
void handleEvent(Context const &ctx) override {
|
|
52
52
|
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
53
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
54
|
+
|
|
53
55
|
if (eventEmitter == nullptr) {
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
std::vector<std::string> supportedComponentNames = {
|
|
60
|
+
{{#arkTSComponents}}
|
|
61
|
+
"{{name}}",
|
|
62
|
+
{{/arkTSComponents}}
|
|
63
|
+
};
|
|
64
|
+
|
|
57
65
|
std::vector<std::string> supportedEventNames = {
|
|
58
66
|
{{#arkTSEvents}}
|
|
59
67
|
"{{name}}",
|
|
60
68
|
{{/arkTSEvents}}
|
|
61
69
|
};
|
|
62
|
-
|
|
70
|
+
|
|
71
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
72
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
63
73
|
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
64
74
|
}
|
|
65
75
|
}
|
|
@@ -126,6 +136,7 @@ class BasePackageHTemplate {
|
|
|
126
136
|
name: this.name,
|
|
127
137
|
turboModules: this.turboModules,
|
|
128
138
|
components: this.components,
|
|
139
|
+
arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
|
|
129
140
|
arkTSEvents: this.arkTSEvents,
|
|
130
141
|
libraries: Array.from(this.libraryCppNames).map((name) => ({
|
|
131
142
|
name,
|
|
@@ -53,16 +53,26 @@ class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
|
53
53
|
public:
|
|
54
54
|
void handleEvent(Context const &ctx) override {
|
|
55
55
|
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
56
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
57
|
+
|
|
56
58
|
if (eventEmitter == nullptr) {
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
std::vector<std::string> supportedComponentNames = {
|
|
63
|
+
{{#arkTSComponents}}
|
|
64
|
+
"{{name}}",
|
|
65
|
+
{{/arkTSComponents}}
|
|
66
|
+
};
|
|
67
|
+
|
|
60
68
|
std::vector<std::string> supportedEventNames = {
|
|
61
69
|
{{#supportedEvents}}
|
|
62
70
|
"{{name}}",
|
|
63
71
|
{{/supportedEvents}}
|
|
64
72
|
};
|
|
65
|
-
|
|
73
|
+
|
|
74
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
75
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
66
76
|
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
67
77
|
}
|
|
68
78
|
}
|
|
@@ -121,6 +131,7 @@ class RNOHGeneratedPackageHTemplate {
|
|
|
121
131
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
122
132
|
turboModules: this.turboModules,
|
|
123
133
|
components: this.components,
|
|
134
|
+
arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
|
|
124
135
|
supportedEvents: this.supportedEventNames.map((eventName) => ({
|
|
125
136
|
name: eventName,
|
|
126
137
|
})),
|
|
@@ -30,7 +30,11 @@ exports.commandCodegenHarmony = {
|
|
|
30
30
|
options: [
|
|
31
31
|
{
|
|
32
32
|
name: '--rnoh-module-path <path>',
|
|
33
|
-
description: 'Specifies the relative path to the rnoh OHOS module',
|
|
33
|
+
description: '[deprecated] Specifies the relative path to the rnoh OHOS module',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: '--ets-output-path <path>',
|
|
37
|
+
description: 'Specifies the relative path to the output directory intended for storing generated ETS files.',
|
|
34
38
|
},
|
|
35
39
|
{
|
|
36
40
|
name: '--cpp-output-path <path>',
|
|
@@ -59,7 +63,12 @@ exports.commandCodegenHarmony = {
|
|
|
59
63
|
const MAX_SUPPORTED_CODEGEN_VERSION = 2;
|
|
60
64
|
// prepare the input data
|
|
61
65
|
validateArgs(args);
|
|
62
|
-
|
|
66
|
+
let etsOutputPath = args.etsOutputPath || args.rnohModulePath;
|
|
67
|
+
const isEndWithGenerated = /\/generated\/?$/.test(etsOutputPath);
|
|
68
|
+
etsOutputPath = new core_1.AbsolutePath(etsOutputPath);
|
|
69
|
+
if (!isEndWithGenerated) {
|
|
70
|
+
etsOutputPath = etsOutputPath.copyWithNewSegment('generated');
|
|
71
|
+
}
|
|
63
72
|
const enableSafetyCheck = args.safetyCheck;
|
|
64
73
|
const cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
|
|
65
74
|
const projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
|
|
@@ -116,11 +125,13 @@ exports.commandCodegenHarmony = {
|
|
|
116
125
|
}),
|
|
117
126
|
};
|
|
118
127
|
function validateArgs(args) {
|
|
119
|
-
if (!args.rnohModulePath) {
|
|
128
|
+
if (!args.rnohModulePath && !args.etsOutputPath) {
|
|
120
129
|
throw new core_1.DescriptiveError({
|
|
121
|
-
whatHappened:
|
|
130
|
+
whatHappened: '--ets-output-path is required',
|
|
122
131
|
whatCanUserDo: [
|
|
123
|
-
'Please provide
|
|
132
|
+
'Please provide an output path for the ETS file.',
|
|
133
|
+
'It is recommended to place it in the same directory as the custom component or TurboModule.',
|
|
134
|
+
'Do not place it inside @rnoh/react-native-openharmony, otherwise a jscrash may occur when using react_native_openharmony_release2.har.'
|
|
124
135
|
],
|
|
125
136
|
});
|
|
126
137
|
}
|
|
@@ -28,7 +28,10 @@ const json5_1 = __importDefault(require("json5"));
|
|
|
28
28
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
29
29
|
const path_1 = __importDefault(require("path"));
|
|
30
30
|
const cli_tools_1 = require("@react-native-community/cli-tools");
|
|
31
|
+
const simulator_1 = require("../simulator");
|
|
31
32
|
const COMMAND_NAME = 'run-harmony';
|
|
33
|
+
const LOOPBACK_IP = '127.0.0.1';
|
|
34
|
+
const DEFAULT_SIMULATOR_NAME = `${LOOPBACK_IP}:5555`;
|
|
32
35
|
exports.commandRunHarmony = {
|
|
33
36
|
name: COMMAND_NAME,
|
|
34
37
|
description: 'Builds your app and starts it on your phone.',
|
|
@@ -112,7 +115,7 @@ exports.commandRunHarmony = {
|
|
|
112
115
|
const buildMode = rawArgs.buildMode;
|
|
113
116
|
const moduleName = rawArgs.module;
|
|
114
117
|
const abilityName = rawArgs.ability;
|
|
115
|
-
|
|
118
|
+
let simulatorName = rawArgs.simulator;
|
|
116
119
|
const defaultPort = rawArgs.port;
|
|
117
120
|
const packager = rawArgs.packager;
|
|
118
121
|
const devEcoStudioToolsPath = new core_1.AbsolutePath(DEVECO_SDK_HOME).copyWithNewSegment('..', 'tools');
|
|
@@ -122,6 +125,19 @@ exports.commandRunHarmony = {
|
|
|
122
125
|
});
|
|
123
126
|
}
|
|
124
127
|
const bundleName = json5_1.default.parse(fs.readTextSync(harmonyProjectPath.copyWithNewSegment('AppScope', 'app.json5'))).app.bundleName;
|
|
128
|
+
let currentPort = defaultPort;
|
|
129
|
+
if (packager) {
|
|
130
|
+
const root = _config.root || '.';
|
|
131
|
+
const reactNativePath = _config.reactNativePath || path_1.default.dirname(require.resolve('react-native', { paths: [root] }));
|
|
132
|
+
const { port: newPort, startPackager } = yield (0, cli_tools_1.findDevServerPort)(defaultPort, root);
|
|
133
|
+
if (newPort !== 8081) {
|
|
134
|
+
yield trySetMetroPort(harmonyProjectPath.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets').toString(), newPort);
|
|
135
|
+
}
|
|
136
|
+
if (startPackager) {
|
|
137
|
+
(0, cli_tools_1.startServerInNewWindow)(newPort, root, reactNativePath, (0, cli_tools_1.getDefaultUserTerminal)());
|
|
138
|
+
}
|
|
139
|
+
currentPort = newPort;
|
|
140
|
+
}
|
|
125
141
|
const selectDevice = (deviceAndSimulatorInfos) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
142
|
const lines = deviceAndSimulatorInfos.trim().split('\n');
|
|
127
143
|
const availableDevices = lines.map((line) => {
|
|
@@ -147,6 +163,9 @@ exports.commandRunHarmony = {
|
|
|
147
163
|
return simulatorName;
|
|
148
164
|
}
|
|
149
165
|
const connectedDevices = availableDevices.filter((deviceOrSimulator) => deviceOrSimulator.state === 'Connected');
|
|
166
|
+
if (connectedDevices.length === 1) {
|
|
167
|
+
return connectedDevices[0].name;
|
|
168
|
+
}
|
|
150
169
|
if (connectedDevices.length > 1) {
|
|
151
170
|
const answers = yield inquirer_1.default.prompt([
|
|
152
171
|
{
|
|
@@ -158,15 +177,32 @@ exports.commandRunHarmony = {
|
|
|
158
177
|
]);
|
|
159
178
|
return connectedDevices[parseInt(answers.selectedDeviceIndex) - 1].name;
|
|
160
179
|
}
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
try {
|
|
181
|
+
yield (0, simulator_1.launchHarmonySimulator)({
|
|
182
|
+
devEcoStudioToolsPath,
|
|
183
|
+
sdkToolchainsPath,
|
|
184
|
+
cli,
|
|
185
|
+
logger,
|
|
186
|
+
env: process.env,
|
|
187
|
+
});
|
|
188
|
+
simulatorName = DEFAULT_SIMULATOR_NAME;
|
|
189
|
+
return simulatorName;
|
|
163
190
|
}
|
|
164
|
-
|
|
191
|
+
catch (e) {
|
|
192
|
+
if (e instanceof core_1.DescriptiveError) {
|
|
193
|
+
throw new core_1.DescriptiveError({
|
|
194
|
+
whatHappened: `${e.getMessage()} \n No devices are connected. Failed to auto-launch simulator.`,
|
|
195
|
+
whatCanUserDo: [...e.getSuggestions()],
|
|
196
|
+
extraData: e.getRawData().extraData,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
165
199
|
throw new core_1.DescriptiveError({
|
|
166
|
-
whatHappened: `No devices are connected in the current environment.`,
|
|
200
|
+
whatHappened: `No devices are connected in the current environment (auto-launch attempt failed).`,
|
|
167
201
|
whatCanUserDo: [
|
|
168
|
-
'
|
|
169
|
-
|
|
202
|
+
'Connect a HarmonyOS device via USB or start the simulator manually.',
|
|
203
|
+
'Re-run the command after a device is listed by: hdc list targets -v',
|
|
204
|
+
],
|
|
205
|
+
extraData: e,
|
|
170
206
|
});
|
|
171
207
|
}
|
|
172
208
|
});
|
|
@@ -175,18 +211,8 @@ exports.commandRunHarmony = {
|
|
|
175
211
|
cwd: harmonyProjectPath,
|
|
176
212
|
});
|
|
177
213
|
const deviceOrSimulatorName = yield selectDevice(deviceAndSimulatorInfo);
|
|
178
|
-
|
|
179
|
-
|
|
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;
|
|
214
|
+
if (deviceOrSimulatorName.includes(`${LOOPBACK_IP}:`)) {
|
|
215
|
+
simulatorName = deviceOrSimulatorName;
|
|
190
216
|
}
|
|
191
217
|
const runJob = (name, job) => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
218
|
const stop = logger.start((s) => s.bold(name));
|
|
@@ -215,13 +241,10 @@ exports.commandRunHarmony = {
|
|
|
215
241
|
ohpmPath = devEcoStudioToolsPath
|
|
216
242
|
.copyWithNewSegment('ohpm', 'bin', 'ohpm.bat');
|
|
217
243
|
}
|
|
218
|
-
yield cli.run(
|
|
219
|
-
ohpmPath.toString(), {
|
|
244
|
+
yield cli.run(`"${ohpmPath.toString()}"`, {
|
|
220
245
|
args: [
|
|
221
246
|
'install',
|
|
222
247
|
'--all',
|
|
223
|
-
'--strict_ssl',
|
|
224
|
-
'true',
|
|
225
248
|
],
|
|
226
249
|
cwd: harmonyProjectPath,
|
|
227
250
|
shell: true,
|
|
@@ -243,9 +266,8 @@ exports.commandRunHarmony = {
|
|
|
243
266
|
nodePath = devEcoStudioToolsPath.copyWithNewSegment('node', 'node');
|
|
244
267
|
}
|
|
245
268
|
let hvigorPathRaw = devEcoStudioToolsPath.copyWithNewSegment('hvigor', 'bin', 'hvigorw.js').toString();
|
|
246
|
-
const hvigorPath =
|
|
247
|
-
yield cli.run(
|
|
248
|
-
nodePath.toString(), {
|
|
269
|
+
const hvigorPath = `"${hvigorPathRaw}"`;
|
|
270
|
+
yield cli.run(`"${nodePath.toString()}"`, {
|
|
249
271
|
args: [
|
|
250
272
|
hvigorPath,
|
|
251
273
|
`-p`,
|
|
@@ -294,7 +316,7 @@ exports.commandRunHarmony = {
|
|
|
294
316
|
const hdcPathStrRaw = sdkToolchainsPath
|
|
295
317
|
.copyWithNewSegment('hdc')
|
|
296
318
|
.toString();
|
|
297
|
-
const hdcPathStr =
|
|
319
|
+
const hdcPathStr = `"${hdcPathStrRaw.toString()}"`;
|
|
298
320
|
const tryRemoveForwardPorting = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
299
321
|
let fportInfo = '';
|
|
300
322
|
yield cli.run(hdcPathStrRaw, {
|
|
@@ -29,16 +29,14 @@ class ProjectDependency {
|
|
|
29
29
|
getCodegenConfigs() {
|
|
30
30
|
return this.readPackageJSON().getCodegenConfigs();
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
getHarFilePaths() {
|
|
33
33
|
const packageHarmonyPath = this.packageRootPath.copyWithNewSegment('harmony');
|
|
34
|
-
if (
|
|
35
|
-
return
|
|
34
|
+
if (this.fs.existsSync(packageHarmonyPath)) {
|
|
35
|
+
return this.fs.findFilePathsWithExtensions(packageHarmonyPath, ['har']);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return null;
|
|
37
|
+
else {
|
|
38
|
+
return this.fs.findFilePathsWithExtensions(this.packageRootPath, ['har']);
|
|
40
39
|
}
|
|
41
|
-
return harFilePaths[0];
|
|
42
40
|
}
|
|
43
41
|
readPackageJSON() {
|
|
44
42
|
return PackageJSON_1.PackageJSON.fromProjectRootPath(this.fs, this.packageRootPath, this.projectRootPath);
|