@react-native-oh/react-native-harmony-cli 0.0.30 → 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/assetResolver.js +105 -10
- package/dist/autolinking/Autolinking.js +21 -26
- 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 +4 -13
- package/dist/codegen/core/TypeAnnotationToTS.js +3 -9
- package/dist/codegen/core/UberSchema.js +8 -21
- package/dist/codegen/core/index.js +0 -6
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -7
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +3 -6
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +3 -6
- package/dist/codegen/generators/CppComponentCodeGenerator.js +3 -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 +15 -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 +133 -101
- package/dist/commands/clean-harmony.js +84 -0
- package/dist/commands/codegen-harmony.js +12 -22
- package/dist/commands/codegen-lib-harmony.js +15 -25
- package/dist/commands/index.js +3 -9
- package/dist/commands/init-harmony.js +226 -0
- package/dist/commands/init.js +703 -0
- package/dist/commands/link-harmony.js +12 -16
- package/dist/commands/run-harmony.js +438 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/verify-package-harmony.js +7 -11
- package/dist/core/AbsolutePath.js +3 -6
- package/dist/core/CodegenConfig.js +3 -11
- package/dist/core/DescriptiveError.js +7 -9
- package/dist/core/FileSystem.js +0 -6
- package/dist/core/OHPackageJSON5.js +0 -6
- package/dist/core/PackageJSON.js +4 -7
- 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 +16 -10
- package/dist/core/index.js +0 -6
- package/dist/index.js +3 -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 +56 -29
- package/dist/io/Logger.js +71 -47
- package/dist/io/RealFS.js +10 -6
- package/dist/io/TarGz.js +3 -10
- package/dist/io/__fixtures__.js +8 -8
- package/dist/io/fsUtils.js +1 -8
- package/dist/io/index.js +1 -6
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +1 -8
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +1 -8
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +1 -8
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +1 -8
- 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 +5 -14
- package/harmony/rnoh-hvigor-plugin-0.77.18.tgz +0 -0
- package/jest.config.js +0 -7
- package/package.json +20 -16
- package/react-native.config.js +0 -7
- package/scripts/copy-template.js +18 -0
- package/src/assetResolver.ts +117 -11
- package/src/autolinking/Autolinking.test.ts +54 -18
- package/src/autolinking/Autolinking.ts +32 -31
- 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 +3 -12
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -7
- package/src/codegen/core/TypeAnnotationToTS.ts +3 -8
- package/src/codegen/core/UberSchema.ts +9 -22
- package/src/codegen/core/index.ts +0 -7
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -8
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +3 -7
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +3 -7
- package/src/codegen/generators/CppComponentCodeGenerator.ts +3 -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 +24 -8
- 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 +178 -118
- package/src/commands/clean-harmony.ts +54 -0
- package/src/commands/codegen-harmony.ts +13 -25
- package/src/commands/codegen-lib-harmony.ts +16 -28
- package/src/commands/index.ts +3 -10
- package/src/commands/init-harmony.ts +299 -0
- package/src/commands/init.ts +755 -0
- package/src/commands/link-harmony.ts +14 -19
- package/src/commands/run-harmony.ts +478 -0
- package/src/commands/types.ts +14 -0
- package/src/commands/verify-package-harmony.ts +9 -12
- package/src/core/AbsolutePath.ts +4 -7
- package/src/core/CodegenConfig.ts +3 -12
- package/src/core/DescriptiveError.ts +8 -15
- package/src/core/FileSystem.ts +5 -8
- package/src/core/OHPackageJSON5.ts +0 -7
- package/src/core/PackageJSON.ts +4 -13
- 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 +14 -8
- package/src/core/index.ts +0 -7
- package/src/index.ts +8 -15
- 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 +55 -40
- package/src/io/Logger.ts +77 -51
- package/src/io/RealFS.ts +15 -8
- package/src/io/TarGz.ts +1 -8
- package/src/io/__fixtures__.ts +15 -18
- 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 +4 -13
- 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 -191
- 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 -240
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -119,11 +113,9 @@ function validateArgs(args) {
|
|
|
119
113
|
if (!args.rnohModulePath) {
|
|
120
114
|
throw new core_1.DescriptiveError({
|
|
121
115
|
whatHappened: "--rnoh-module-path argument wasn't provided",
|
|
122
|
-
whatCanUserDo:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
],
|
|
126
|
-
},
|
|
116
|
+
whatCanUserDo: [
|
|
117
|
+
'Please provide a path to the native React Native for Open Harmony module (rnoh) which is probably located somewhere in "<PROJECT_ROOT>/harmony" directory',
|
|
118
|
+
],
|
|
127
119
|
});
|
|
128
120
|
}
|
|
129
121
|
}
|
|
@@ -155,12 +147,10 @@ function throwErrorIfUnsupportedCodegenVersion(codegenVersion, maxSupportedCodeg
|
|
|
155
147
|
if (codegenVersion > maxSupportedCodegenVersion) {
|
|
156
148
|
throw new codegen_1.CodegenError({
|
|
157
149
|
whatHappened: `Package "${packageName}" requires codegenVersion: ${codegenVersion}, which is not supported (maxSupportedCodegenVersion=${maxSupportedCodegenVersion}).`,
|
|
158
|
-
whatCanUserDo:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
],
|
|
163
|
-
},
|
|
150
|
+
whatCanUserDo: [
|
|
151
|
+
`Try downgrading "${packageName}".`,
|
|
152
|
+
'Update the "@react-native-oh/react-native-harmony-cli" package.',
|
|
153
|
+
],
|
|
164
154
|
});
|
|
165
155
|
}
|
|
166
156
|
}
|
|
@@ -181,7 +171,7 @@ function prepareDirectory(path, enableSafetyCheck) {
|
|
|
181
171
|
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
182
172
|
throw new core_1.DescriptiveError({
|
|
183
173
|
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
184
|
-
whatCanUserDo:
|
|
174
|
+
whatCanUserDo: ['Run codegen from different location'],
|
|
185
175
|
});
|
|
186
176
|
}
|
|
187
177
|
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
@@ -190,11 +180,11 @@ function logCodegenResult(logger, fileContentByPath, projectRootPath) {
|
|
|
190
180
|
const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => node_path_1.default.relative(projectRootPath.getValue(), path.getValue()));
|
|
191
181
|
sortedRelativePathStrings.sort();
|
|
192
182
|
sortedRelativePathStrings.forEach((pathStr) => {
|
|
193
|
-
logger.
|
|
183
|
+
logger.debug((styles) => styles.gray(`• ${pathStr}`));
|
|
194
184
|
});
|
|
195
|
-
logger.
|
|
196
|
-
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)
|
|
197
|
-
logger.
|
|
185
|
+
logger.debug(() => '');
|
|
186
|
+
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`);
|
|
187
|
+
logger.debug(() => '');
|
|
198
188
|
}
|
|
199
189
|
function deriveCppDirectoryNameFromNpmPackageName(npmPackageName) {
|
|
200
190
|
let result = npmPackageName;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,19 +29,19 @@ exports.commandCodegenLibHarmony = {
|
|
|
35
29
|
description: '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.',
|
|
36
30
|
},
|
|
37
31
|
{
|
|
38
|
-
name: '--turbo-modules-spec-paths [path]',
|
|
32
|
+
name: '--turbo-modules-spec-paths [path...]',
|
|
39
33
|
description: 'Path or paths to Turbo Module spec files. Each path can point to a spec file or a directory containing spec files.',
|
|
40
|
-
parse: (val) =>
|
|
34
|
+
parse: (val, prev) => (prev ? [...prev, val] : [val]),
|
|
41
35
|
},
|
|
42
36
|
{
|
|
43
|
-
name: '--arkts-components-spec-paths [path]',
|
|
37
|
+
name: '--arkts-components-spec-paths [path...]',
|
|
44
38
|
description: '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.',
|
|
45
|
-
parse: (val) =>
|
|
39
|
+
parse: (val, prev) => (prev ? [...prev, val] : [val]),
|
|
46
40
|
},
|
|
47
41
|
{
|
|
48
|
-
name: '--cpp-components-spec-paths [path]',
|
|
42
|
+
name: '--cpp-components-spec-paths [path...]',
|
|
49
43
|
description: '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.',
|
|
50
|
-
parse: (val) =>
|
|
44
|
+
parse: (val, prev) => (prev ? [...prev, val] : [val]),
|
|
51
45
|
},
|
|
52
46
|
{
|
|
53
47
|
name: '--cpp-output-path <path>',
|
|
@@ -107,19 +101,19 @@ function validateRawArgs(rawArgs) {
|
|
|
107
101
|
if (!rawArgs.npmPackageName) {
|
|
108
102
|
throw new core_1.DescriptiveError({
|
|
109
103
|
whatHappened: '--npm-package-name is required',
|
|
110
|
-
whatCanUserDo:
|
|
104
|
+
whatCanUserDo: ['Please specify --npm-package-name'],
|
|
111
105
|
});
|
|
112
106
|
}
|
|
113
107
|
if (!rawArgs.cppOutputPath) {
|
|
114
108
|
throw new core_1.DescriptiveError({
|
|
115
109
|
whatHappened: '--cpp-output-path is required',
|
|
116
|
-
whatCanUserDo:
|
|
110
|
+
whatCanUserDo: ['Please specify --cpp-output-path'],
|
|
117
111
|
});
|
|
118
112
|
}
|
|
119
113
|
if (!rawArgs.etsOutputPath) {
|
|
120
114
|
throw new core_1.DescriptiveError({
|
|
121
115
|
whatHappened: '--ets-output-path is required',
|
|
122
|
-
whatCanUserDo:
|
|
116
|
+
whatCanUserDo: ['Please specify --ets-output-path'],
|
|
123
117
|
});
|
|
124
118
|
}
|
|
125
119
|
return {
|
|
@@ -138,9 +132,7 @@ function specPathsToSpecFilePaths(specPaths) {
|
|
|
138
132
|
if (!node_fs_1.default.existsSync(specPath.getValue())) {
|
|
139
133
|
throw new core_1.DescriptiveError({
|
|
140
134
|
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
141
|
-
whatCanUserDo:
|
|
142
|
-
default: [`Are you sure provided specPath exists?`],
|
|
143
|
-
},
|
|
135
|
+
whatCanUserDo: [`Are you sure provided specPath exists?`],
|
|
144
136
|
});
|
|
145
137
|
}
|
|
146
138
|
if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
|
|
@@ -237,12 +229,10 @@ function prepareDirectory(path, enableSafetyCheck) {
|
|
|
237
229
|
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
238
230
|
throw new core_1.DescriptiveError({
|
|
239
231
|
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
240
|
-
whatCanUserDo:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
],
|
|
245
|
-
},
|
|
232
|
+
whatCanUserDo: [
|
|
233
|
+
'Run this command with --no-safety-check flag',
|
|
234
|
+
'Run codegen from different location',
|
|
235
|
+
],
|
|
246
236
|
});
|
|
247
237
|
}
|
|
248
238
|
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
@@ -254,6 +244,6 @@ function logCodegenResult(logger, fileContentByPath, rootPath) {
|
|
|
254
244
|
logger.info((styles) => styles.gray(`• ${pathStr}`));
|
|
255
245
|
});
|
|
256
246
|
logger.info(() => '');
|
|
257
|
-
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)
|
|
247
|
+
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`);
|
|
258
248
|
logger.info(() => '');
|
|
259
249
|
}
|
package/dist/commands/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
3
|
if (k2 === undefined) k2 = k;
|
|
10
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -21,10 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
21
15
|
};
|
|
22
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
17
|
__exportStar(require("./bundle-harmony"), exports);
|
|
24
|
-
__exportStar(require("./pack-harmony"), exports);
|
|
25
|
-
__exportStar(require("./unpack-harmony"), exports);
|
|
26
|
-
__exportStar(require("./create-metro-host-constants"), exports);
|
|
27
18
|
__exportStar(require("./codegen-harmony"), exports);
|
|
28
19
|
__exportStar(require("./verify-package-harmony"), exports);
|
|
29
20
|
__exportStar(require("./codegen-lib-harmony"), exports);
|
|
30
21
|
__exportStar(require("./link-harmony"), exports);
|
|
22
|
+
__exportStar(require("./run-harmony"), exports);
|
|
23
|
+
__exportStar(require("./init-harmony"), exports);
|
|
24
|
+
__exportStar(require("./clean-harmony"), exports);
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.commandInitHarmony = void 0;
|
|
13
|
+
const io_1 = require("../io");
|
|
14
|
+
const templates_1 = require("../init/templates");
|
|
15
|
+
const core_1 = require("../core");
|
|
16
|
+
const fs_extra_1 = require("fs-extra");
|
|
17
|
+
const AppScopeStringVarTemplate_1 = require("../init/templates/AppScopeStringVarTemplate");
|
|
18
|
+
const AppScopeAppJSON5Template_1 = require("../init/templates/AppScopeAppJSON5Template");
|
|
19
|
+
const COMMAND_NAME = 'init-harmony';
|
|
20
|
+
const BUNDLE_NAME_PATTERN = /^[a-zA-Z][0-9a-zA-Z_.]+$/;
|
|
21
|
+
exports.commandInitHarmony = {
|
|
22
|
+
name: COMMAND_NAME,
|
|
23
|
+
description: 'Initializes a new RNOH project.',
|
|
24
|
+
options: [
|
|
25
|
+
{
|
|
26
|
+
name: '--bundle-name <string>',
|
|
27
|
+
description: `Required. The native app bundle name. It must match ${BUNDLE_NAME_PATTERN} pattern and include three segments separated by a dot (.).`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: '--project-root-path [path]',
|
|
31
|
+
description: 'Relative path to the project root',
|
|
32
|
+
default: '.',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: '--app-name [string]',
|
|
36
|
+
description: 'The native app name. Defaults to the name property in package.json',
|
|
37
|
+
default: undefined,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: '--rnoh-npm-package-name [string]',
|
|
41
|
+
description: 'Name of the react-native-harmony package.',
|
|
42
|
+
default: '@react-native-oh/react-native-harmony',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: '--rnoh-cli-npm-package-name [string]',
|
|
46
|
+
description: 'Name of the react-native-harmony-cli package.',
|
|
47
|
+
default: '@react-native-oh/react-native-harmony-cli',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
var _a;
|
|
52
|
+
const fs = new io_1.RealFS();
|
|
53
|
+
const logger = new io_1.Logger();
|
|
54
|
+
try {
|
|
55
|
+
// input preparation and validation
|
|
56
|
+
if (!rawArgs.bundleName) {
|
|
57
|
+
throw new core_1.DescriptiveError({
|
|
58
|
+
whatHappened: "--bundle-name argument wasn't provided",
|
|
59
|
+
whatCanUserDo: ['Please provide --bundle-name argument'],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const projectRootPath = new core_1.AbsolutePath(rawArgs.projectRootPath);
|
|
63
|
+
const harmonyDirPath = projectRootPath.copyWithNewSegment('harmony');
|
|
64
|
+
if (fs.existsSync(harmonyDirPath)) {
|
|
65
|
+
throw new core_1.DescriptiveError({
|
|
66
|
+
whatHappened: 'The "harmony" directory is already initialized',
|
|
67
|
+
whatCanUserDo: ["Remove the 'harmony' directory."],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const rnohNpmPackageName = rawArgs.rnohNpmPackageName;
|
|
71
|
+
const rnohNpmPackagePath = projectRootPath.copyWithNewSegment('node_modules', rnohNpmPackageName);
|
|
72
|
+
if (!fs.existsSync(rnohNpmPackagePath)) {
|
|
73
|
+
throw new core_1.DescriptiveError({
|
|
74
|
+
whatHappened: `${rnohNpmPackagePath
|
|
75
|
+
.relativeTo(projectRootPath)
|
|
76
|
+
.toString()} does not exist. This command requires that 'react-native-harmony' NPM package is already installed.`,
|
|
77
|
+
whatCanUserDo: [
|
|
78
|
+
'Install react-native-harmony and try again.',
|
|
79
|
+
'Provide --rnoh-npm-package-name if the default value is incorrect.',
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const rnohCliNpmPackageName = rawArgs.rnohCliNpmPackageName;
|
|
84
|
+
const rnohCliNpmPackagePath = projectRootPath.copyWithNewSegment('node_modules', rnohCliNpmPackageName);
|
|
85
|
+
if (!fs.existsSync(rnohCliNpmPackagePath)) {
|
|
86
|
+
throw new core_1.DescriptiveError({
|
|
87
|
+
whatHappened: `${rnohCliNpmPackagePath
|
|
88
|
+
.relativeTo(projectRootPath)
|
|
89
|
+
.toString()} does not exist. This command requires that 'react-native-cli-harmony' NPM package is already installed.`,
|
|
90
|
+
whatCanUserDo: [
|
|
91
|
+
'Install react-native-harmony-cli and try again.',
|
|
92
|
+
'Provide --rnoh-cli-npm-package-name if the default value is incorrect.',
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const rnohHvigorPluginPath = findRNOHHvigorPluginPath(fs, rnohCliNpmPackagePath.copyWithNewSegment('harmony'));
|
|
97
|
+
if (rnohHvigorPluginPath === null) {
|
|
98
|
+
throw new core_1.DescriptiveError({
|
|
99
|
+
whatHappened: `Couldn't find RNOH hvigor plugin in ${rnohHvigorPluginPath}. This CLI package seems to be incompatible with RNOH.`,
|
|
100
|
+
whatCanUserDo: ['Try using different RNOH or CLI version.'],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const packageJSON = core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath);
|
|
104
|
+
const appName = (_a = rawArgs.appName) !== null && _a !== void 0 ? _a : packageJSON.name;
|
|
105
|
+
const bundleName = rawArgs.bundleName;
|
|
106
|
+
if (!isBundleNameValid(bundleName)) {
|
|
107
|
+
throw new core_1.DescriptiveError({
|
|
108
|
+
whatHappened: 'Bundle name validation failed',
|
|
109
|
+
whatCanUserDo: [
|
|
110
|
+
`Provide a different project name or provide a bundle name explicitly. Bundle name should have three parts separated by dot e.g. com.org.project and it should match the following regex pattern: ${BUNDLE_NAME_PATTERN}`,
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const harmonyTemplateDirPath = new core_1.AbsolutePath(__dirname).copyWithNewSegment('..', 'init', 'templates', 'harmony');
|
|
115
|
+
yield (0, fs_extra_1.ensureDir)(harmonyDirPath.toString());
|
|
116
|
+
// processing
|
|
117
|
+
const metroConfigPath = projectRootPath.copyWithNewSegment('metro.config.js');
|
|
118
|
+
const metroConfigContent = new templates_1.MetroConfigTemplate(rnohNpmPackageName).build();
|
|
119
|
+
const dynamicTemplateContentByPath = new Map([
|
|
120
|
+
[
|
|
121
|
+
harmonyDirPath.copyWithNewSegment('oh-package.json5'),
|
|
122
|
+
new templates_1.OhPackageJson5Template(rnohNpmPackageName).build(),
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
harmonyDirPath.copyWithNewSegment('hvigor', 'hvigor-config.json5'),
|
|
126
|
+
new templates_1.HvigorConfigJson5Template(rnohCliNpmPackageName, rnohHvigorPluginPath.getBasename()).build(),
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
harmonyDirPath.copyWithNewSegment('entry', 'src', 'main', 'resources', 'base', 'element', 'string.json'),
|
|
130
|
+
new templates_1.EntryStringVarTemplate(appName, '').build(),
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
harmonyDirPath.copyWithNewSegment('entry', 'src', 'main', 'ets', 'pages', 'Index.ets'),
|
|
134
|
+
new templates_1.EntryIndexTemplate(appName).build(),
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
harmonyDirPath.copyWithNewSegment('AppScope', 'resources', 'base', 'element', 'string.json'),
|
|
138
|
+
new AppScopeStringVarTemplate_1.AppScopeStringVarTemplate(appName).build(),
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
harmonyDirPath.copyWithNewSegment('AppScope', 'app.json5'),
|
|
142
|
+
new AppScopeAppJSON5Template_1.AppScopeAppJSON5Template(bundleName).build(),
|
|
143
|
+
],
|
|
144
|
+
]);
|
|
145
|
+
// output
|
|
146
|
+
if (fs.existsSync(metroConfigPath)) {
|
|
147
|
+
if (fs.existsSync(projectRootPath.copyWithNewSegment('.git'))) {
|
|
148
|
+
logger.warn((s) => `Overwritten "${s.bold('./metro.config.js')}"`);
|
|
149
|
+
fs.writeTextSync(metroConfigPath, metroConfigContent);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
logger.warn((s) => `Skipped overriding "${s.bold('./metro.config.js')}" due to lack of .git. Override "${s.bold('./metro.config.js')}" manually.`);
|
|
153
|
+
console.log(metroConfigContent);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
fs.writeTextSync(metroConfigPath, metroConfigContent);
|
|
158
|
+
}
|
|
159
|
+
yield (0, fs_extra_1.copy)(harmonyTemplateDirPath.toString(), harmonyDirPath.toString());
|
|
160
|
+
renameGitignoreFiles(fs, harmonyDirPath);
|
|
161
|
+
logger.succeed((s) => `Created "${s.bold('./harmony')}" directory`);
|
|
162
|
+
dynamicTemplateContentByPath.forEach((content, path) => {
|
|
163
|
+
fs.writeTextSync(path, content);
|
|
164
|
+
});
|
|
165
|
+
const buildProfileTemplateComment = "build-profile.json5 can contain signingConfigs which are unique for each developer, therefore that file is ignored by Git. Create a build-profile.json5 based on this template after cloning this repository to be able to open this project in DevEco Studio.";
|
|
166
|
+
const buildProfilePath = harmonyDirPath.copyWithNewSegment('build-profile.json5');
|
|
167
|
+
const buildProfileContent = fs.readTextSync(buildProfilePath);
|
|
168
|
+
const contentLines = buildProfileContent.split('\n');
|
|
169
|
+
contentLines.splice(1, 0, " // " + buildProfileTemplateComment);
|
|
170
|
+
const buildProfileTemplateContent = contentLines.join('\n');
|
|
171
|
+
fs.writeTextSync(harmonyDirPath.copyWithNewSegment('build-profile.template.json5'), buildProfileTemplateContent);
|
|
172
|
+
logger.info((s) => [
|
|
173
|
+
s.bold('Run on a physical device:'),
|
|
174
|
+
s.gray('1. Run `npm start` to start the Metro server.'),
|
|
175
|
+
s.gray('2. Open `./harmony` project in DevEco Studio and wait for background jobs to finish.'),
|
|
176
|
+
s.gray('3. Press the user icon in top right corner, and then press "Sign in" button.'),
|
|
177
|
+
s.gray('4. Connect the device.'),
|
|
178
|
+
s.gray('5. Go to File > Project Structure > Signing Configs and mark "Automatically generate signature", and then press OK.'),
|
|
179
|
+
s.gray("6. Select 'entry' run configuration (top right corner)."),
|
|
180
|
+
s.gray("7. Press the `Debug 'entry'` button (top right corner)."),
|
|
181
|
+
].join('\n'));
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
if (err instanceof core_1.DescriptiveError && !err.isUnexpected()) {
|
|
185
|
+
logger.descriptiveError(err);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
throw err;
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
191
|
+
};
|
|
192
|
+
function findRNOHHvigorPluginPath(fs, dirPath) {
|
|
193
|
+
for (let dirent of fs.readDirentsSync(dirPath)) {
|
|
194
|
+
if (dirent.isDirectory() || !dirent.name.startsWith('rnoh-hvigor-plugin')) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
return dirent.path;
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* In the template directory, gitignore files don't start with a dot.
|
|
203
|
+
* After copying the template, those files need to be renamed.
|
|
204
|
+
*/
|
|
205
|
+
function renameGitignoreFiles(fs, dirPath) {
|
|
206
|
+
try {
|
|
207
|
+
for (const dirent of fs.readDirentsSync(dirPath)) {
|
|
208
|
+
if (dirent.isDirectory()) {
|
|
209
|
+
renameGitignoreFiles(fs, dirent.path);
|
|
210
|
+
}
|
|
211
|
+
else if (!dirent.isDirectory() && dirent.name === 'gitignore') {
|
|
212
|
+
const newFilePath = dirPath.copyWithNewSegment('.gitignore');
|
|
213
|
+
fs.renameSync(dirent.path, newFilePath);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
throw new core_1.DescriptiveError({
|
|
219
|
+
whatHappened: 'Encounter an error when processing .gitignore files',
|
|
220
|
+
extraData: error,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function isBundleNameValid(bundleName) {
|
|
225
|
+
return (BUNDLE_NAME_PATTERN.test(bundleName) && bundleName.split('.').length === 3);
|
|
226
|
+
}
|