@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,128 +0,0 @@
|
|
|
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';
|
|
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,240 +0,0 @@
|
|
|
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';
|
|
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
|
-
prefix: true,
|
|
66
|
-
});
|
|
67
|
-
let unpackedArchivesCount = 0;
|
|
68
|
-
let skippedArchivesCount = 0;
|
|
69
|
-
await projectDependenciesManager.forEachAsync(async (dependency) => {
|
|
70
|
-
const packageJSON = dependency.readPackageJSON();
|
|
71
|
-
const harmonyArchivePath = dependency
|
|
72
|
-
.getRootPath()
|
|
73
|
-
.copyWithNewSegment('harmony.tar.gz');
|
|
74
|
-
const pkgHarmonyDirPath = dependency
|
|
75
|
-
.getRootPath()
|
|
76
|
-
.copyWithNewSegment('harmony');
|
|
77
|
-
const harmonyTarGzPathStr = dependency
|
|
78
|
-
.getRootPath()
|
|
79
|
-
.copyWithNewSegment('harmony.tar.gz')
|
|
80
|
-
.relativeTo(projectRootPath)
|
|
81
|
-
.getValue();
|
|
82
|
-
if (
|
|
83
|
-
packageJSON.version &&
|
|
84
|
-
shouldUnpack(
|
|
85
|
-
harmonyArchivePath,
|
|
86
|
-
pkgHarmonyDirPath,
|
|
87
|
-
outputDirPath,
|
|
88
|
-
packageJSON.version
|
|
89
|
-
)
|
|
90
|
-
) {
|
|
91
|
-
if (!fs.existsSync(pkgHarmonyDirPath)) {
|
|
92
|
-
/**
|
|
93
|
-
* After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
|
|
94
|
-
*/
|
|
95
|
-
logger.info(
|
|
96
|
-
(styles) =>
|
|
97
|
-
`[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`
|
|
98
|
-
);
|
|
99
|
-
await unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
|
|
100
|
-
unpackedArchivesCount++;
|
|
101
|
-
} else {
|
|
102
|
-
skippedArchivesCount++;
|
|
103
|
-
logger.info(
|
|
104
|
-
(styles) =>
|
|
105
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
106
|
-
harmonyTarGzPathStr
|
|
107
|
-
)}`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
111
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
112
|
-
const moduleArchivePathStr = dependency
|
|
113
|
-
.getRootPath()
|
|
114
|
-
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
115
|
-
.relativeTo(projectRootPath)
|
|
116
|
-
.getValue();
|
|
117
|
-
logger.info(
|
|
118
|
-
(styles) =>
|
|
119
|
-
`[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`
|
|
120
|
-
);
|
|
121
|
-
unpackedArchivesCount++;
|
|
122
|
-
await unpackTarGz(
|
|
123
|
-
ohModuleInfo.archivePath,
|
|
124
|
-
ohModuleInfo.computedModulePath
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
if (fs.existsSync(harmonyArchivePath)) {
|
|
129
|
-
skippedArchivesCount++;
|
|
130
|
-
logger.info(
|
|
131
|
-
(styles) =>
|
|
132
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
133
|
-
harmonyTarGzPathStr
|
|
134
|
-
)}`
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
138
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
139
|
-
const moduleArchivePathStr = dependency
|
|
140
|
-
.getRootPath()
|
|
141
|
-
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
142
|
-
.relativeTo(projectRootPath)
|
|
143
|
-
.getValue();
|
|
144
|
-
skippedArchivesCount++;
|
|
145
|
-
logger.info(
|
|
146
|
-
(styles) =>
|
|
147
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
148
|
-
moduleArchivePathStr
|
|
149
|
-
)}`
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
logger.info(
|
|
155
|
-
(styles) =>
|
|
156
|
-
`\nUnpacked: ${styles.cyan(
|
|
157
|
-
unpackedArchivesCount
|
|
158
|
-
)}, Skipped: ${styles.yellow(skippedArchivesCount)}`
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function shouldUnpack(
|
|
163
|
-
harmonyArchivePath: AbsolutePath,
|
|
164
|
-
pkgHarmonyDirPath: AbsolutePath,
|
|
165
|
-
outputDirPath: AbsolutePath,
|
|
166
|
-
nodePackageVersion: string
|
|
167
|
-
) {
|
|
168
|
-
if (!fs.existsSync(harmonyArchivePath.getValue())) return false;
|
|
169
|
-
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return true;
|
|
170
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
171
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
172
|
-
if (
|
|
173
|
-
!fs.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
|
|
174
|
-
getOhPackageVersion(ohModuleInfo.computedModulePath) !==
|
|
175
|
-
nodePackageVersion
|
|
176
|
-
) {
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function getOhPackageVersion(modulePath: AbsolutePath) {
|
|
184
|
-
const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
|
|
185
|
-
if (!fs.existsSync(ohPackagePath.getValue())) return null;
|
|
186
|
-
const content = fs.readFileSync(ohPackagePath.getValue(), {
|
|
187
|
-
encoding: 'utf-8',
|
|
188
|
-
});
|
|
189
|
-
return JSON5.parse(content)['version'];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function getOhModulesInfo(
|
|
193
|
-
pkgHarmonyDirPath: AbsolutePath,
|
|
194
|
-
outputDirPath: AbsolutePath
|
|
195
|
-
) {
|
|
196
|
-
const results: {
|
|
197
|
-
archivePath: AbsolutePath;
|
|
198
|
-
archiveFileName: string;
|
|
199
|
-
computedModulePath: AbsolutePath;
|
|
200
|
-
computedModuleName: string;
|
|
201
|
-
}[] = [];
|
|
202
|
-
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return [];
|
|
203
|
-
const names = fs.readdirSync(pkgHarmonyDirPath.getValue());
|
|
204
|
-
for (const name of names) {
|
|
205
|
-
if (name.endsWith('.tar.gz')) {
|
|
206
|
-
const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
|
|
207
|
-
const computedModuleName = pathUtils
|
|
208
|
-
.parse(archivePath.getValue())
|
|
209
|
-
.name.split('.')[0];
|
|
210
|
-
const computedModulePath =
|
|
211
|
-
outputDirPath.copyWithNewSegment(computedModuleName);
|
|
212
|
-
results.push({
|
|
213
|
-
archivePath,
|
|
214
|
-
archiveFileName: name,
|
|
215
|
-
computedModulePath,
|
|
216
|
-
computedModuleName,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return results;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function unpackTarGz(archivePath: AbsolutePath, outputDirPath: AbsolutePath) {
|
|
224
|
-
if (!fs.existsSync(outputDirPath.getValue())) {
|
|
225
|
-
fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
226
|
-
}
|
|
227
|
-
const readStream = fs.createReadStream(archivePath.getValue());
|
|
228
|
-
const writeStream = tar.extract({
|
|
229
|
-
cwd: outputDirPath.getValue(),
|
|
230
|
-
});
|
|
231
|
-
readStream.pipe(zlib.createGunzip()).pipe(writeStream);
|
|
232
|
-
return new Promise((resolve, reject) => {
|
|
233
|
-
writeStream.on('finish', () => {
|
|
234
|
-
resolve(undefined);
|
|
235
|
-
});
|
|
236
|
-
writeStream.on('error', (err) => {
|
|
237
|
-
reject(err);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
}
|