@react-native-oh/react-native-harmony-cli 0.0.36 → 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/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/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,55 +0,0 @@
|
|
|
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
|
-
import { Command } from './types';
|
|
9
|
-
import os from 'node:os';
|
|
10
|
-
import fs from 'node:fs';
|
|
11
|
-
import pathUtils from 'node:path';
|
|
12
|
-
|
|
13
|
-
export const commandCreateMetroConstantsHarmony: Command = {
|
|
14
|
-
name: 'create-metro-host-constants-harmony',
|
|
15
|
-
description:
|
|
16
|
-
'Creates a Typescript file that exports constant with IP of the host machine. That IP is later used to connect to the Metro server from a physical device.',
|
|
17
|
-
options: [
|
|
18
|
-
{
|
|
19
|
-
name: '--output <string>',
|
|
20
|
-
description: 'Output file',
|
|
21
|
-
default: './harmony/entry/src/main/ets/codegen/MetroHostConstants.ts',
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
func: async (argv, config, args: any) => {
|
|
25
|
-
createMetroHostConstants(pathUtils.resolve(args.output));
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function createMetroHostConstants(outputPath: string): void {
|
|
30
|
-
const networkInterfacesByName = os.networkInterfaces();
|
|
31
|
-
const getIP = () => {
|
|
32
|
-
for (let name of Object.keys(networkInterfacesByName)) {
|
|
33
|
-
for (let net of networkInterfacesByName[name] ?? []) {
|
|
34
|
-
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
|
|
35
|
-
if (net.family === 'IPv4' && !net.internal) {
|
|
36
|
-
return net.address;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
};
|
|
42
|
-
const ip = getIP();
|
|
43
|
-
const tsCode = [
|
|
44
|
-
'// This file is autogenerated. Do not modify it manually.',
|
|
45
|
-
'',
|
|
46
|
-
`export const METRO_SERVER_IP = '${ip}';\n`,
|
|
47
|
-
];
|
|
48
|
-
fs.writeFile(outputPath, tsCode.join('\n'), (err) => {
|
|
49
|
-
if (err) {
|
|
50
|
-
console.error(`Error writing to ${outputPath}:`, err);
|
|
51
|
-
} else {
|
|
52
|
-
console.log(`Created file at ${outputPath}`);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
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
|
-
import { Command } from './types';
|
|
9
|
-
import { globSync } from 'glob';
|
|
10
|
-
import pathUtils from 'path';
|
|
11
|
-
import tar from 'tar';
|
|
12
|
-
import fs from 'fs';
|
|
13
|
-
import { ValidationError } from '../core';
|
|
14
|
-
import ignore, { Ignore } from 'ignore';
|
|
15
|
-
import JSON5 from 'json5';
|
|
16
|
-
|
|
17
|
-
export const commandPackHarmony: Command = {
|
|
18
|
-
name: 'pack-harmony',
|
|
19
|
-
description: 'Pack native code. Used for package development.',
|
|
20
|
-
options: [
|
|
21
|
-
{
|
|
22
|
-
name: '--oh-module-path <string>',
|
|
23
|
-
description: 'Path to the OH module',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: '--harmony-dir-path <string>',
|
|
27
|
-
description: 'Path to the harmony dir',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: '--package-json-path <string>',
|
|
31
|
-
description: 'Path to the package.json',
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
func: async (argv, config, args: any) => {
|
|
35
|
-
try {
|
|
36
|
-
await pack(
|
|
37
|
-
pathUtils.resolve(args.harmonyDirPath),
|
|
38
|
-
pathUtils.resolve(args.ohModulePath),
|
|
39
|
-
pathUtils.resolve(args.packageJsonPath)
|
|
40
|
-
);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
if (err instanceof ValidationError) {
|
|
43
|
-
console.error('[ERROR]', err.message);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
} else {
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
async function pack(
|
|
53
|
-
harmonyDirPath: string,
|
|
54
|
-
ohModuleDirPath: string,
|
|
55
|
-
packageJSONPath: string
|
|
56
|
-
) {
|
|
57
|
-
syncVersions(
|
|
58
|
-
packageJSONPath,
|
|
59
|
-
pathUtils.join(ohModuleDirPath, 'oh-package.json5')
|
|
60
|
-
);
|
|
61
|
-
if (!fs.existsSync(harmonyDirPath)) {
|
|
62
|
-
fs.mkdirSync(harmonyDirPath, { recursive: true });
|
|
63
|
-
}
|
|
64
|
-
await createTGZFromDir(
|
|
65
|
-
ohModuleDirPath,
|
|
66
|
-
pathUtils.join(
|
|
67
|
-
harmonyDirPath,
|
|
68
|
-
`${pathUtils.parse(ohModuleDirPath).name}.tar.gz`
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
await createTGZFromDir(
|
|
72
|
-
harmonyDirPath,
|
|
73
|
-
pathUtils.join(pathUtils.dirname(harmonyDirPath), 'harmony.tar.gz')
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function syncVersions(
|
|
78
|
-
packageJSONFilePath: string,
|
|
79
|
-
ohPackageJSONFilePath: string
|
|
80
|
-
) {
|
|
81
|
-
const packageJSONFileContent = JSON.parse(
|
|
82
|
-
fs.readFileSync(packageJSONFilePath, { encoding: 'utf-8' })
|
|
83
|
-
);
|
|
84
|
-
if (fs.existsSync(ohPackageJSONFilePath)) {
|
|
85
|
-
const ohPackageJSONFileContent = JSON5.parse(
|
|
86
|
-
fs.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' })
|
|
87
|
-
);
|
|
88
|
-
ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
|
|
89
|
-
fs.writeFileSync(
|
|
90
|
-
ohPackageJSONFilePath,
|
|
91
|
-
JSON5.stringify(ohPackageJSONFileContent, null, 2)
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function createTGZFromDir(dirPath: string, outputFilePath: string) {
|
|
97
|
-
const ig = getIgnoreUtil(pathUtils.join(dirPath, '.tarignore'));
|
|
98
|
-
const filesToInclude = globSync('**', {
|
|
99
|
-
cwd: dirPath,
|
|
100
|
-
nodir: true,
|
|
101
|
-
}).filter((path) => !ig.ignores(path));
|
|
102
|
-
await createArchive(outputFilePath, dirPath, filesToInclude);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function getIgnoreUtil(tarignorePath: string): Ignore {
|
|
106
|
-
if (!fs.existsSync(tarignorePath)) {
|
|
107
|
-
return ignore();
|
|
108
|
-
}
|
|
109
|
-
return ignore().add(fs.readFileSync(tarignorePath).toString());
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async function createArchive(
|
|
113
|
-
outputFilePath: string,
|
|
114
|
-
packageDirPath: string,
|
|
115
|
-
filesToInclude: string[]
|
|
116
|
-
) {
|
|
117
|
-
if (filesToInclude.length === 0) {
|
|
118
|
-
throw new ValidationError('Nothing to pack');
|
|
119
|
-
}
|
|
120
|
-
await tar.c(
|
|
121
|
-
{
|
|
122
|
-
gzip: true,
|
|
123
|
-
file: outputFilePath,
|
|
124
|
-
cwd: packageDirPath,
|
|
125
|
-
},
|
|
126
|
-
filesToInclude
|
|
127
|
-
);
|
|
128
|
-
}
|
|
@@ -1,238 +0,0 @@
|
|
|
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
|
-
import { Command } from './types';
|
|
9
|
-
import { Logger, RealFS } from '../io';
|
|
10
|
-
|
|
11
|
-
import pathUtils from 'path';
|
|
12
|
-
import fs from 'fs';
|
|
13
|
-
import zlib from 'zlib';
|
|
14
|
-
import tar from 'tar';
|
|
15
|
-
import JSON5 from 'json5';
|
|
16
|
-
import {
|
|
17
|
-
ValidationError,
|
|
18
|
-
AbsolutePath,
|
|
19
|
-
ProjectDependenciesManager,
|
|
20
|
-
} from '../core';
|
|
21
|
-
|
|
22
|
-
export const commandUnpackHarmony: Command = {
|
|
23
|
-
name: 'unpack-harmony',
|
|
24
|
-
description: 'Unpacks native code.',
|
|
25
|
-
options: [
|
|
26
|
-
{
|
|
27
|
-
name: '--project-root-path <path>',
|
|
28
|
-
description: 'Relative path to package root',
|
|
29
|
-
default: '.',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: '--output-dir <string>',
|
|
33
|
-
description: 'Output directory to which OH modules should be unpacked to',
|
|
34
|
-
default: './harmony/rnoh_modules',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
func: async (argv, config, args: any) => {
|
|
38
|
-
try {
|
|
39
|
-
await unpack(
|
|
40
|
-
new AbsolutePath(args.projectRootPath),
|
|
41
|
-
new AbsolutePath(args.outputDir)
|
|
42
|
-
);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
if (err instanceof ValidationError) {
|
|
45
|
-
console.error('[ERROR]', err.message);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
} else {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
async function unpack(
|
|
55
|
-
projectRootPath: AbsolutePath,
|
|
56
|
-
outputDirPath: AbsolutePath
|
|
57
|
-
) {
|
|
58
|
-
const logger = new Logger();
|
|
59
|
-
const fs = new RealFS();
|
|
60
|
-
const projectDependenciesManager = new ProjectDependenciesManager(
|
|
61
|
-
fs,
|
|
62
|
-
projectRootPath
|
|
63
|
-
);
|
|
64
|
-
logger.info((styles) => styles.bold(`Unpacking RNOH modules`));
|
|
65
|
-
let unpackedArchivesCount = 0;
|
|
66
|
-
let skippedArchivesCount = 0;
|
|
67
|
-
await projectDependenciesManager.forEachAsync(async (dependency) => {
|
|
68
|
-
const packageJSON = dependency.readPackageJSON();
|
|
69
|
-
const harmonyArchivePath = dependency
|
|
70
|
-
.getRootPath()
|
|
71
|
-
.copyWithNewSegment('harmony.tar.gz');
|
|
72
|
-
const pkgHarmonyDirPath = dependency
|
|
73
|
-
.getRootPath()
|
|
74
|
-
.copyWithNewSegment('harmony');
|
|
75
|
-
const harmonyTarGzPathStr = dependency
|
|
76
|
-
.getRootPath()
|
|
77
|
-
.copyWithNewSegment('harmony.tar.gz')
|
|
78
|
-
.relativeTo(projectRootPath)
|
|
79
|
-
.getValue();
|
|
80
|
-
if (
|
|
81
|
-
packageJSON.version &&
|
|
82
|
-
shouldUnpack(
|
|
83
|
-
harmonyArchivePath,
|
|
84
|
-
pkgHarmonyDirPath,
|
|
85
|
-
outputDirPath,
|
|
86
|
-
packageJSON.version
|
|
87
|
-
)
|
|
88
|
-
) {
|
|
89
|
-
if (!fs.existsSync(pkgHarmonyDirPath)) {
|
|
90
|
-
/**
|
|
91
|
-
* After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
|
|
92
|
-
*/
|
|
93
|
-
logger.info(
|
|
94
|
-
(styles) =>
|
|
95
|
-
`[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`
|
|
96
|
-
);
|
|
97
|
-
await unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
|
|
98
|
-
unpackedArchivesCount++;
|
|
99
|
-
} else {
|
|
100
|
-
skippedArchivesCount++;
|
|
101
|
-
logger.info(
|
|
102
|
-
(styles) =>
|
|
103
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
104
|
-
harmonyTarGzPathStr
|
|
105
|
-
)}`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
109
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
110
|
-
const moduleArchivePathStr = dependency
|
|
111
|
-
.getRootPath()
|
|
112
|
-
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
113
|
-
.relativeTo(projectRootPath)
|
|
114
|
-
.getValue();
|
|
115
|
-
logger.info(
|
|
116
|
-
(styles) =>
|
|
117
|
-
`[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`
|
|
118
|
-
);
|
|
119
|
-
unpackedArchivesCount++;
|
|
120
|
-
await unpackTarGz(
|
|
121
|
-
ohModuleInfo.archivePath,
|
|
122
|
-
ohModuleInfo.computedModulePath
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
if (fs.existsSync(harmonyArchivePath)) {
|
|
127
|
-
skippedArchivesCount++;
|
|
128
|
-
logger.info(
|
|
129
|
-
(styles) =>
|
|
130
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
131
|
-
harmonyTarGzPathStr
|
|
132
|
-
)}`
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
136
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
137
|
-
const moduleArchivePathStr = dependency
|
|
138
|
-
.getRootPath()
|
|
139
|
-
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
140
|
-
.relativeTo(projectRootPath)
|
|
141
|
-
.getValue();
|
|
142
|
-
skippedArchivesCount++;
|
|
143
|
-
logger.info(
|
|
144
|
-
(styles) =>
|
|
145
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
146
|
-
moduleArchivePathStr
|
|
147
|
-
)}`
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
logger.info(
|
|
153
|
-
(styles) =>
|
|
154
|
-
`\nUnpacked: ${styles.cyan(
|
|
155
|
-
unpackedArchivesCount
|
|
156
|
-
)}, Skipped: ${styles.yellow(skippedArchivesCount)}`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function shouldUnpack(
|
|
161
|
-
harmonyArchivePath: AbsolutePath,
|
|
162
|
-
pkgHarmonyDirPath: AbsolutePath,
|
|
163
|
-
outputDirPath: AbsolutePath,
|
|
164
|
-
nodePackageVersion: string
|
|
165
|
-
) {
|
|
166
|
-
if (!fs.existsSync(harmonyArchivePath.getValue())) return false;
|
|
167
|
-
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return true;
|
|
168
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
169
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
170
|
-
if (
|
|
171
|
-
!fs.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
|
|
172
|
-
getOhPackageVersion(ohModuleInfo.computedModulePath) !==
|
|
173
|
-
nodePackageVersion
|
|
174
|
-
) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function getOhPackageVersion(modulePath: AbsolutePath) {
|
|
182
|
-
const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
|
|
183
|
-
if (!fs.existsSync(ohPackagePath.getValue())) return null;
|
|
184
|
-
const content = fs.readFileSync(ohPackagePath.getValue(), {
|
|
185
|
-
encoding: 'utf-8',
|
|
186
|
-
});
|
|
187
|
-
return JSON5.parse(content)['version'];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function getOhModulesInfo(
|
|
191
|
-
pkgHarmonyDirPath: AbsolutePath,
|
|
192
|
-
outputDirPath: AbsolutePath
|
|
193
|
-
) {
|
|
194
|
-
const results: {
|
|
195
|
-
archivePath: AbsolutePath;
|
|
196
|
-
archiveFileName: string;
|
|
197
|
-
computedModulePath: AbsolutePath;
|
|
198
|
-
computedModuleName: string;
|
|
199
|
-
}[] = [];
|
|
200
|
-
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return [];
|
|
201
|
-
const names = fs.readdirSync(pkgHarmonyDirPath.getValue());
|
|
202
|
-
for (const name of names) {
|
|
203
|
-
if (name.endsWith('.tar.gz')) {
|
|
204
|
-
const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
|
|
205
|
-
const computedModuleName = pathUtils
|
|
206
|
-
.parse(archivePath.getValue())
|
|
207
|
-
.name.split('.')[0];
|
|
208
|
-
const computedModulePath =
|
|
209
|
-
outputDirPath.copyWithNewSegment(computedModuleName);
|
|
210
|
-
results.push({
|
|
211
|
-
archivePath,
|
|
212
|
-
archiveFileName: name,
|
|
213
|
-
computedModulePath,
|
|
214
|
-
computedModuleName,
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return results;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function unpackTarGz(archivePath: AbsolutePath, outputDirPath: AbsolutePath) {
|
|
222
|
-
if (!fs.existsSync(outputDirPath.getValue())) {
|
|
223
|
-
fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
224
|
-
}
|
|
225
|
-
const readStream = fs.createReadStream(archivePath.getValue());
|
|
226
|
-
const writeStream = tar.extract({
|
|
227
|
-
cwd: outputDirPath.getValue(),
|
|
228
|
-
});
|
|
229
|
-
readStream.pipe(zlib.createGunzip()).pipe(writeStream);
|
|
230
|
-
return new Promise((resolve, reject) => {
|
|
231
|
-
writeStream.on('finish', () => {
|
|
232
|
-
resolve(undefined);
|
|
233
|
-
});
|
|
234
|
-
writeStream.on('error', (err) => {
|
|
235
|
-
reject(err);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
}
|