@react-native-oh/react-native-harmony-cli 0.0.36 → 0.77.18-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/LICENSE +21 -0
- package/README.md +4 -4
- package/dist/autolinking/Autolinking.js +13 -16
- package/dist/autolinking/index.js +0 -6
- package/dist/codegen/core/CodeGenerator.js +0 -6
- package/dist/codegen/core/CodegenError.js +0 -6
- package/dist/codegen/core/EventUtils.js +0 -6
- package/dist/codegen/core/TypeAnnotationToTS.js +0 -6
- package/dist/codegen/core/UberSchema.js +2 -11
- package/dist/codegen/core/index.js +0 -6
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -7
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +0 -6
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +0 -6
- package/dist/codegen/generators/CppComponentCodeGenerator.js +0 -6
- package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -8
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +1 -7
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +0 -6
- package/dist/codegen/generators/UberGeneratorV1.js +0 -6
- package/dist/codegen/generators/UberGeneratorV2.js +0 -6
- package/dist/codegen/generators/index.js +0 -6
- package/dist/codegen/index.js +0 -6
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +0 -6
- package/dist/codegen/templates/BasePackageHTemplate.js +12 -7
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +1 -6
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -6
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -6
- package/dist/codegen/templates/IndexTSTemplate.js +0 -6
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -7
- package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -6
- package/dist/codegen/templates/TurboModuleHTemplate.js +0 -6
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -6
- package/dist/codegen/templates/index.js +0 -6
- package/dist/commands/bundle-harmony.js +131 -36
- package/dist/commands/clean-harmony.js +84 -0
- package/dist/commands/codegen-harmony.js +0 -6
- package/dist/commands/codegen-lib-harmony.js +6 -12
- package/dist/commands/index.js +2 -9
- package/dist/commands/init-harmony.js +226 -0
- package/dist/commands/init.js +0 -0
- package/dist/commands/link-harmony.js +12 -16
- package/dist/commands/types.js +0 -6
- package/dist/commands/verify-package-harmony.js +6 -10
- package/dist/core/AbsolutePath.js +3 -6
- package/dist/core/CodegenConfig.js +0 -6
- package/dist/core/DescriptiveError.js +0 -6
- package/dist/core/FileSystem.js +0 -6
- package/dist/core/OHPackageJSON5.js +0 -6
- package/dist/core/ProjectDependenciesManager.js +6 -14
- package/dist/core/ValidationError.js +0 -6
- package/dist/core/ValueObject.js +0 -6
- package/dist/core/fs.js +13 -6
- package/dist/core/index.js +0 -6
- package/dist/index.js +2 -9
- package/dist/init/templates/AppScopeAppJSON5Template.js +30 -0
- package/dist/init/templates/AppScopeStringVarTemplate.js +28 -0
- package/dist/init/templates/EntryIndexTemplate.js +65 -0
- package/dist/init/templates/EntryStringVarTemplate.js +38 -0
- package/dist/init/templates/HvigorConfigJson5Template.js +44 -0
- package/dist/init/templates/MetroConfigTemplate.js +47 -0
- package/dist/init/templates/OhPackageJson5Template.js +37 -0
- package/dist/init/templates/harmony/AppScope/app.json5 +10 -0
- package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
- package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
- package/dist/init/templates/harmony/build-profile.json5 +36 -0
- package/dist/init/templates/harmony/codelinter.json +32 -0
- package/dist/init/templates/harmony/entry/build-profile.json5 +18 -0
- package/dist/init/templates/harmony/entry/gitignore +7 -0
- package/dist/init/templates/harmony/entry/hvigorfile.ts +13 -0
- package/dist/init/templates/harmony/entry/oh-package.json5 +9 -0
- package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
- package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
- package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
- package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
- package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
- package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
- package/dist/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
- 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 +16 -0
- package/dist/init/templates/harmony/entry/src/main/module.json5 +58 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
- 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 +7 -0
- 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 +5 -0
- package/dist/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
- package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
- package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
- package/dist/init/templates/harmony/gitignore +16 -0
- package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
- package/dist/init/templates/harmony/hvigorfile.ts +7 -0
- package/dist/init/templates/index.js +21 -0
- package/dist/io/CliExecutor.js +0 -6
- package/dist/io/Logger.js +0 -6
- package/dist/io/RealFS.js +10 -6
- package/dist/io/TarGz.js +2 -8
- package/dist/io/__fixtures__.js +0 -6
- package/dist/io/fsUtils.js +0 -6
- package/dist/io/index.js +1 -6
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +0 -6
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +0 -6
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +0 -6
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +0 -6
- package/dist/package-verifier/checks/index.js +0 -6
- package/dist/package-verifier/index.js +0 -6
- package/dist/package-verifier/types.js +0 -6
- package/dist/package-verifier/verify-package.js +1 -7
- package/harmony/rnoh-hvigor-plugin-0.77.18.tgz +0 -0
- package/jest.config.js +0 -7
- package/package.json +15 -18
- package/react-native.config.js +0 -7
- package/scripts/copy-template.js +18 -0
- package/src/autolinking/Autolinking.test.ts +54 -18
- package/src/autolinking/Autolinking.ts +23 -20
- package/src/autolinking/index.ts +1 -8
- package/src/codegen/core/CodeGenerator.ts +0 -7
- package/src/codegen/core/CodegenError.ts +0 -7
- package/src/codegen/core/EventUtils.ts +0 -7
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -7
- package/src/codegen/core/TypeAnnotationToTS.ts +3 -8
- package/src/codegen/core/UberSchema.ts +3 -12
- package/src/codegen/core/index.ts +0 -7
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -8
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -7
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -7
- package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -7
- package/src/codegen/generators/LibGlueCodeGenerator.ts +2 -9
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +1 -8
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -7
- package/src/codegen/generators/UberGeneratorV1.ts +0 -7
- package/src/codegen/generators/UberGeneratorV2.ts +0 -7
- package/src/codegen/generators/index.ts +0 -7
- package/src/codegen/index.ts +0 -7
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -7
- package/src/codegen/templates/BasePackageHTemplate.ts +13 -8
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +1 -7
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -7
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -7
- package/src/codegen/templates/IndexTSTemplate.ts +0 -7
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +13 -8
- package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -7
- package/src/codegen/templates/TurboModuleHTemplate.ts +0 -7
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -7
- package/src/codegen/templates/index.ts +0 -7
- package/src/commands/bundle-harmony.ts +174 -39
- package/src/commands/clean-harmony.ts +54 -0
- package/src/commands/codegen-harmony.ts +0 -7
- package/src/commands/codegen-lib-harmony.ts +6 -13
- package/src/commands/index.ts +2 -10
- package/src/commands/init-harmony.ts +299 -0
- package/src/commands/link-harmony.ts +13 -18
- package/src/commands/types.ts +0 -7
- package/src/commands/verify-package-harmony.ts +7 -10
- package/src/core/AbsolutePath.ts +4 -7
- package/src/core/CodegenConfig.ts +0 -7
- package/src/core/DescriptiveError.ts +0 -7
- package/src/core/FileSystem.ts +5 -8
- package/src/core/OHPackageJSON5.ts +0 -7
- package/src/core/PackageJSON.ts +0 -6
- package/src/core/ProjectDependenciesManager.ts +14 -22
- package/src/core/ValidationError.ts +0 -7
- package/src/core/ValueObject.ts +0 -7
- package/src/core/fs.ts +13 -7
- package/src/core/index.ts +0 -7
- package/src/index.ts +4 -13
- package/src/init/templates/AppScopeAppJSON5Template.ts +24 -0
- package/src/init/templates/AppScopeStringVarTemplate.ts +22 -0
- package/src/init/templates/EntryIndexTemplate.ts +59 -0
- package/src/init/templates/EntryStringVarTemplate.ts +31 -0
- package/src/init/templates/HvigorConfigJson5Template.ts +40 -0
- package/src/init/templates/MetroConfigTemplate.ts +41 -0
- package/src/init/templates/OhPackageJson5Template.ts +31 -0
- package/src/init/templates/harmony/AppScope/app.json5 +10 -0
- package/src/init/templates/harmony/AppScope/resources/base/element/string.json +8 -0
- package/src/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
- package/src/init/templates/harmony/build-profile.json5 +36 -0
- package/src/init/templates/harmony/codelinter.json +32 -0
- package/src/init/templates/harmony/entry/build-profile.json5 +18 -0
- package/src/init/templates/harmony/entry/gitignore +7 -0
- package/src/init/templates/harmony/entry/hvigorfile.ts +13 -0
- package/src/init/templates/harmony/entry/oh-package.json5 +9 -0
- package/src/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
- package/src/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
- package/src/init/templates/harmony/entry/src/main/cpp/gitignore +4 -0
- package/src/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
- package/src/init/templates/harmony/entry/src/main/ets/codegen/gitignore +2 -0
- package/src/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
- package/src/init/templates/harmony/entry/src/main/ets/gitignore +1 -0
- package/src/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
- package/src/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
- package/src/init/templates/harmony/entry/src/main/module.json5 +58 -0
- package/src/init/templates/harmony/entry/src/main/resources/base/element/color.json +8 -0
- package/src/init/templates/harmony/entry/src/main/resources/base/element/string.json +16 -0
- package/src/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
- package/src/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
- package/src/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
- package/src/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/src/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
- package/src/init/templates/harmony/entry/src/main/resources/gitignore +1 -0
- package/src/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
- package/src/init/templates/harmony/entry/src/ohosTest/module.json5 +13 -0
- package/src/init/templates/harmony/gitignore +16 -0
- package/src/init/templates/harmony/hvigor/hvigor-config.json5 +22 -0
- package/src/init/templates/harmony/hvigorfile.ts +7 -0
- package/src/init/templates/index.ts +5 -0
- package/src/io/CliExecutor.ts +1 -8
- package/src/io/Logger.ts +0 -7
- package/src/io/RealFS.ts +15 -8
- package/src/io/TarGz.ts +1 -8
- package/src/io/__fixtures__.ts +1 -8
- package/src/io/fsUtils.ts +1 -7
- package/src/io/index.ts +1 -7
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -7
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -7
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -7
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -7
- package/src/package-verifier/checks/index.ts +0 -7
- package/src/package-verifier/index.ts +0 -7
- package/src/package-verifier/types.ts +0 -7
- package/src/package-verifier/verify-package.ts +0 -7
- package/tsconfig.build.json +2 -5
- package/tsconfig.json +4 -0
- package/dist/commands/create-metro-host-constants.js +0 -67
- package/dist/commands/pack-harmony.js +0 -106
- package/dist/commands/unpack-harmony.js +0 -189
- package/src/commands/create-metro-host-constants.ts +0 -55
- package/src/commands/pack-harmony.ts +0 -128
- package/src/commands/unpack-harmony.ts +0 -238
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
import mustache from 'mustache';
|
|
9
2
|
import Case from 'case';
|
|
10
3
|
import { TypeAnnotation } from '../core';
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
import mustache from 'mustache';
|
|
9
2
|
|
|
10
3
|
const TEMPLATE = `
|
|
@@ -46,16 +39,26 @@ class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
|
|
|
46
39
|
public:
|
|
47
40
|
void handleEvent(Context const &ctx) override {
|
|
48
41
|
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
42
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
43
|
+
|
|
49
44
|
if (eventEmitter == nullptr) {
|
|
50
45
|
return;
|
|
51
46
|
}
|
|
52
47
|
|
|
48
|
+
std::vector<std::string> supportedComponentNames = {
|
|
49
|
+
{{#arkTSComponents}}
|
|
50
|
+
"{{name}}",
|
|
51
|
+
{{/arkTSComponents}}
|
|
52
|
+
};
|
|
53
|
+
|
|
53
54
|
std::vector<std::string> supportedEventNames = {
|
|
54
55
|
{{#arkTSEvents}}
|
|
55
56
|
"{{name}}",
|
|
56
57
|
{{/arkTSEvents}}
|
|
57
58
|
};
|
|
58
|
-
|
|
59
|
+
|
|
60
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
61
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
59
62
|
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
60
63
|
}
|
|
61
64
|
}
|
|
@@ -103,6 +106,7 @@ type GeneratedPackageTurboModule = {
|
|
|
103
106
|
type GeneratedPackageComponent = {
|
|
104
107
|
name: string;
|
|
105
108
|
libraryCppName: string;
|
|
109
|
+
isArkTSComponent: boolean;
|
|
106
110
|
};
|
|
107
111
|
|
|
108
112
|
type ArkTSEvent = {
|
|
@@ -138,6 +142,7 @@ export class BasePackageHTemplate {
|
|
|
138
142
|
name: this.name,
|
|
139
143
|
turboModules: this.turboModules,
|
|
140
144
|
components: this.components,
|
|
145
|
+
arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
|
|
141
146
|
arkTSEvents: this.arkTSEvents,
|
|
142
147
|
libraries: Array.from(this.libraryCppNames).map((name) => ({
|
|
143
148
|
name,
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
import mustache from 'mustache';
|
|
9
2
|
|
|
10
3
|
const TEMPLATE = `
|
|
@@ -26,6 +19,7 @@ const TEMPLATE = `
|
|
|
26
19
|
namespace facebook {
|
|
27
20
|
namespace react {
|
|
28
21
|
|
|
22
|
+
// RNOH patch
|
|
29
23
|
constexpr char {{name}}ComponentName[] = "{{name}}";
|
|
30
24
|
|
|
31
25
|
class {{name}}Props : public ViewProps {
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
import mustache from 'mustache';
|
|
9
2
|
|
|
10
3
|
const TEMPLATE = `
|
|
@@ -49,16 +42,26 @@ class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
|
49
42
|
public:
|
|
50
43
|
void handleEvent(Context const &ctx) override {
|
|
51
44
|
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
45
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
46
|
+
|
|
52
47
|
if (eventEmitter == nullptr) {
|
|
53
48
|
return;
|
|
54
49
|
}
|
|
55
50
|
|
|
51
|
+
std::vector<std::string> supportedComponentNames = {
|
|
52
|
+
{{#arkTSComponents}}
|
|
53
|
+
"{{name}}",
|
|
54
|
+
{{/arkTSComponents}}
|
|
55
|
+
};
|
|
56
|
+
|
|
56
57
|
std::vector<std::string> supportedEventNames = {
|
|
57
58
|
{{#supportedEvents}}
|
|
58
59
|
"{{name}}",
|
|
59
60
|
{{/supportedEvents}}
|
|
60
61
|
};
|
|
61
|
-
|
|
62
|
+
|
|
63
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
64
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
62
65
|
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
63
66
|
}
|
|
64
67
|
}
|
|
@@ -105,6 +108,7 @@ type RNOHGeneratedPackageTurboModule = {
|
|
|
105
108
|
type RNOHGeneratedPackageComponent = {
|
|
106
109
|
name: string;
|
|
107
110
|
supportedEventNames: string[];
|
|
111
|
+
isArkTSComponent: boolean;
|
|
108
112
|
};
|
|
109
113
|
|
|
110
114
|
export class RNOHGeneratedPackageHTemplate {
|
|
@@ -130,6 +134,7 @@ export class RNOHGeneratedPackageHTemplate {
|
|
|
130
134
|
return mustache.render(TEMPLATE.trimStart(), {
|
|
131
135
|
turboModules: this.turboModules,
|
|
132
136
|
components: this.components,
|
|
137
|
+
arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
|
|
133
138
|
supportedEvents: this.supportedEventNames.map((eventName) => ({
|
|
134
139
|
name: eventName,
|
|
135
140
|
})),
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
export * from './TurboModuleHTemplate';
|
|
9
2
|
export * from './TurboModuleCppTemplate';
|
|
10
3
|
export * from './RNOHGeneratedPackageHTemplate';
|
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
import { Command } from './types';
|
|
9
|
-
import fs from 'fs';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'os';
|
|
10
4
|
import fse from 'fs-extra';
|
|
11
5
|
import Metro from 'metro';
|
|
12
6
|
import { RunBuildOptions as BuildOptions } from 'metro';
|
|
13
7
|
import MetroServer from 'metro/src/Server';
|
|
14
8
|
import pathUtils from 'path';
|
|
15
9
|
import { copyAssets } from '../assetResolver';
|
|
16
|
-
import {
|
|
10
|
+
import { execSync } from 'child_process';
|
|
17
11
|
import { Logger } from '../io';
|
|
12
|
+
import { DescriptiveError } from '../core';
|
|
13
|
+
import { randomUUID } from 'node:crypto';
|
|
14
|
+
|
|
15
|
+
type MetroConfig = Awaited<ReturnType<typeof Metro.loadConfig>>;
|
|
18
16
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
'
|
|
17
|
+
const HERMESC_BIN_PATH = {
|
|
18
|
+
darwin: pathUtils.normalize('osx-bin/hermesc'),
|
|
19
|
+
linux: pathUtils.normalize('linux64-bin/hermesc'),
|
|
20
|
+
win32: pathUtils.normalize('win64-bin/hermesc.exe'),
|
|
21
|
+
};
|
|
22
|
+
const HERMESC_PATH_PREFIX = pathUtils.normalize(
|
|
23
|
+
'./node_modules/react-native/sdks/hermesc/'
|
|
24
|
+
);
|
|
25
|
+
const HARMONY_RESOURCE_PATH = pathUtils.normalize(
|
|
26
|
+
'./harmony/entry/src/main/resources/rawfile'
|
|
27
|
+
);
|
|
28
|
+
const ASSETS_DEFAULT_DEST_PATH = pathUtils.normalize(
|
|
29
|
+
'./harmony/entry/src/main/resources/rawfile/assets'
|
|
30
|
+
);
|
|
22
31
|
|
|
23
32
|
type AssetData = Metro.AssetData;
|
|
24
33
|
type Bundle = { code: string; map: string };
|
|
25
34
|
type Path = string;
|
|
35
|
+
type OSType = 'darwin' | 'linux' | 'win32';
|
|
26
36
|
|
|
27
37
|
export const commandBundleHarmony: Command = {
|
|
28
38
|
name: 'bundle-harmony',
|
|
@@ -40,58 +50,131 @@ export const commandBundleHarmony: Command = {
|
|
|
40
50
|
description:
|
|
41
51
|
'Path to the root JS file, either absolute or relative to JS root',
|
|
42
52
|
default: 'index.js',
|
|
53
|
+
parse: (val: string) => pathUtils.normalize(val),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: '--reset-cache',
|
|
57
|
+
description: 'Removes cached files',
|
|
58
|
+
default: false,
|
|
43
59
|
},
|
|
44
60
|
{
|
|
45
61
|
name: '--config <path>',
|
|
46
62
|
description: 'Path to the Metro configuration file',
|
|
63
|
+
parse: (val: string) => pathUtils.normalize(val),
|
|
47
64
|
},
|
|
48
65
|
{
|
|
49
66
|
name: '--bundle-output <path>',
|
|
67
|
+
description: `File path where to store the resulting bundle (default: "${HARMONY_RESOURCE_PATH}${pathUtils.sep}bundle.harmony.js")`,
|
|
68
|
+
parse: (val: string) => pathUtils.normalize(val),
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: '--js-engine <string>',
|
|
50
72
|
description:
|
|
51
|
-
'
|
|
52
|
-
default:
|
|
73
|
+
'JavaScript engine used to run the bundle. Supported engines: "hermes" and "any" (default: "any"). Setting this option to "hermes" will generate a HBC bundle instead of a JS bundle.',
|
|
74
|
+
default: 'any',
|
|
75
|
+
parse: (val: string) => {
|
|
76
|
+
if (val !== 'any' && val !== 'hermes') {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Only "any" and "hermes" are supported as JavaScript engines, but "${val}" was provided`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return val;
|
|
82
|
+
},
|
|
53
83
|
},
|
|
54
84
|
{
|
|
55
85
|
name: '--assets-dest <path>',
|
|
56
86
|
description:
|
|
57
87
|
'Directory name where to store assets referenced in the bundle',
|
|
58
88
|
default: ASSETS_DEFAULT_DEST_PATH,
|
|
89
|
+
parse: (val: string) => pathUtils.normalize(val),
|
|
59
90
|
},
|
|
60
91
|
{
|
|
61
92
|
name: '--sourcemap-output <path>',
|
|
62
93
|
description:
|
|
63
94
|
'File name where to store the resulting source map, ex. /tmp/groups.map',
|
|
95
|
+
parse: (val: string) => pathUtils.normalize(val),
|
|
64
96
|
},
|
|
65
97
|
{
|
|
66
98
|
name: '--minify [boolean]',
|
|
67
99
|
description: 'Allows overriding whether bundle is minified',
|
|
68
100
|
parse: (val: string) => val !== 'false',
|
|
69
101
|
},
|
|
102
|
+
{
|
|
103
|
+
name: '--hermesc-dir <path>',
|
|
104
|
+
description:
|
|
105
|
+
'Path to hermesc directory. Relevant when --js-engine set to "hermes".',
|
|
106
|
+
default: HERMESC_PATH_PREFIX,
|
|
107
|
+
parse: (val: string) => pathUtils.normalize(val),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: '--hermesc-options <string...>',
|
|
111
|
+
description:
|
|
112
|
+
'Additional options to pass to hermesc when generating HBC bundle. Example: --hermesc-options O g reuse-prop-cache. Relevant when --js-engine set to "hermes".',
|
|
113
|
+
parse: (val, prev) => (prev ? [...prev, val] : [val]),
|
|
114
|
+
},
|
|
70
115
|
],
|
|
71
116
|
func: async (argv, config, args: any) => {
|
|
72
117
|
const logger = new Logger();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
try {
|
|
119
|
+
const defaultBundleName =
|
|
120
|
+
args.jsEngine === 'hermes' ? 'hermes_bundle.hbc' : 'bundle.harmony.js';
|
|
121
|
+
const bundleOutput: string =
|
|
122
|
+
args.bundleOutput ??
|
|
123
|
+
`${HARMONY_RESOURCE_PATH}${pathUtils.sep}${defaultBundleName}`;
|
|
124
|
+
const shouldGenerateHbcBundle = bundleOutput
|
|
125
|
+
.toLowerCase()
|
|
126
|
+
.endsWith('hbc');
|
|
127
|
+
await fse.ensureDir(pathUtils.dirname(bundleOutput));
|
|
128
|
+
const assetsDest: Path = args.assetsDest;
|
|
129
|
+
await fse.ensureDir(assetsDest);
|
|
130
|
+
const buildOptions: BuildOptions = {
|
|
131
|
+
entry: args.entryFile,
|
|
132
|
+
platform: 'harmony',
|
|
133
|
+
minify: args.minify !== undefined ? args.minify : !args.dev,
|
|
134
|
+
dev: args.dev,
|
|
135
|
+
sourceMap: args.sourcemapOutput,
|
|
136
|
+
sourceMapUrl: args.sourcemapOutput,
|
|
137
|
+
};
|
|
138
|
+
const metroConfig = await loadMetroConfig({
|
|
139
|
+
config: args.config,
|
|
140
|
+
resetCache: args.resetCache,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const bundle = await createBundle(metroConfig, buildOptions);
|
|
144
|
+
const assets = await retrieveAssetsData(metroConfig, buildOptions);
|
|
145
|
+
|
|
146
|
+
if (shouldGenerateHbcBundle) {
|
|
147
|
+
await saveHbcBundle(
|
|
148
|
+
logger,
|
|
149
|
+
bundle.code,
|
|
150
|
+
bundleOutput,
|
|
151
|
+
args.hermescDir,
|
|
152
|
+
args.hermescOptions
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
await saveJSBundle(logger, bundle, bundleOutput);
|
|
156
|
+
}
|
|
157
|
+
maybeSaveSourceMap(logger, bundle, args.sourcemapOutput);
|
|
158
|
+
await copyAssets(logger, assets, assetsDest);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if (err instanceof DescriptiveError) {
|
|
161
|
+
logger.descriptiveError(err);
|
|
162
|
+
return;
|
|
163
|
+
} else {
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
86
167
|
},
|
|
87
168
|
};
|
|
88
169
|
|
|
89
|
-
async function loadMetroConfig(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
170
|
+
async function loadMetroConfig(options: {
|
|
171
|
+
config: Path | undefined;
|
|
172
|
+
resetCache: boolean;
|
|
173
|
+
}): Promise<MetroConfig> {
|
|
174
|
+
if (!options.config) {
|
|
175
|
+
delete options.config;
|
|
176
|
+
}
|
|
177
|
+
return await Metro.loadConfig(options);
|
|
95
178
|
}
|
|
96
179
|
|
|
97
180
|
async function createBundle(
|
|
@@ -103,17 +186,68 @@ async function createBundle(
|
|
|
103
186
|
return (await Metro.runBuild(metroConfig, buildOptions)) as unknown as Bundle;
|
|
104
187
|
}
|
|
105
188
|
|
|
106
|
-
async function
|
|
107
|
-
|
|
189
|
+
async function saveHbcBundle(
|
|
190
|
+
logger: Logger,
|
|
191
|
+
bundleCode: string,
|
|
108
192
|
bundleOutput: Path,
|
|
109
|
-
|
|
193
|
+
hermescPath: string,
|
|
194
|
+
hermescOptions: string[] | undefined
|
|
195
|
+
) {
|
|
196
|
+
if (
|
|
197
|
+
process.platform !== 'darwin' &&
|
|
198
|
+
process.platform !== 'linux' &&
|
|
199
|
+
process.platform !== 'win32'
|
|
200
|
+
) {
|
|
201
|
+
throw new Error(`Unsupported platform ${process.platform} (⊙︿⊙)`);
|
|
202
|
+
}
|
|
203
|
+
const resolvedHermescPath = pathUtils.resolve(
|
|
204
|
+
hermescPath,
|
|
205
|
+
HERMESC_BIN_PATH[process.platform as OSType]
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (!fs.existsSync(resolvedHermescPath)) {
|
|
209
|
+
throw new DescriptiveError({
|
|
210
|
+
whatHappened: `Couldn't find hermesc at ${resolvedHermescPath}`,
|
|
211
|
+
whatCanUserDo: [
|
|
212
|
+
'Find hermesc dir and provide it by using --hermesc-dir argument. hermesc dir should be in react-native package.',
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const tmpBundlePath = `${os.tmpdir()}${pathUtils.sep}b-${randomUUID()}.harmony.js`;
|
|
218
|
+
await fse.writeFile(tmpBundlePath, bundleCode);
|
|
219
|
+
const hbcFilePath = bundleOutput.endsWith('.hbc')
|
|
220
|
+
? bundleOutput
|
|
221
|
+
: pathUtils.join(pathUtils.dirname(bundleOutput), 'hermes_bundle.hbc');
|
|
222
|
+
const hermescOptionsString =
|
|
223
|
+
hermescOptions?.map((e) => `-${e}`).join(' ') || '';
|
|
224
|
+
execSync(
|
|
225
|
+
`${resolvedHermescPath} ${hermescOptionsString} --emit-binary -out ${hbcFilePath} ${tmpBundlePath}`,
|
|
226
|
+
{
|
|
227
|
+
stdio: 'inherit',
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
fs.unlinkSync(tmpBundlePath);
|
|
231
|
+
logger.info((s) => `Created ${hbcFilePath}`);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function saveJSBundle(
|
|
235
|
+
logger: Logger,
|
|
236
|
+
bundle: Bundle,
|
|
237
|
+
bundleOutput: Path
|
|
110
238
|
) {
|
|
111
|
-
await fse.ensureDir(pathUtils.dirname(bundleOutput));
|
|
112
239
|
fs.writeFileSync(bundleOutput, bundle.code);
|
|
113
|
-
|
|
240
|
+
logger.info((s) => `Created ${bundleOutput}`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function maybeSaveSourceMap(
|
|
244
|
+
logger: Logger,
|
|
245
|
+
bundle: Bundle,
|
|
246
|
+
sourceMapOutput: Path | undefined
|
|
247
|
+
) {
|
|
114
248
|
if (sourceMapOutput) {
|
|
115
249
|
fs.writeFileSync(sourceMapOutput, bundle.map);
|
|
116
|
-
|
|
250
|
+
logger.info((s) => `Created ${sourceMapOutput}`);
|
|
117
251
|
}
|
|
118
252
|
}
|
|
119
253
|
|
|
@@ -127,6 +261,7 @@ async function retrieveAssetsData(
|
|
|
127
261
|
...MetroServer.DEFAULT_BUNDLE_OPTIONS,
|
|
128
262
|
...buildOptions,
|
|
129
263
|
entryFile: buildOptions.entry,
|
|
264
|
+
bundleType: 'todo',
|
|
130
265
|
});
|
|
131
266
|
} finally {
|
|
132
267
|
metroServer.end();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AbsolutePath, maybeReadFile } from '../core';
|
|
2
|
+
import { Command } from './types';
|
|
3
|
+
import JSON5 from 'json5';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import * as crypto from 'node:crypto';
|
|
8
|
+
|
|
9
|
+
const COMMAND_NAME = 'clean-harmony';
|
|
10
|
+
export const commandCleanHarmony: Command = {
|
|
11
|
+
name: COMMAND_NAME,
|
|
12
|
+
description: 'Remove cached files in the OpenHarmony project.',
|
|
13
|
+
options: [
|
|
14
|
+
{
|
|
15
|
+
name: "--harmony-project-path <path>",
|
|
16
|
+
description: "Specifies the root of your OpenHarmony project.",
|
|
17
|
+
default: "./harmony"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
func: async (_argv, _config, rawArgs: any) => {
|
|
21
|
+
const harmonyProjectPath = new AbsolutePath(rawArgs.harmonyProjectPath);
|
|
22
|
+
const md5Path = crypto.createHash("md5").update(harmonyProjectPath.getValue()).digest("hex");
|
|
23
|
+
const hvigorCachePath = new AbsolutePath(path.join(os.homedir(), ".hvigor", "project_caches", md5Path));
|
|
24
|
+
|
|
25
|
+
if (fs.existsSync(hvigorCachePath.getValue())) {
|
|
26
|
+
fs.rmSync(hvigorCachePath.getValue(), { recursive: true, force: true });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const buildProfilePath = harmonyProjectPath.copyWithNewSegment('build-profile.json5');
|
|
30
|
+
const buildProfileContent = maybeReadFile(buildProfilePath);
|
|
31
|
+
|
|
32
|
+
if (buildProfileContent) {
|
|
33
|
+
const buildProfile = JSON5.parse(buildProfileContent);
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(buildProfile.modules)) {
|
|
36
|
+
buildProfile.modules.forEach((module: any) => {
|
|
37
|
+
if (module && module.srcPath) {
|
|
38
|
+
const modulePath = harmonyProjectPath.copyWithNewSegment(module.srcPath);
|
|
39
|
+
const cxxPath = modulePath.copyWithNewSegment('.cxx');
|
|
40
|
+
const buildPath = modulePath.copyWithNewSegment('build');
|
|
41
|
+
|
|
42
|
+
if (fs.existsSync(cxxPath.getValue())) {
|
|
43
|
+
fs.rmSync(cxxPath.getValue(), { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (fs.existsSync(buildPath.getValue())) {
|
|
47
|
+
fs.rmSync(buildPath.getValue(), { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
import pathUtils from 'node:path';
|
|
9
2
|
import Case from 'case';
|
|
10
3
|
import { Command } from './types';
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
import { Command } from './types';
|
|
9
2
|
import {
|
|
10
3
|
AbsolutePath,
|
|
@@ -37,22 +30,22 @@ export const commandCodegenLibHarmony: Command = {
|
|
|
37
30
|
'Name of your React Native library. This value is processed and used as a directory name for C++ files to reduce the chances of conflicts between libraries.',
|
|
38
31
|
},
|
|
39
32
|
{
|
|
40
|
-
name: '--turbo-modules-spec-paths [path]',
|
|
33
|
+
name: '--turbo-modules-spec-paths [path...]',
|
|
41
34
|
description:
|
|
42
35
|
'Path or paths to Turbo Module spec files. Each path can point to a spec file or a directory containing spec files.',
|
|
43
|
-
parse: (val
|
|
36
|
+
parse: (val, prev) => (prev ? [...prev, val] : [val]),
|
|
44
37
|
},
|
|
45
38
|
{
|
|
46
|
-
name: '--arkts-components-spec-paths [path]',
|
|
39
|
+
name: '--arkts-components-spec-paths [path...]',
|
|
47
40
|
description:
|
|
48
41
|
'Path or paths to component spec files used to generate code for components to be implemented on the ArkTS side. Each path can point to a spec file or a directory containing spec files.',
|
|
49
|
-
parse: (val
|
|
42
|
+
parse: (val, prev) => (prev ? [...prev, val] : [val]),
|
|
50
43
|
},
|
|
51
44
|
{
|
|
52
|
-
name: '--cpp-components-spec-paths [path]',
|
|
45
|
+
name: '--cpp-components-spec-paths [path...]',
|
|
53
46
|
description:
|
|
54
47
|
'Path or paths to component spec files used to generate code for components to be implemented on the C++ side. Each path can point to a spec file or a directory containing spec files.',
|
|
55
|
-
parse: (val
|
|
48
|
+
parse: (val, prev) => (prev ? [...prev, val] : [val]),
|
|
56
49
|
},
|
|
57
50
|
{
|
|
58
51
|
name: '--cpp-output-path <path>',
|
package/src/commands/index.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
export * from './bundle-harmony';
|
|
9
|
-
export * from './pack-harmony';
|
|
10
|
-
export * from './unpack-harmony';
|
|
11
|
-
export * from './create-metro-host-constants';
|
|
12
2
|
export * from './codegen-harmony';
|
|
13
3
|
export * from './verify-package-harmony';
|
|
14
4
|
export * from './codegen-lib-harmony';
|
|
15
5
|
export * from './link-harmony';
|
|
16
6
|
export * from './run-harmony';
|
|
7
|
+
export * from './init-harmony';
|
|
8
|
+
export * from './clean-harmony';
|