@react-native-oh/react-native-harmony-cli 0.0.30 → 0.77.18
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/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,13 +1,6 @@
|
|
|
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 pathUtils from 'node:path';
|
|
9
2
|
import Case from 'case';
|
|
10
|
-
import { Command } from '
|
|
3
|
+
import { Command } from './types';
|
|
11
4
|
import {
|
|
12
5
|
AbsolutePath,
|
|
13
6
|
DescriptiveError,
|
|
@@ -169,11 +162,9 @@ function validateArgs(args: any) {
|
|
|
169
162
|
if (!args.rnohModulePath) {
|
|
170
163
|
throw new DescriptiveError({
|
|
171
164
|
whatHappened: "--rnoh-module-path argument wasn't provided",
|
|
172
|
-
whatCanUserDo:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
],
|
|
176
|
-
},
|
|
165
|
+
whatCanUserDo: [
|
|
166
|
+
'Please provide a path to the native React Native for Open Harmony module (rnoh) which is probably located somewhere in "<PROJECT_ROOT>/harmony" directory',
|
|
167
|
+
],
|
|
177
168
|
});
|
|
178
169
|
}
|
|
179
170
|
}
|
|
@@ -222,12 +213,10 @@ function throwErrorIfUnsupportedCodegenVersion(
|
|
|
222
213
|
if (codegenVersion > maxSupportedCodegenVersion) {
|
|
223
214
|
throw new CodegenError({
|
|
224
215
|
whatHappened: `Package "${packageName}" requires codegenVersion: ${codegenVersion}, which is not supported (maxSupportedCodegenVersion=${maxSupportedCodegenVersion}).`,
|
|
225
|
-
whatCanUserDo:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
],
|
|
230
|
-
},
|
|
216
|
+
whatCanUserDo: [
|
|
217
|
+
`Try downgrading "${packageName}".`,
|
|
218
|
+
'Update the "@react-native-oh/react-native-harmony-cli" package.',
|
|
219
|
+
],
|
|
231
220
|
});
|
|
232
221
|
}
|
|
233
222
|
}
|
|
@@ -262,7 +251,7 @@ function prepareDirectory(path: AbsolutePath, enableSafetyCheck: boolean) {
|
|
|
262
251
|
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
263
252
|
throw new DescriptiveError({
|
|
264
253
|
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
265
|
-
whatCanUserDo:
|
|
254
|
+
whatCanUserDo: ['Run codegen from different location'],
|
|
266
255
|
});
|
|
267
256
|
}
|
|
268
257
|
maybeRemoveFilesInDirectory(path);
|
|
@@ -278,15 +267,14 @@ function logCodegenResult(
|
|
|
278
267
|
);
|
|
279
268
|
sortedRelativePathStrings.sort();
|
|
280
269
|
sortedRelativePathStrings.forEach((pathStr) => {
|
|
281
|
-
logger.
|
|
270
|
+
logger.debug((styles) => styles.gray(`• ${pathStr}`));
|
|
282
271
|
});
|
|
283
|
-
logger.
|
|
272
|
+
logger.debug(() => '');
|
|
284
273
|
logger.info(
|
|
285
274
|
(styles) =>
|
|
286
|
-
`Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)
|
|
287
|
-
{ prefix: true }
|
|
275
|
+
`Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`
|
|
288
276
|
);
|
|
289
|
-
logger.
|
|
277
|
+
logger.debug(() => '');
|
|
290
278
|
}
|
|
291
279
|
|
|
292
280
|
function deriveCppDirectoryNameFromNpmPackageName(
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
import { Command } from '@react-native-community/cli-types';
|
|
1
|
+
import { Command } from './types';
|
|
9
2
|
import {
|
|
10
3
|
AbsolutePath,
|
|
11
4
|
DescriptiveError,
|
|
@@ -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>',
|
|
@@ -147,19 +140,19 @@ function validateRawArgs(rawArgs: RawArgs): Args {
|
|
|
147
140
|
if (!rawArgs.npmPackageName) {
|
|
148
141
|
throw new DescriptiveError({
|
|
149
142
|
whatHappened: '--npm-package-name is required',
|
|
150
|
-
whatCanUserDo:
|
|
143
|
+
whatCanUserDo: ['Please specify --npm-package-name'],
|
|
151
144
|
});
|
|
152
145
|
}
|
|
153
146
|
if (!rawArgs.cppOutputPath) {
|
|
154
147
|
throw new DescriptiveError({
|
|
155
148
|
whatHappened: '--cpp-output-path is required',
|
|
156
|
-
whatCanUserDo:
|
|
149
|
+
whatCanUserDo: ['Please specify --cpp-output-path'],
|
|
157
150
|
});
|
|
158
151
|
}
|
|
159
152
|
if (!rawArgs.etsOutputPath) {
|
|
160
153
|
throw new DescriptiveError({
|
|
161
154
|
whatHappened: '--ets-output-path is required',
|
|
162
|
-
whatCanUserDo:
|
|
155
|
+
whatCanUserDo: ['Please specify --ets-output-path'],
|
|
163
156
|
});
|
|
164
157
|
}
|
|
165
158
|
return {
|
|
@@ -185,9 +178,7 @@ function specPathsToSpecFilePaths(specPaths: AbsolutePath[]): AbsolutePath[] {
|
|
|
185
178
|
if (!fs.existsSync(specPath.getValue())) {
|
|
186
179
|
throw new DescriptiveError({
|
|
187
180
|
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
188
|
-
whatCanUserDo:
|
|
189
|
-
default: [`Are you sure provided specPath exists?`],
|
|
190
|
-
},
|
|
181
|
+
whatCanUserDo: [`Are you sure provided specPath exists?`],
|
|
191
182
|
});
|
|
192
183
|
}
|
|
193
184
|
if (fs.lstatSync(specPath.getValue()).isDirectory()) {
|
|
@@ -361,12 +352,10 @@ function prepareDirectory(path: AbsolutePath, enableSafetyCheck: boolean) {
|
|
|
361
352
|
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
362
353
|
throw new DescriptiveError({
|
|
363
354
|
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
364
|
-
whatCanUserDo:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
],
|
|
369
|
-
},
|
|
355
|
+
whatCanUserDo: [
|
|
356
|
+
'Run this command with --no-safety-check flag',
|
|
357
|
+
'Run codegen from different location',
|
|
358
|
+
],
|
|
370
359
|
});
|
|
371
360
|
}
|
|
372
361
|
maybeRemoveFilesInDirectory(path);
|
|
@@ -387,8 +376,7 @@ function logCodegenResult(
|
|
|
387
376
|
logger.info(() => '');
|
|
388
377
|
logger.info(
|
|
389
378
|
(styles) =>
|
|
390
|
-
`Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)
|
|
391
|
-
{ prefix: true }
|
|
379
|
+
`Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`
|
|
392
380
|
);
|
|
393
381
|
logger.info(() => '');
|
|
394
382
|
}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
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 './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';
|
|
6
|
+
export * from './run-harmony';
|
|
7
|
+
export * from './init-harmony';
|
|
8
|
+
export * from './clean-harmony';
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { Command } from './types';
|
|
2
|
+
import { Logger, RealFS } from '../io';
|
|
3
|
+
import {
|
|
4
|
+
MetroConfigTemplate,
|
|
5
|
+
EntryStringVarTemplate,
|
|
6
|
+
EntryIndexTemplate,
|
|
7
|
+
OhPackageJson5Template,
|
|
8
|
+
HvigorConfigJson5Template,
|
|
9
|
+
} from '../init/templates';
|
|
10
|
+
import { AbsolutePath, DescriptiveError, PackageJSON } from '../core';
|
|
11
|
+
import { copy as dirCopy, ensureDir } from 'fs-extra';
|
|
12
|
+
import { AppScopeStringVarTemplate } from '../init/templates/AppScopeStringVarTemplate';
|
|
13
|
+
import { AppScopeAppJSON5Template } from '../init/templates/AppScopeAppJSON5Template';
|
|
14
|
+
|
|
15
|
+
const COMMAND_NAME = 'init-harmony';
|
|
16
|
+
const BUNDLE_NAME_PATTERN = /^[a-zA-Z][0-9a-zA-Z_.]+$/;
|
|
17
|
+
|
|
18
|
+
export const commandInitHarmony: Command = {
|
|
19
|
+
name: COMMAND_NAME,
|
|
20
|
+
description: 'Initializes a new RNOH project.',
|
|
21
|
+
options: [
|
|
22
|
+
{
|
|
23
|
+
name: '--bundle-name <string>',
|
|
24
|
+
description: `Required. The native app bundle name. It must match ${BUNDLE_NAME_PATTERN} pattern and include three segments separated by a dot (.).`,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: '--project-root-path [path]',
|
|
28
|
+
description: 'Relative path to the project root',
|
|
29
|
+
default: '.',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: '--app-name [string]',
|
|
33
|
+
description:
|
|
34
|
+
'The native app name. Defaults to the name property in package.json',
|
|
35
|
+
default: undefined,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: '--rnoh-npm-package-name [string]',
|
|
39
|
+
description: 'Name of the react-native-harmony package.',
|
|
40
|
+
default: '@react-native-oh/react-native-harmony',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: '--rnoh-cli-npm-package-name [string]',
|
|
44
|
+
description: 'Name of the react-native-harmony-cli package.',
|
|
45
|
+
default: '@react-native-oh/react-native-harmony-cli',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
func: async (_argv, _config, rawArgs: any) => {
|
|
49
|
+
const fs = new RealFS();
|
|
50
|
+
const logger = new Logger();
|
|
51
|
+
try {
|
|
52
|
+
// input preparation and validation
|
|
53
|
+
if (!rawArgs.bundleName) {
|
|
54
|
+
throw new DescriptiveError({
|
|
55
|
+
whatHappened: "--bundle-name argument wasn't provided",
|
|
56
|
+
whatCanUserDo: ['Please provide --bundle-name argument'],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const projectRootPath = new AbsolutePath(rawArgs.projectRootPath);
|
|
60
|
+
const harmonyDirPath = projectRootPath.copyWithNewSegment('harmony');
|
|
61
|
+
|
|
62
|
+
if (fs.existsSync(harmonyDirPath)) {
|
|
63
|
+
throw new DescriptiveError({
|
|
64
|
+
whatHappened: 'The "harmony" directory is already initialized',
|
|
65
|
+
whatCanUserDo: ["Remove the 'harmony' directory."],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const rnohNpmPackageName: string = rawArgs.rnohNpmPackageName;
|
|
69
|
+
const rnohNpmPackagePath = projectRootPath.copyWithNewSegment(
|
|
70
|
+
'node_modules',
|
|
71
|
+
rnohNpmPackageName
|
|
72
|
+
);
|
|
73
|
+
if (!fs.existsSync(rnohNpmPackagePath)) {
|
|
74
|
+
throw new DescriptiveError({
|
|
75
|
+
whatHappened: `${rnohNpmPackagePath
|
|
76
|
+
.relativeTo(projectRootPath)
|
|
77
|
+
.toString()} does not exist. This command requires that 'react-native-harmony' NPM package is already installed.`,
|
|
78
|
+
whatCanUserDo: [
|
|
79
|
+
'Install react-native-harmony and try again.',
|
|
80
|
+
'Provide --rnoh-npm-package-name if the default value is incorrect.',
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const rnohCliNpmPackageName: string = rawArgs.rnohCliNpmPackageName;
|
|
85
|
+
const rnohCliNpmPackagePath = projectRootPath.copyWithNewSegment(
|
|
86
|
+
'node_modules',
|
|
87
|
+
rnohCliNpmPackageName
|
|
88
|
+
);
|
|
89
|
+
if (!fs.existsSync(rnohCliNpmPackagePath)) {
|
|
90
|
+
throw new DescriptiveError({
|
|
91
|
+
whatHappened: `${rnohCliNpmPackagePath
|
|
92
|
+
.relativeTo(projectRootPath)
|
|
93
|
+
.toString()} does not exist. This command requires that 'react-native-cli-harmony' NPM package is already installed.`,
|
|
94
|
+
whatCanUserDo: [
|
|
95
|
+
'Install react-native-harmony-cli and try again.',
|
|
96
|
+
'Provide --rnoh-cli-npm-package-name if the default value is incorrect.',
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const rnohHvigorPluginPath = findRNOHHvigorPluginPath(
|
|
101
|
+
fs,
|
|
102
|
+
rnohCliNpmPackagePath.copyWithNewSegment('harmony')
|
|
103
|
+
);
|
|
104
|
+
if (rnohHvigorPluginPath === null) {
|
|
105
|
+
throw new DescriptiveError({
|
|
106
|
+
whatHappened: `Couldn't find RNOH hvigor plugin in ${rnohHvigorPluginPath}. This CLI package seems to be incompatible with RNOH.`,
|
|
107
|
+
whatCanUserDo: ['Try using different RNOH or CLI version.'],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const packageJSON = PackageJSON.fromProjectRootPath(
|
|
111
|
+
fs,
|
|
112
|
+
projectRootPath,
|
|
113
|
+
projectRootPath
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const appName = rawArgs.appName ?? packageJSON.name;
|
|
117
|
+
const bundleName = rawArgs.bundleName;
|
|
118
|
+
if (!isBundleNameValid(bundleName)) {
|
|
119
|
+
throw new DescriptiveError({
|
|
120
|
+
whatHappened: 'Bundle name validation failed',
|
|
121
|
+
whatCanUserDo: [
|
|
122
|
+
`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}`,
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const harmonyTemplateDirPath = new AbsolutePath(
|
|
128
|
+
__dirname
|
|
129
|
+
).copyWithNewSegment('..', 'init', 'templates', 'harmony');
|
|
130
|
+
await ensureDir(harmonyDirPath.toString());
|
|
131
|
+
|
|
132
|
+
// processing
|
|
133
|
+
const metroConfigPath =
|
|
134
|
+
projectRootPath.copyWithNewSegment('metro.config.js');
|
|
135
|
+
const metroConfigContent = new MetroConfigTemplate(
|
|
136
|
+
rnohNpmPackageName
|
|
137
|
+
).build();
|
|
138
|
+
const dynamicTemplateContentByPath = new Map<AbsolutePath, string>([
|
|
139
|
+
[
|
|
140
|
+
harmonyDirPath.copyWithNewSegment('oh-package.json5'),
|
|
141
|
+
new OhPackageJson5Template(rnohNpmPackageName).build(),
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
harmonyDirPath.copyWithNewSegment('hvigor', 'hvigor-config.json5'),
|
|
145
|
+
new HvigorConfigJson5Template(
|
|
146
|
+
rnohCliNpmPackageName,
|
|
147
|
+
rnohHvigorPluginPath!.getBasename()
|
|
148
|
+
).build(),
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
harmonyDirPath.copyWithNewSegment(
|
|
152
|
+
'entry',
|
|
153
|
+
'src',
|
|
154
|
+
'main',
|
|
155
|
+
'resources',
|
|
156
|
+
'base',
|
|
157
|
+
'element',
|
|
158
|
+
'string.json'
|
|
159
|
+
),
|
|
160
|
+
new EntryStringVarTemplate(appName, '').build(),
|
|
161
|
+
],
|
|
162
|
+
[
|
|
163
|
+
harmonyDirPath.copyWithNewSegment(
|
|
164
|
+
'entry',
|
|
165
|
+
'src',
|
|
166
|
+
'main',
|
|
167
|
+
'ets',
|
|
168
|
+
'pages',
|
|
169
|
+
'Index.ets'
|
|
170
|
+
),
|
|
171
|
+
new EntryIndexTemplate(appName).build(),
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
harmonyDirPath.copyWithNewSegment(
|
|
175
|
+
'AppScope',
|
|
176
|
+
'resources',
|
|
177
|
+
'base',
|
|
178
|
+
'element',
|
|
179
|
+
'string.json'
|
|
180
|
+
),
|
|
181
|
+
new AppScopeStringVarTemplate(appName).build(),
|
|
182
|
+
],
|
|
183
|
+
[
|
|
184
|
+
harmonyDirPath.copyWithNewSegment('AppScope', 'app.json5'),
|
|
185
|
+
new AppScopeAppJSON5Template(bundleName).build(),
|
|
186
|
+
],
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
// output
|
|
190
|
+
if (fs.existsSync(metroConfigPath)) {
|
|
191
|
+
if (fs.existsSync(projectRootPath.copyWithNewSegment('.git'))) {
|
|
192
|
+
logger.warn((s) => `Overwritten "${s.bold('./metro.config.js')}"`);
|
|
193
|
+
fs.writeTextSync(metroConfigPath, metroConfigContent);
|
|
194
|
+
} else {
|
|
195
|
+
logger.warn(
|
|
196
|
+
(s) =>
|
|
197
|
+
`Skipped overriding "${s.bold(
|
|
198
|
+
'./metro.config.js'
|
|
199
|
+
)}" due to lack of .git. Override "${s.bold(
|
|
200
|
+
'./metro.config.js'
|
|
201
|
+
)}" manually.`
|
|
202
|
+
);
|
|
203
|
+
console.log(metroConfigContent);
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
fs.writeTextSync(metroConfigPath, metroConfigContent);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
await dirCopy(
|
|
210
|
+
harmonyTemplateDirPath.toString(),
|
|
211
|
+
harmonyDirPath.toString()
|
|
212
|
+
);
|
|
213
|
+
renameGitignoreFiles(fs, harmonyDirPath);
|
|
214
|
+
logger.succeed((s) => `Created "${s.bold('./harmony')}" directory`);
|
|
215
|
+
dynamicTemplateContentByPath.forEach((content, path) => {
|
|
216
|
+
fs.writeTextSync(path, content);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
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.";
|
|
220
|
+
|
|
221
|
+
const buildProfilePath = harmonyDirPath.copyWithNewSegment('build-profile.json5');
|
|
222
|
+
const buildProfileContent = fs.readTextSync(buildProfilePath);
|
|
223
|
+
const contentLines = buildProfileContent.split('\n');
|
|
224
|
+
contentLines.splice(1, 0, " // " + buildProfileTemplateComment);
|
|
225
|
+
const buildProfileTemplateContent = contentLines.join('\n');
|
|
226
|
+
|
|
227
|
+
fs.writeTextSync(
|
|
228
|
+
harmonyDirPath.copyWithNewSegment('build-profile.template.json5'),
|
|
229
|
+
buildProfileTemplateContent
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
logger.info((s) =>
|
|
233
|
+
[
|
|
234
|
+
s.bold('Run on a physical device:'),
|
|
235
|
+
s.gray('1. Run `npm start` to start the Metro server.'),
|
|
236
|
+
s.gray(
|
|
237
|
+
'2. Open `./harmony` project in DevEco Studio and wait for background jobs to finish.'
|
|
238
|
+
),
|
|
239
|
+
s.gray(
|
|
240
|
+
'3. Press the user icon in top right corner, and then press "Sign in" button.'
|
|
241
|
+
),
|
|
242
|
+
s.gray('4. Connect the device.'),
|
|
243
|
+
s.gray(
|
|
244
|
+
'5. Go to File > Project Structure > Signing Configs and mark "Automatically generate signature", and then press OK.'
|
|
245
|
+
),
|
|
246
|
+
s.gray("6. Select 'entry' run configuration (top right corner)."),
|
|
247
|
+
s.gray("7. Press the `Debug 'entry'` button (top right corner)."),
|
|
248
|
+
].join('\n')
|
|
249
|
+
);
|
|
250
|
+
} catch (err) {
|
|
251
|
+
if (err instanceof DescriptiveError && !err.isUnexpected()) {
|
|
252
|
+
logger.descriptiveError(err);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
throw err;
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
function findRNOHHvigorPluginPath(
|
|
261
|
+
fs: RealFS,
|
|
262
|
+
dirPath: AbsolutePath
|
|
263
|
+
): AbsolutePath | null {
|
|
264
|
+
for (let dirent of fs.readDirentsSync(dirPath)) {
|
|
265
|
+
if (dirent.isDirectory() || !dirent.name.startsWith('rnoh-hvigor-plugin')) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
return dirent.path;
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* In the template directory, gitignore files don't start with a dot.
|
|
275
|
+
* After copying the template, those files need to be renamed.
|
|
276
|
+
*/
|
|
277
|
+
function renameGitignoreFiles(fs: RealFS, dirPath: AbsolutePath) {
|
|
278
|
+
try {
|
|
279
|
+
for (const dirent of fs.readDirentsSync(dirPath)) {
|
|
280
|
+
if (dirent.isDirectory()) {
|
|
281
|
+
renameGitignoreFiles(fs, dirent.path);
|
|
282
|
+
} else if (!dirent.isDirectory() && dirent.name === 'gitignore') {
|
|
283
|
+
const newFilePath = dirPath.copyWithNewSegment('.gitignore');
|
|
284
|
+
fs.renameSync(dirent.path, newFilePath);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} catch (error) {
|
|
288
|
+
throw new DescriptiveError({
|
|
289
|
+
whatHappened: 'Encounter an error when processing .gitignore files',
|
|
290
|
+
extraData: error,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function isBundleNameValid(bundleName: string): boolean {
|
|
296
|
+
return (
|
|
297
|
+
BUNDLE_NAME_PATTERN.test(bundleName) && bundleName.split('.').length === 3
|
|
298
|
+
);
|
|
299
|
+
}
|