@react-native-oh/react-native-harmony-cli 0.0.36 → 0.0.40
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/README.md +11 -11
- package/dist/assetResolver.js +74 -43
- package/dist/autolinking/Autolinking.js +183 -179
- package/dist/codegen/core/CodegenError.js +23 -3
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
- package/dist/codegen/core/UberSchema.js +96 -57
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +42 -28
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
- package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
- package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -18
- package/dist/codegen/generators/UberGeneratorV2.js +36 -28
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
- package/dist/codegen/templates/BasePackageHTemplate.js +21 -109
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
- package/dist/codegen/templates/IndexTSTemplate.js +17 -37
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -108
- package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
- package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
- package/dist/commands/bundle-harmony.js +138 -53
- package/dist/commands/codegen-harmony.js +175 -104
- package/dist/commands/codegen-lib-harmony.js +116 -76
- package/dist/commands/create-metro-host-constants.js +47 -18
- package/dist/commands/init.js +961 -537
- package/dist/commands/link-harmony.js +71 -33
- package/dist/commands/pack-harmony.js +108 -47
- package/dist/commands/run-harmony.js +520 -352
- package/dist/commands/unpack-harmony.js +198 -105
- package/dist/commands/verify-package-harmony.js +108 -54
- package/dist/core/AbsolutePath.js +47 -31
- package/dist/core/CodegenConfig.js +22 -24
- package/dist/core/DescriptiveError.js +37 -18
- package/dist/core/FileSystem.js +18 -14
- package/dist/core/OHPackageJSON5.js +23 -17
- package/dist/core/PackageJSON.js +42 -26
- package/dist/core/ProjectDependenciesManager.js +96 -46
- package/dist/core/ValidationError.js +22 -2
- package/dist/core/fs.js +6 -9
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +98 -46
- package/dist/io/Logger.js +46 -40
- package/dist/io/RealFS.js +88 -35
- package/dist/io/TarGz.js +8 -11
- package/dist/io/__fixtures__.js +141 -79
- package/dist/io/fsUtils.js +12 -13
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
- package/dist/package-verifier/verify-package.js +132 -55
- package/dist/simulator/LaunchSimulator.js +395 -0
- package/dist/simulator/index.js +23 -0
- package/jest.config.js +12 -12
- package/package.json +78 -70
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/.prettierrc +0 -6
- package/src/assetResolver.ts +0 -134
- package/src/autolinking/Autolinking.test.ts +0 -483
- package/src/autolinking/Autolinking.ts +0 -382
- package/src/autolinking/index.ts +0 -8
- package/src/codegen/core/CodeGenerator.ts +0 -16
- package/src/codegen/core/CodegenError.ts +0 -10
- package/src/codegen/core/EventUtils.ts +0 -23
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
- package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
- package/src/codegen/core/UberSchema.ts +0 -152
- package/src/codegen/core/index.ts +0 -12
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -120
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
- package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
- package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
- package/src/codegen/generators/UberGeneratorV1.ts +0 -75
- package/src/codegen/generators/UberGeneratorV2.ts +0 -114
- package/src/codegen/generators/index.ts +0 -15
- package/src/codegen/index.ts +0 -9
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
- package/src/codegen/templates/BasePackageHTemplate.ts +0 -147
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
- package/src/codegen/templates/IndexTSTemplate.ts +0 -62
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -138
- package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
- package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
- package/src/codegen/templates/index.ts +0 -16
- package/src/commands/bundle-harmony.ts +0 -134
- package/src/commands/codegen-harmony.ts +0 -297
- package/src/commands/codegen-lib-harmony.ts +0 -389
- package/src/commands/create-metro-host-constants.ts +0 -55
- package/src/commands/index.ts +0 -16
- package/src/commands/init.ts +0 -755
- package/src/commands/link-harmony.ts +0 -102
- package/src/commands/pack-harmony.ts +0 -128
- package/src/commands/run-harmony.ts +0 -478
- package/src/commands/types.ts +0 -21
- package/src/commands/unpack-harmony.ts +0 -238
- package/src/commands/verify-package-harmony.ts +0 -113
- package/src/core/AbsolutePath.ts +0 -66
- package/src/core/CodegenConfig.ts +0 -67
- package/src/core/DescriptiveError.ts +0 -68
- package/src/core/FileSystem.ts +0 -57
- package/src/core/OHPackageJSON5.ts +0 -30
- package/src/core/PackageJSON.ts +0 -104
- package/src/core/ProjectDependenciesManager.ts +0 -103
- package/src/core/ValidationError.ts +0 -8
- package/src/core/ValueObject.ts +0 -9
- package/src/core/fs.ts +0 -38
- package/src/core/index.ts +0 -17
- package/src/index.ts +0 -33
- package/src/io/CliExecutor.ts +0 -69
- package/src/io/Logger.ts +0 -112
- package/src/io/RealFS.ts +0 -62
- package/src/io/TarGz.ts +0 -33
- package/src/io/__fixtures__.ts +0 -139
- package/src/io/fsUtils.ts +0 -44
- package/src/io/index.ts +0 -11
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
- package/src/package-verifier/checks/index.ts +0 -11
- package/src/package-verifier/index.ts +0 -9
- package/src/package-verifier/types.ts +0 -19
- package/src/package-verifier/verify-package.ts +0 -123
package/src/core/PackageJSON.ts
DELETED
|
@@ -1,104 +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
|
-
import { AbsolutePath } from './AbsolutePath';
|
|
8
|
-
import { CodegenConfig, RawCodegenConfig } from './CodegenConfig';
|
|
9
|
-
import { DescriptiveError } from './DescriptiveError';
|
|
10
|
-
import { FS } from './FileSystem';
|
|
11
|
-
|
|
12
|
-
type RawAutolinkingConfig = {
|
|
13
|
-
etsPackageClassName?: string;
|
|
14
|
-
cppPackageClassName?: string;
|
|
15
|
-
cmakeLibraryTargetName?: string;
|
|
16
|
-
ohPackageName?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export class PackageJSON {
|
|
20
|
-
static fromProjectRootPath(
|
|
21
|
-
fs: FS,
|
|
22
|
-
packageRootPath: AbsolutePath,
|
|
23
|
-
projectRootPath: AbsolutePath
|
|
24
|
-
) {
|
|
25
|
-
const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
|
|
26
|
-
if (!fs.existsSync(packageJSONPath)) {
|
|
27
|
-
throw new DescriptiveError({
|
|
28
|
-
whatHappened: "Couldn't find 'package.json'",
|
|
29
|
-
whatCanUserDo: [
|
|
30
|
-
'Check if the path to project root is correct',
|
|
31
|
-
'Try changing working directory to project root',
|
|
32
|
-
],
|
|
33
|
-
extraData: packageJSONPath.getValue(),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
return new PackageJSON(
|
|
38
|
-
JSON.parse(fs.readTextSync(packageJSONPath).toString()),
|
|
39
|
-
packageRootPath,
|
|
40
|
-
projectRootPath
|
|
41
|
-
);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
throw new DescriptiveError({
|
|
44
|
-
whatHappened: "Couldn't parse package.json",
|
|
45
|
-
extraData: { packageJSONPath, err },
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private constructor(
|
|
51
|
-
private rawPackageJSON: Record<string, any>,
|
|
52
|
-
private packageRootPath: AbsolutePath,
|
|
53
|
-
private projectRootPath: AbsolutePath
|
|
54
|
-
) {}
|
|
55
|
-
|
|
56
|
-
get name(): string {
|
|
57
|
-
return this.rawPackageJSON.name;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get version(): string {
|
|
61
|
-
return this.rawPackageJSON.version;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get harmony():
|
|
65
|
-
| undefined
|
|
66
|
-
| {
|
|
67
|
-
alias?: string;
|
|
68
|
-
codegenConfig?: RawCodegenConfig | RawCodegenConfig[];
|
|
69
|
-
autolinking?: RawAutolinkingConfig | null | true;
|
|
70
|
-
} {
|
|
71
|
-
return this.rawPackageJSON.harmony;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getCodegenConfigs(): CodegenConfig[] {
|
|
75
|
-
/**
|
|
76
|
-
* Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
|
|
77
|
-
* generate code for harmony-specific packages. The shape of this codegenConfig is different
|
|
78
|
-
* that the shape of the shared config, to allow specifying which specific turbo modules or
|
|
79
|
-
* fabric components should be code generated.
|
|
80
|
-
*/
|
|
81
|
-
const rawCodegenConfig = this.rawPackageJSON.harmony?.codegenConfig;
|
|
82
|
-
if (!rawCodegenConfig) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
if (Array.isArray(rawCodegenConfig)) {
|
|
86
|
-
return rawCodegenConfig.map((config) =>
|
|
87
|
-
CodegenConfig.fromRawCodegenConfig(
|
|
88
|
-
config,
|
|
89
|
-
this.packageRootPath,
|
|
90
|
-
this.projectRootPath,
|
|
91
|
-
this.name
|
|
92
|
-
)
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return [
|
|
96
|
-
CodegenConfig.fromRawCodegenConfig(
|
|
97
|
-
rawCodegenConfig,
|
|
98
|
-
this.packageRootPath,
|
|
99
|
-
this.projectRootPath,
|
|
100
|
-
this.name
|
|
101
|
-
),
|
|
102
|
-
];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,103 +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 { AbsolutePath } from './AbsolutePath';
|
|
9
|
-
import { PackageJSON } from './PackageJSON';
|
|
10
|
-
import { FS } from '../core';
|
|
11
|
-
|
|
12
|
-
export class ProjectDependency {
|
|
13
|
-
constructor(
|
|
14
|
-
private fs: FS,
|
|
15
|
-
private packageRootPath: AbsolutePath,
|
|
16
|
-
private projectRootPath: AbsolutePath
|
|
17
|
-
) {}
|
|
18
|
-
|
|
19
|
-
getRootPath() {
|
|
20
|
-
return this.packageRootPath;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getCodegenConfigs() {
|
|
24
|
-
return this.readPackageJSON().getCodegenConfigs();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getHarFilePath(): AbsolutePath | null {
|
|
28
|
-
const packageHarmonyPath =
|
|
29
|
-
this.packageRootPath.copyWithNewSegment('harmony');
|
|
30
|
-
if (!this.fs.existsSync(packageHarmonyPath)) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const harFilePaths = this.fs.findFilePathsWithExtensions(
|
|
35
|
-
packageHarmonyPath,
|
|
36
|
-
['har']
|
|
37
|
-
);
|
|
38
|
-
if (harFilePaths.length !== 1) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return harFilePaths[0];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
readPackageJSON() {
|
|
45
|
-
return PackageJSON.fromProjectRootPath(
|
|
46
|
-
this.fs,
|
|
47
|
-
this.packageRootPath,
|
|
48
|
-
this.projectRootPath
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class ProjectDependenciesManager {
|
|
54
|
-
constructor(private fs: FS, private projectRootPath: AbsolutePath) {}
|
|
55
|
-
|
|
56
|
-
async forEachAsync(
|
|
57
|
-
cb: (dependency: ProjectDependency) => Promise<void> | void
|
|
58
|
-
) {
|
|
59
|
-
await this.forEachDependencyInDirectory(
|
|
60
|
-
cb,
|
|
61
|
-
this.projectRootPath.copyWithNewSegment('node_modules')
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private async forEachDependencyInDirectory(
|
|
66
|
-
cb: (dependency: ProjectDependency) => Promise<void> | void,
|
|
67
|
-
directoryPath: AbsolutePath
|
|
68
|
-
) {
|
|
69
|
-
if (!this.fs.existsSync(directoryPath)) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
for (let dirent of this.fs.readDirentsSync(directoryPath)) {
|
|
73
|
-
if (dirent.isDirectory()) {
|
|
74
|
-
if (dirent.name.startsWith('.')) {
|
|
75
|
-
continue;
|
|
76
|
-
} else if (dirent.name.startsWith('@')) {
|
|
77
|
-
await this.forEachDependencyInDirectory(
|
|
78
|
-
cb,
|
|
79
|
-
directoryPath.copyWithNewSegment(dirent.name)
|
|
80
|
-
);
|
|
81
|
-
} else {
|
|
82
|
-
const potentialDependencyRootPath = directoryPath.copyWithNewSegment(
|
|
83
|
-
dirent.name
|
|
84
|
-
);
|
|
85
|
-
if (
|
|
86
|
-
!this.fs.existsSync(
|
|
87
|
-
potentialDependencyRootPath.copyWithNewSegment('package.json')
|
|
88
|
-
)
|
|
89
|
-
) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
await cb(
|
|
93
|
-
new ProjectDependency(
|
|
94
|
-
this.fs,
|
|
95
|
-
potentialDependencyRootPath,
|
|
96
|
-
this.projectRootPath
|
|
97
|
-
)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
package/src/core/ValueObject.ts
DELETED
|
@@ -1,9 +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
|
-
/** https://en.wikipedia.org/wiki/Value_object */
|
|
9
|
-
export interface ValueObject {}
|
package/src/core/fs.ts
DELETED
|
@@ -1,38 +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 fs from 'node:fs';
|
|
9
|
-
import { AbsolutePath } from './AbsolutePath';
|
|
10
|
-
import { DescriptiveError } from './DescriptiveError';
|
|
11
|
-
|
|
12
|
-
export function maybeMakeDirectories(path: AbsolutePath): void {
|
|
13
|
-
if (!fs.existsSync(path.getValue())) {
|
|
14
|
-
fs.mkdirSync(path.getValue(), { recursive: true });
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function maybeRemoveFilesInDirectory(path: AbsolutePath): void {
|
|
19
|
-
if (!fs.existsSync(path.getValue())) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (!fs.lstatSync(path.getValue()).isDirectory()) {
|
|
23
|
-
throw new DescriptiveError({
|
|
24
|
-
whatHappened:
|
|
25
|
-
"Tried to remove all files from a path that doesn't point to a directory",
|
|
26
|
-
whatCanUserDo: [`Verify path: ${path.getValue()}`],
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
const fileOrDirNames = fs.readdirSync(path.getValue());
|
|
30
|
-
fileOrDirNames.forEach((fileOrDirName) => {
|
|
31
|
-
const maybeFilePath = path.copyWithNewSegment(fileOrDirName);
|
|
32
|
-
if (fs.statSync(maybeFilePath.getValue()).isDirectory()) {
|
|
33
|
-
return;
|
|
34
|
-
} else {
|
|
35
|
-
fs.unlinkSync(maybeFilePath.getValue());
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
package/src/core/index.ts
DELETED
|
@@ -1,17 +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
|
-
export * from './AbsolutePath';
|
|
9
|
-
export * from './ValidationError';
|
|
10
|
-
export * from './DescriptiveError';
|
|
11
|
-
export * from './ValueObject';
|
|
12
|
-
export * from './PackageJSON';
|
|
13
|
-
export * from './ProjectDependenciesManager';
|
|
14
|
-
export * from './CodegenConfig';
|
|
15
|
-
export * from './fs';
|
|
16
|
-
export * from './OHPackageJSON5';
|
|
17
|
-
export * from './FileSystem';
|
package/src/index.ts
DELETED
|
@@ -1,33 +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 { Config, Command } from '@react-native-community/cli-types';
|
|
9
|
-
import {
|
|
10
|
-
commandBundleHarmony,
|
|
11
|
-
commandPackHarmony,
|
|
12
|
-
commandUnpackHarmony,
|
|
13
|
-
commandCreateMetroConstantsHarmony,
|
|
14
|
-
commandCodegenHarmony,
|
|
15
|
-
commandVerifyPackageHarmony,
|
|
16
|
-
commandCodegenLibHarmony,
|
|
17
|
-
commandLinkHarmony,
|
|
18
|
-
commandRunHarmony,
|
|
19
|
-
} from './commands';
|
|
20
|
-
|
|
21
|
-
export const config = {
|
|
22
|
-
commands: [
|
|
23
|
-
commandBundleHarmony,
|
|
24
|
-
commandPackHarmony,
|
|
25
|
-
commandUnpackHarmony,
|
|
26
|
-
commandCreateMetroConstantsHarmony,
|
|
27
|
-
commandCodegenHarmony,
|
|
28
|
-
commandVerifyPackageHarmony,
|
|
29
|
-
commandCodegenLibHarmony,
|
|
30
|
-
commandLinkHarmony,
|
|
31
|
-
commandRunHarmony,
|
|
32
|
-
] as Command[],
|
|
33
|
-
} satisfies Partial<Config>;
|
package/src/io/CliExecutor.ts
DELETED
|
@@ -1,69 +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 { AbsolutePath } from '../core';
|
|
9
|
-
import { spawn } from 'node:child_process';
|
|
10
|
-
|
|
11
|
-
export type CliOptions = {
|
|
12
|
-
args: string[];
|
|
13
|
-
cwd?: AbsolutePath;
|
|
14
|
-
onArgsStringified?: (commandWithArgs: string) => void;
|
|
15
|
-
onStdout?: (data: string) => void;
|
|
16
|
-
onStderr?: (data: string) => void;
|
|
17
|
-
shell?: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export abstract class CliExecutor {
|
|
21
|
-
abstract run(command: string, options?: CliOptions): Promise<string>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class RealCliExecutor extends CliExecutor {
|
|
25
|
-
async run(command: string, options?: CliOptions): Promise<string> {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
let commandWithArgs = command;
|
|
28
|
-
let argStrings: string[] = [];
|
|
29
|
-
if (options?.args) {
|
|
30
|
-
argStrings = options.args;
|
|
31
|
-
commandWithArgs += ' ' + argStrings.join(' ');
|
|
32
|
-
}
|
|
33
|
-
options?.onArgsStringified?.(commandWithArgs);
|
|
34
|
-
const process = spawn(command, argStrings, {
|
|
35
|
-
cwd: options?.cwd?.toString(),
|
|
36
|
-
shell: options?.shell ? true : false,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
let stdout = '';
|
|
40
|
-
let stderr = '';
|
|
41
|
-
|
|
42
|
-
process.stdout.on('data', (data) => {
|
|
43
|
-
const output = data.toString();
|
|
44
|
-
stdout += output;
|
|
45
|
-
options?.onStdout?.(output);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
process.stderr.on('data', (data) => {
|
|
49
|
-
const output = data.toString();
|
|
50
|
-
stderr += output;
|
|
51
|
-
options?.onStderr?.(output);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
process.on('error', (error) => {
|
|
55
|
-
reject(error);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
process.on('close', (code) => {
|
|
59
|
-
if (code === 0) {
|
|
60
|
-
resolve(stdout);
|
|
61
|
-
} else {
|
|
62
|
-
reject(
|
|
63
|
-
new Error(`Command failed with code ${code}\nStderr: ${stderr}`)
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
package/src/io/Logger.ts
DELETED
|
@@ -1,112 +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 chalk from 'chalk';
|
|
9
|
-
import { DescriptiveError } from '../core';
|
|
10
|
-
import { getLoader, logger as LOGGER } from '@react-native-community/cli-tools';
|
|
11
|
-
import process from 'node:process';
|
|
12
|
-
export class Logger {
|
|
13
|
-
private loader = getLoader({
|
|
14
|
-
interval: process.stdout.isTTY ? undefined : 0,
|
|
15
|
-
});
|
|
16
|
-
private logger = LOGGER;
|
|
17
|
-
private isLoaderActive = false;
|
|
18
|
-
|
|
19
|
-
start(prepareMsg: (styles: typeof chalk) => string) {
|
|
20
|
-
this.loader.start(prepareMsg(chalk));
|
|
21
|
-
this.isLoaderActive = true;
|
|
22
|
-
return (options?: { persist?: boolean }) => {
|
|
23
|
-
this.isLoaderActive = false;
|
|
24
|
-
if (options?.persist) {
|
|
25
|
-
console.log({ loader: this.loader });
|
|
26
|
-
this.loader.stopAndPersist();
|
|
27
|
-
} else {
|
|
28
|
-
this.loader.stop();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
info(prepareMsg: (styles: typeof chalk) => string) {
|
|
34
|
-
const info = (msg: string) => {
|
|
35
|
-
this.isLoaderActive ? this.loader.info(msg) : this.logger.info(msg);
|
|
36
|
-
};
|
|
37
|
-
info(prepareMsg(chalk));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
succeed(prepareMsg: (styles: typeof chalk) => string) {
|
|
41
|
-
const succeed = (msg: string) =>
|
|
42
|
-
this.isLoaderActive ? this.loader.succeed(msg) : this.logger.success(msg);
|
|
43
|
-
succeed(prepareMsg(chalk));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
warn(prepareMsg: (styles: typeof chalk) => string) {
|
|
47
|
-
const warn = (msg: string) =>
|
|
48
|
-
this.isLoaderActive ? this.loader.warn(msg) : this.logger.warn(msg);
|
|
49
|
-
warn(prepareMsg(chalk));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
debug(prepareMsg: (styles: typeof chalk) => string) {
|
|
53
|
-
if (this.isLoaderActive) {
|
|
54
|
-
clearLine(process.stdout);
|
|
55
|
-
moveCursor(process.stdout, 0);
|
|
56
|
-
console.debug(prepareMsg(chalk));
|
|
57
|
-
this.loader.render();
|
|
58
|
-
} else {
|
|
59
|
-
console.debug(prepareMsg(chalk));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
descriptiveError(error: DescriptiveError) {
|
|
64
|
-
const lines: string[] = [];
|
|
65
|
-
if (error.isUnexpected() && error.stack) {
|
|
66
|
-
lines.push('');
|
|
67
|
-
lines.push(chalk.bold('Stack'));
|
|
68
|
-
error.stack.split('\n').forEach((line) => lines.push(chalk.gray(line)));
|
|
69
|
-
}
|
|
70
|
-
const details = error.getDetails();
|
|
71
|
-
if (details) {
|
|
72
|
-
lines.push('');
|
|
73
|
-
lines.push(chalk.bold('Details'));
|
|
74
|
-
details.split('\n').forEach((line) => lines.push(line));
|
|
75
|
-
}
|
|
76
|
-
lines.push('');
|
|
77
|
-
lines.push(`${error.getMessage()}`);
|
|
78
|
-
const suggestions = error.getSuggestions();
|
|
79
|
-
|
|
80
|
-
if (suggestions.length > 0) {
|
|
81
|
-
lines.push('');
|
|
82
|
-
lines.push(chalk.bold(`Suggestions`));
|
|
83
|
-
suggestions.forEach((suggestion) => {
|
|
84
|
-
lines.push('• ' + suggestion);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (this.isLoaderActive) {
|
|
89
|
-
this.loader.fail(lines.join('\n').trim());
|
|
90
|
-
} else {
|
|
91
|
-
this.logger.error(lines.join('\n').trim());
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const clearLine = (stream: NodeJS.WriteStream): void => {
|
|
97
|
-
if (stream.clearLine) {
|
|
98
|
-
stream.clearLine(0);
|
|
99
|
-
} else {
|
|
100
|
-
process.stdout.write(
|
|
101
|
-
'\r' + ' '.repeat(process.stdout.columns || 80) + '\r'
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const moveCursor = (stream: NodeJS.WriteStream, x: number): void => {
|
|
107
|
-
if (stream.cursorTo) {
|
|
108
|
-
stream.cursorTo(x);
|
|
109
|
-
} else {
|
|
110
|
-
process.stdout.write('\r');
|
|
111
|
-
}
|
|
112
|
-
};
|
package/src/io/RealFS.ts
DELETED
|
@@ -1,62 +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 { AbsolutePath } from '../core';
|
|
9
|
-
import { Dirent, FS } from '../core/FileSystem';
|
|
10
|
-
import fs, { Dirent as NodeFSDirent } from 'node:fs';
|
|
11
|
-
|
|
12
|
-
class RealFSDirent extends Dirent {
|
|
13
|
-
constructor(private nodeFSDirent: NodeFSDirent) {
|
|
14
|
-
super();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
isDirectory(): boolean {
|
|
18
|
-
return this.nodeFSDirent.isDirectory();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get name(): string {
|
|
22
|
-
return this.nodeFSDirent.name;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class RealFS extends FS {
|
|
27
|
-
existsSync(path: AbsolutePath): boolean {
|
|
28
|
-
return fs.existsSync(path.toString());
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
readTextSync(path: AbsolutePath): string {
|
|
32
|
-
return fs.readFileSync(path.toString()).toString();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async readText(path: AbsolutePath): Promise<string> {
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
fs.readFile(path.toString(), undefined, (err, data) => {
|
|
38
|
-
if (err) {
|
|
39
|
-
reject(err);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
resolve(data.toString());
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
writeTextSync(path: AbsolutePath, data: string): void {
|
|
48
|
-
fs.writeFileSync(path.toString(), data);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
readDirentsSync(
|
|
52
|
-
path: AbsolutePath,
|
|
53
|
-
options?: { recursive?: boolean | undefined } | undefined
|
|
54
|
-
): Dirent[] {
|
|
55
|
-
return fs
|
|
56
|
-
.readdirSync(path.toString(), {
|
|
57
|
-
withFileTypes: true,
|
|
58
|
-
recursive: options?.recursive,
|
|
59
|
-
})
|
|
60
|
-
.map((rawDirent) => new RealFSDirent(rawDirent));
|
|
61
|
-
}
|
|
62
|
-
}
|
package/src/io/TarGz.ts
DELETED
|
@@ -1,33 +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 fs from 'node:fs';
|
|
9
|
-
import zlib from 'zlib';
|
|
10
|
-
import tar from 'tar';
|
|
11
|
-
import { AbsolutePath } from '../core';
|
|
12
|
-
|
|
13
|
-
export function unpackTarGz(
|
|
14
|
-
archivePath: AbsolutePath,
|
|
15
|
-
outputDirPath: AbsolutePath
|
|
16
|
-
) {
|
|
17
|
-
if (!fs.existsSync(outputDirPath.getValue())) {
|
|
18
|
-
fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
19
|
-
}
|
|
20
|
-
const readStream = fs.createReadStream(archivePath.getValue());
|
|
21
|
-
const writeStream = tar.extract({
|
|
22
|
-
cwd: outputDirPath.getValue(),
|
|
23
|
-
});
|
|
24
|
-
readStream.pipe(zlib.createGunzip()).pipe(writeStream);
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
writeStream.on('finish', () => {
|
|
27
|
-
resolve(undefined);
|
|
28
|
-
});
|
|
29
|
-
writeStream.on('error', (err) => {
|
|
30
|
-
reject(err);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|