@react-native-oh/react-native-harmony-cli 0.0.26 → 0.0.28
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 +12 -0
- package/dist/assetResolver.js +25 -0
- package/dist/autolinking/Autolinking.js +275 -0
- package/dist/autolinking/index.js +23 -0
- package/dist/codegen/core/CodeGenerator.js +8 -0
- package/dist/codegen/core/CodegenError.js +13 -0
- package/dist/codegen/core/EventUtils.js +25 -0
- package/dist/codegen/core/TypeAnnotationToTS.js +138 -0
- package/dist/codegen/core/UberSchema.js +109 -0
- package/dist/codegen/core/index.js +27 -0
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +67 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +82 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +80 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +62 -0
- package/dist/codegen/generators/LibGlueCodeGenerator.js +56 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +79 -0
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +40 -0
- package/dist/codegen/generators/UberGeneratorV1.js +56 -0
- package/dist/codegen/generators/UberGeneratorV2.js +77 -0
- package/dist/codegen/generators/index.js +30 -0
- package/dist/codegen/index.js +24 -0
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +111 -0
- package/dist/codegen/templates/BasePackageHTemplate.js +136 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +68 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +91 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +198 -0
- package/dist/codegen/templates/IndexTSTemplate.js +58 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +130 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +59 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +48 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +81 -0
- package/dist/codegen/templates/index.js +31 -0
- package/dist/commands/bundle-harmony.js +185 -0
- package/dist/commands/codegen-harmony.js +207 -0
- package/dist/commands/codegen-lib-harmony.js +259 -0
- package/dist/commands/create-metro-host-constants.js +67 -0
- package/dist/commands/index.js +30 -0
- package/dist/commands/link-harmony.js +97 -0
- package/dist/commands/pack-harmony.js +106 -0
- package/dist/commands/unpack-harmony.js +191 -0
- package/dist/commands/verify-package-harmony.js +128 -0
- package/dist/core/AbsolutePath.js +59 -0
- package/dist/core/CodegenConfig.js +63 -0
- package/dist/core/DescriptiveError.js +55 -0
- package/dist/core/FileSystem.js +33 -0
- package/dist/core/OHPackageJSON5.js +29 -0
- package/dist/core/PackageJSON.js +66 -0
- package/dist/core/ProjectDependenciesManager.js +83 -0
- package/dist/core/ValidationError.js +12 -0
- package/dist/core/ValueObject.js +8 -0
- package/dist/core/fs.js +42 -0
- package/dist/core/index.js +32 -0
- package/dist/index.js +22 -0
- package/dist/io/CliExecutor.js +35 -0
- package/dist/io/Logger.js +80 -0
- package/dist/io/RealFS.js +68 -0
- package/dist/io/TarGz.js +34 -0
- package/dist/io/__fixtures__.js +127 -0
- package/dist/io/fsUtils.js +37 -0
- package/dist/io/index.js +26 -0
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +44 -0
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +38 -0
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +32 -0
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +57 -0
- package/dist/package-verifier/checks/index.js +26 -0
- package/dist/package-verifier/index.js +24 -0
- package/dist/package-verifier/types.js +8 -0
- package/dist/package-verifier/verify-package.js +107 -0
- package/jest.config.js +7 -0
- package/package.json +8 -2
- package/react-native.config.js +7 -0
- package/src/assetResolver.ts +7 -0
- package/src/autolinking/Autolinking.test.ts +483 -0
- package/src/autolinking/Autolinking.ts +384 -0
- package/src/autolinking/index.ts +8 -0
- package/src/codegen/core/CodeGenerator.ts +7 -0
- package/src/codegen/core/CodegenError.ts +7 -0
- package/src/codegen/core/EventUtils.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.test.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.ts +7 -0
- package/src/codegen/core/UberSchema.ts +15 -1
- package/src/codegen/core/index.ts +7 -0
- package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +20 -9
- package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +18 -5
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +119 -0
- package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +21 -43
- package/src/codegen/generators/LibGlueCodeGenerator.ts +98 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +14 -5
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +57 -0
- package/src/codegen/generators/UberGeneratorV1.ts +19 -8
- package/src/codegen/generators/UberGeneratorV2.ts +39 -16
- package/src/codegen/generators/index.ts +12 -3
- package/src/codegen/index.ts +7 -0
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +19 -7
- package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +52 -12
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +9 -1
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +15 -10
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +20 -8
- package/src/codegen/templates/IndexTSTemplate.ts +18 -9
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +8 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleHTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +20 -9
- package/src/codegen/templates/index.ts +7 -0
- package/src/commands/bundle-harmony.ts +8 -1
- package/src/commands/codegen-harmony.ts +43 -13
- package/src/commands/codegen-lib-harmony.ts +394 -0
- package/src/commands/create-metro-host-constants.ts +7 -0
- package/src/commands/index.ts +9 -0
- package/src/commands/link-harmony.ts +102 -0
- package/src/commands/pack-harmony.ts +7 -0
- package/src/commands/unpack-harmony.ts +12 -3
- package/src/commands/verify-package-harmony.ts +7 -0
- package/src/core/AbsolutePath.ts +16 -0
- package/src/core/CodegenConfig.ts +7 -0
- package/src/core/DescriptiveError.ts +7 -0
- package/src/core/FileSystem.ts +57 -0
- package/src/core/OHPackageJSON5.ts +7 -0
- package/src/core/PackageJSON.ts +40 -8
- package/src/core/ProjectDependenciesManager.ts +40 -14
- package/src/core/ValidationError.ts +7 -0
- package/src/core/ValueObject.ts +7 -0
- package/src/core/fs.ts +7 -0
- package/src/core/index.ts +8 -0
- package/src/index.ts +11 -0
- package/src/io/CliExecutor.ts +47 -0
- package/src/io/Logger.ts +11 -0
- package/src/io/RealFS.ts +62 -0
- package/src/io/TarGz.ts +7 -0
- package/src/io/__fixtures__.ts +135 -0
- package/src/io/fsUtils.ts +26 -6
- package/src/io/index.ts +8 -0
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +7 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +7 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +7 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +7 -0
- package/src/package-verifier/checks/index.ts +7 -0
- package/src/package-verifier/index.ts +7 -0
- package/src/package-verifier/types.ts +7 -0
- package/src/package-verifier/verify-package.ts +9 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageJSON = void 0;
|
|
4
|
+
const CodegenConfig_1 = require("./CodegenConfig");
|
|
5
|
+
const DescriptiveError_1 = require("./DescriptiveError");
|
|
6
|
+
class PackageJSON {
|
|
7
|
+
static fromProjectRootPath(fs, packageRootPath, projectRootPath) {
|
|
8
|
+
const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
|
|
9
|
+
if (!fs.existsSync(packageJSONPath)) {
|
|
10
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
11
|
+
whatHappened: "Couldn't find 'package.json'",
|
|
12
|
+
whatCanUserDo: {
|
|
13
|
+
default: [
|
|
14
|
+
'Check if the path to project root is correct',
|
|
15
|
+
'Try changing working directory to project root',
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
extraData: packageJSONPath.getValue(),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return new PackageJSON(JSON.parse(fs.readTextSync(packageJSONPath).toString()), packageRootPath, projectRootPath);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
26
|
+
whatHappened: "Couldn't parse package.json",
|
|
27
|
+
whatCanUserDo: {},
|
|
28
|
+
extraData: { packageJSONPath, err },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
constructor(rawPackageJSON, packageRootPath, projectRootPath) {
|
|
33
|
+
this.rawPackageJSON = rawPackageJSON;
|
|
34
|
+
this.packageRootPath = packageRootPath;
|
|
35
|
+
this.projectRootPath = projectRootPath;
|
|
36
|
+
}
|
|
37
|
+
get name() {
|
|
38
|
+
return this.rawPackageJSON.name;
|
|
39
|
+
}
|
|
40
|
+
get version() {
|
|
41
|
+
return this.rawPackageJSON.version;
|
|
42
|
+
}
|
|
43
|
+
get harmony() {
|
|
44
|
+
return this.rawPackageJSON.harmony;
|
|
45
|
+
}
|
|
46
|
+
getCodegenConfigs() {
|
|
47
|
+
var _a;
|
|
48
|
+
/**
|
|
49
|
+
* Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
|
|
50
|
+
* generate code for harmony-specific packages. The shape of this codegenConfig is different
|
|
51
|
+
* that the shape of the shared config, to allow specifying which specific turbo modules or
|
|
52
|
+
* fabric components should be code generated.
|
|
53
|
+
*/
|
|
54
|
+
const rawCodegenConfig = (_a = this.rawPackageJSON.harmony) === null || _a === void 0 ? void 0 : _a.codegenConfig;
|
|
55
|
+
if (!rawCodegenConfig) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(rawCodegenConfig)) {
|
|
59
|
+
return rawCodegenConfig.map((config) => CodegenConfig_1.CodegenConfig.fromRawCodegenConfig(config, this.packageRootPath, this.projectRootPath, this.name));
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
CodegenConfig_1.CodegenConfig.fromRawCodegenConfig(rawCodegenConfig, this.packageRootPath, this.projectRootPath, this.name),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.PackageJSON = PackageJSON;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ProjectDependenciesManager = exports.ProjectDependency = void 0;
|
|
19
|
+
const PackageJSON_1 = require("./PackageJSON");
|
|
20
|
+
class ProjectDependency {
|
|
21
|
+
constructor(fs, packageRootPath, projectRootPath) {
|
|
22
|
+
this.fs = fs;
|
|
23
|
+
this.packageRootPath = packageRootPath;
|
|
24
|
+
this.projectRootPath = projectRootPath;
|
|
25
|
+
}
|
|
26
|
+
getRootPath() {
|
|
27
|
+
return this.packageRootPath;
|
|
28
|
+
}
|
|
29
|
+
getCodegenConfigs() {
|
|
30
|
+
return this.readPackageJSON().getCodegenConfigs();
|
|
31
|
+
}
|
|
32
|
+
getHarFilePath() {
|
|
33
|
+
const packageHarmonyPath = this.packageRootPath.copyWithNewSegment('harmony');
|
|
34
|
+
if (!this.fs.existsSync(packageHarmonyPath)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const harFilePaths = this.fs.findFilePathsWithExtensions(packageHarmonyPath, ['har']);
|
|
38
|
+
if (harFilePaths.length !== 1) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return harFilePaths[0];
|
|
42
|
+
}
|
|
43
|
+
readPackageJSON() {
|
|
44
|
+
return PackageJSON_1.PackageJSON.fromProjectRootPath(this.fs, this.packageRootPath, this.projectRootPath);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.ProjectDependency = ProjectDependency;
|
|
48
|
+
class ProjectDependenciesManager {
|
|
49
|
+
constructor(fs, projectRootPath) {
|
|
50
|
+
this.fs = fs;
|
|
51
|
+
this.projectRootPath = projectRootPath;
|
|
52
|
+
}
|
|
53
|
+
forEachAsync(cb) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
yield this.forEachDependencyInDirectory(cb, this.projectRootPath.copyWithNewSegment('node_modules'));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
forEachDependencyInDirectory(cb, directoryPath) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (!this.fs.existsSync(directoryPath)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (let dirent of this.fs.readDirentsSync(directoryPath)) {
|
|
64
|
+
if (dirent.isDirectory()) {
|
|
65
|
+
if (dirent.name.startsWith('.')) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
else if (dirent.name.startsWith('@')) {
|
|
69
|
+
yield this.forEachDependencyInDirectory(cb, directoryPath.copyWithNewSegment(dirent.name));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const potentialDependencyRootPath = directoryPath.copyWithNewSegment(dirent.name);
|
|
73
|
+
if (!this.fs.existsSync(potentialDependencyRootPath.copyWithNewSegment('package.json'))) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
yield cb(new ProjectDependency(this.fs, potentialDependencyRootPath, this.projectRootPath));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ProjectDependenciesManager = ProjectDependenciesManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ValidationError = void 0;
|
|
10
|
+
class ValidationError extends Error {
|
|
11
|
+
}
|
|
12
|
+
exports.ValidationError = ValidationError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/core/fs.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.maybeRemoveFilesInDirectory = exports.maybeMakeDirectories = void 0;
|
|
13
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
14
|
+
const DescriptiveError_1 = require("./DescriptiveError");
|
|
15
|
+
function maybeMakeDirectories(path) {
|
|
16
|
+
if (!node_fs_1.default.existsSync(path.getValue())) {
|
|
17
|
+
node_fs_1.default.mkdirSync(path.getValue(), { recursive: true });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.maybeMakeDirectories = maybeMakeDirectories;
|
|
21
|
+
function maybeRemoveFilesInDirectory(path) {
|
|
22
|
+
if (!node_fs_1.default.existsSync(path.getValue())) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!node_fs_1.default.lstatSync(path.getValue()).isDirectory()) {
|
|
26
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
27
|
+
whatHappened: "Tried to remove all files from a path that doesn't point to a directory",
|
|
28
|
+
whatCanUserDo: { default: [`Verify path: ${path.getValue()}`] },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const fileOrDirNames = node_fs_1.default.readdirSync(path.getValue());
|
|
32
|
+
fileOrDirNames.forEach((fileOrDirName) => {
|
|
33
|
+
const maybeFilePath = path.copyWithNewSegment(fileOrDirName);
|
|
34
|
+
if (node_fs_1.default.statSync(maybeFilePath.getValue()).isDirectory()) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
node_fs_1.default.unlinkSync(maybeFilePath.getValue());
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.maybeRemoveFilesInDirectory = maybeRemoveFilesInDirectory;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./AbsolutePath"), exports);
|
|
24
|
+
__exportStar(require("./ValidationError"), exports);
|
|
25
|
+
__exportStar(require("./DescriptiveError"), exports);
|
|
26
|
+
__exportStar(require("./ValueObject"), exports);
|
|
27
|
+
__exportStar(require("./PackageJSON"), exports);
|
|
28
|
+
__exportStar(require("./ProjectDependenciesManager"), exports);
|
|
29
|
+
__exportStar(require("./CodegenConfig"), exports);
|
|
30
|
+
__exportStar(require("./fs"), exports);
|
|
31
|
+
__exportStar(require("./OHPackageJSON5"), exports);
|
|
32
|
+
__exportStar(require("./FileSystem"), exports);
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.config = void 0;
|
|
10
|
+
const commands_1 = require("./commands");
|
|
11
|
+
exports.config = {
|
|
12
|
+
commands: [
|
|
13
|
+
commands_1.commandBundleHarmony,
|
|
14
|
+
commands_1.commandPackHarmony,
|
|
15
|
+
commands_1.commandUnpackHarmony,
|
|
16
|
+
commands_1.commandCreateMetroConstantsHarmony,
|
|
17
|
+
commands_1.commandCodegenHarmony,
|
|
18
|
+
commands_1.commandVerifyPackageHarmony,
|
|
19
|
+
commands_1.commandCodegenLibHarmony,
|
|
20
|
+
commands_1.commandLinkHarmony,
|
|
21
|
+
],
|
|
22
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CliExecutor = void 0;
|
|
10
|
+
class CliExecutor {
|
|
11
|
+
stringifyCliArgs(args) {
|
|
12
|
+
return Object.entries(args)
|
|
13
|
+
.filter(([_, value]) => {
|
|
14
|
+
if (typeof value === 'boolean') {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
return value !== undefined && value !== null;
|
|
18
|
+
})
|
|
19
|
+
.map(([key, value]) => {
|
|
20
|
+
const formattedKey = toKebabCase(key);
|
|
21
|
+
if (typeof value === 'boolean') {
|
|
22
|
+
return `--${formattedKey}`;
|
|
23
|
+
}
|
|
24
|
+
return `--${formattedKey} ${value}`;
|
|
25
|
+
})
|
|
26
|
+
.join(' ');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.CliExecutor = CliExecutor;
|
|
30
|
+
function toKebabCase(str) {
|
|
31
|
+
return str
|
|
32
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
33
|
+
.replace(/[\s_]+/g, '-')
|
|
34
|
+
.toLowerCase();
|
|
35
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Logger = void 0;
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
class Logger {
|
|
15
|
+
info(prepareMsg, options) {
|
|
16
|
+
const prefix = (options === null || options === void 0 ? void 0 : options.prefix) ? `[${chalk_1.default.bold(chalk_1.default.cyan('INFO'))}]` : '';
|
|
17
|
+
if (prefix) {
|
|
18
|
+
console.info(prefix, prepareMsg(chalk_1.default));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.info(prepareMsg(chalk_1.default));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
warn(prepareMsg) {
|
|
25
|
+
console.warn(prepareMsg(chalk_1.default));
|
|
26
|
+
}
|
|
27
|
+
debug(prepareMsg) {
|
|
28
|
+
console.debug(prepareMsg(chalk_1.default));
|
|
29
|
+
}
|
|
30
|
+
descriptiveError(error) {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
32
|
+
const lines = [];
|
|
33
|
+
if (error.isUnexpected() && error.stack) {
|
|
34
|
+
lines.push('');
|
|
35
|
+
lines.push(chalk_1.default.bold('Stack'));
|
|
36
|
+
error.stack.split('\n').forEach((line) => lines.push(chalk_1.default.gray(line)));
|
|
37
|
+
}
|
|
38
|
+
const details = error.getDetails();
|
|
39
|
+
if (details) {
|
|
40
|
+
lines.push('');
|
|
41
|
+
lines.push(chalk_1.default.bold('Details'));
|
|
42
|
+
details.split('\n').forEach((line) => lines.push(line));
|
|
43
|
+
}
|
|
44
|
+
lines.push('');
|
|
45
|
+
let prefix = '';
|
|
46
|
+
if (error.isUnexpected()) {
|
|
47
|
+
prefix = '[' + chalk_1.default.red(chalk_1.default.bold('UNEXPECTED_ERROR')) + ']';
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
prefix = '[' + chalk_1.default.red(chalk_1.default.bold('ERROR')) + ']';
|
|
51
|
+
}
|
|
52
|
+
lines.push(`${prefix} ${error.getMessage()}`);
|
|
53
|
+
const suggestionsByRole = error.getSuggestionsByRole();
|
|
54
|
+
if (suggestionsByRole) {
|
|
55
|
+
if (((_b = (_a = suggestionsByRole.default) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
|
|
56
|
+
lines.push('');
|
|
57
|
+
lines.push(chalk_1.default.bold(`Suggestions`));
|
|
58
|
+
(_c = suggestionsByRole.default) === null || _c === void 0 ? void 0 : _c.forEach((suggestion) => {
|
|
59
|
+
lines.push(suggestion);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (((_e = (_d = suggestionsByRole.rnAppDeveloper) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) > 0) {
|
|
63
|
+
lines.push('');
|
|
64
|
+
lines.push(chalk_1.default.bold(`Suggestions for RN App developers`));
|
|
65
|
+
(_f = suggestionsByRole.rnAppDeveloper) === null || _f === void 0 ? void 0 : _f.forEach((suggestion) => {
|
|
66
|
+
lines.push(suggestion);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if ((_h = (_g = suggestionsByRole.rnPackageDeveloper) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) {
|
|
70
|
+
lines.push('');
|
|
71
|
+
lines.push(chalk_1.default.bold(`Suggestions for RN package developers`));
|
|
72
|
+
(_j = suggestionsByRole.rnPackageDeveloper) === null || _j === void 0 ? void 0 : _j.forEach((suggestion) => {
|
|
73
|
+
lines.push(suggestion);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
console.error(lines.join('\n'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.RealFS = void 0;
|
|
22
|
+
const FileSystem_1 = require("../core/FileSystem");
|
|
23
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
24
|
+
class RealFSDirent extends FileSystem_1.Dirent {
|
|
25
|
+
constructor(nodeFSDirent) {
|
|
26
|
+
super();
|
|
27
|
+
this.nodeFSDirent = nodeFSDirent;
|
|
28
|
+
}
|
|
29
|
+
isDirectory() {
|
|
30
|
+
return this.nodeFSDirent.isDirectory();
|
|
31
|
+
}
|
|
32
|
+
get name() {
|
|
33
|
+
return this.nodeFSDirent.name;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class RealFS extends FileSystem_1.FS {
|
|
37
|
+
existsSync(path) {
|
|
38
|
+
return node_fs_1.default.existsSync(path.toString());
|
|
39
|
+
}
|
|
40
|
+
readTextSync(path) {
|
|
41
|
+
return node_fs_1.default.readFileSync(path.toString()).toString();
|
|
42
|
+
}
|
|
43
|
+
readText(path) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
node_fs_1.default.readFile(path.toString(), undefined, (err, data) => {
|
|
47
|
+
if (err) {
|
|
48
|
+
reject(err);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
resolve(data.toString());
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
writeTextSync(path, data) {
|
|
57
|
+
node_fs_1.default.writeFileSync(path.toString(), data);
|
|
58
|
+
}
|
|
59
|
+
readDirentsSync(path, options) {
|
|
60
|
+
return node_fs_1.default
|
|
61
|
+
.readdirSync(path.toString(), {
|
|
62
|
+
withFileTypes: true,
|
|
63
|
+
recursive: options === null || options === void 0 ? void 0 : options.recursive,
|
|
64
|
+
})
|
|
65
|
+
.map((rawDirent) => new RealFSDirent(rawDirent));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.RealFS = RealFS;
|
package/dist/io/TarGz.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.unpackTarGz = void 0;
|
|
13
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
14
|
+
const zlib_1 = __importDefault(require("zlib"));
|
|
15
|
+
const tar_1 = __importDefault(require("tar"));
|
|
16
|
+
function unpackTarGz(archivePath, outputDirPath) {
|
|
17
|
+
if (!node_fs_1.default.existsSync(outputDirPath.getValue())) {
|
|
18
|
+
node_fs_1.default.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
const readStream = node_fs_1.default.createReadStream(archivePath.getValue());
|
|
21
|
+
const writeStream = tar_1.default.extract({
|
|
22
|
+
cwd: outputDirPath.getValue(),
|
|
23
|
+
});
|
|
24
|
+
readStream.pipe(zlib_1.default.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
|
+
}
|
|
34
|
+
exports.unpackTarGz = unpackTarGz;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.MockedLogger = exports.MemFS = exports.FakeCliExecutor = void 0;
|
|
22
|
+
const core_1 = require("../core");
|
|
23
|
+
const CliExecutor_1 = require("./CliExecutor");
|
|
24
|
+
const memfs_1 = require("memfs");
|
|
25
|
+
const Dirent_1 = __importDefault(require("memfs/lib/Dirent"));
|
|
26
|
+
const Logger_1 = require("./Logger");
|
|
27
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
28
|
+
class FakeCliExecutor extends CliExecutor_1.CliExecutor {
|
|
29
|
+
constructor(onRun) {
|
|
30
|
+
super();
|
|
31
|
+
this.onRun = onRun;
|
|
32
|
+
this.commands = [];
|
|
33
|
+
}
|
|
34
|
+
run(command, options = {}) {
|
|
35
|
+
let commandWithArgs = command;
|
|
36
|
+
if (options.args) {
|
|
37
|
+
commandWithArgs += ' ' + this.stringifyCliArgs(options.args);
|
|
38
|
+
}
|
|
39
|
+
this.commands.push(commandWithArgs);
|
|
40
|
+
return this.onRun(commandWithArgs);
|
|
41
|
+
}
|
|
42
|
+
getCommands() {
|
|
43
|
+
return this.commands;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.FakeCliExecutor = FakeCliExecutor;
|
|
47
|
+
class MemFSDirent extends core_1.Dirent {
|
|
48
|
+
constructor(rawDirent) {
|
|
49
|
+
super();
|
|
50
|
+
this.rawDirent = rawDirent;
|
|
51
|
+
}
|
|
52
|
+
isDirectory() {
|
|
53
|
+
return this.rawDirent.isDirectory();
|
|
54
|
+
}
|
|
55
|
+
get name() {
|
|
56
|
+
return this.rawDirent.name.toString();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class MemFS extends core_1.FS {
|
|
60
|
+
constructor(initialFileStructure) {
|
|
61
|
+
super();
|
|
62
|
+
this.fs = (0, memfs_1.memfs)(initialFileStructure, './').fs;
|
|
63
|
+
}
|
|
64
|
+
existsSync(path) {
|
|
65
|
+
return this.fs.existsSync(path.toString());
|
|
66
|
+
}
|
|
67
|
+
readTextSync(path) {
|
|
68
|
+
return this.fs.readFileSync(path.toString()).toString();
|
|
69
|
+
}
|
|
70
|
+
readText(path) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
this.fs.readFile(path.toString(), {}, (err, data) => {
|
|
74
|
+
var _a;
|
|
75
|
+
if (err) {
|
|
76
|
+
reject(err);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
resolve((_a = data === null || data === void 0 ? void 0 : data.toString()) !== null && _a !== void 0 ? _a : '');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
writeTextSync(path, data) {
|
|
85
|
+
return this.fs.writeFileSync(path.toString(), data);
|
|
86
|
+
}
|
|
87
|
+
readDirentsSync(path, options) {
|
|
88
|
+
return this.fs
|
|
89
|
+
.readdirSync(path.toString(), {
|
|
90
|
+
withFileTypes: true,
|
|
91
|
+
recursive: options === null || options === void 0 ? void 0 : options.recursive,
|
|
92
|
+
})
|
|
93
|
+
.flatMap((dataOutOrDirent) => {
|
|
94
|
+
if (!(dataOutOrDirent instanceof Dirent_1.default)) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return [new MemFSDirent(dataOutOrDirent)];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.MemFS = MemFS;
|
|
102
|
+
class MockedLogger extends Logger_1.Logger {
|
|
103
|
+
constructor() {
|
|
104
|
+
super(...arguments);
|
|
105
|
+
this.logs = [];
|
|
106
|
+
}
|
|
107
|
+
debug(prepareMsg) {
|
|
108
|
+
chalk_1.default.level = 0;
|
|
109
|
+
this.logs.push({ type: 'debug', msg: prepareMsg(chalk_1.default) });
|
|
110
|
+
}
|
|
111
|
+
info(prepareMsg, options) {
|
|
112
|
+
chalk_1.default.level = 0;
|
|
113
|
+
this.logs.push({ type: 'info', msg: prepareMsg(chalk_1.default) });
|
|
114
|
+
}
|
|
115
|
+
warn(prepareMsg) {
|
|
116
|
+
chalk_1.default.level = 0;
|
|
117
|
+
this.logs.push({ type: 'warn', msg: prepareMsg(chalk_1.default) });
|
|
118
|
+
}
|
|
119
|
+
descriptiveError(error) {
|
|
120
|
+
chalk_1.default.level = 0;
|
|
121
|
+
this.logs.push({ type: 'error', msg: error.getMessage() });
|
|
122
|
+
}
|
|
123
|
+
getLogs() {
|
|
124
|
+
return this.logs;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.MockedLogger = MockedLogger;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.findFilePathsWithExtensions = void 0;
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const Dirent_1 = __importDefault(require("memfs/lib/Dirent"));
|
|
15
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
+
const node_fs_2 = require("node:fs");
|
|
17
|
+
function findFilePathsWithExtensions(dirPath, fileExtensions, options = {}) {
|
|
18
|
+
var _a;
|
|
19
|
+
const fs = ((_a = options === null || options === void 0 ? void 0 : options.fs) !== null && _a !== void 0 ? _a : node_fs_1.default);
|
|
20
|
+
let results = [];
|
|
21
|
+
const files = fs.readdirSync(dirPath.getValue(), { withFileTypes: true });
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
if (!(file instanceof node_fs_2.Dirent) &&
|
|
24
|
+
!(file instanceof Dirent_1.default)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const path = dirPath.copyWithNewSegment(file.name.toString());
|
|
28
|
+
if (fs.lstatSync(path.toString()).isDirectory()) {
|
|
29
|
+
results = results.concat(findFilePathsWithExtensions(path, fileExtensions, options));
|
|
30
|
+
}
|
|
31
|
+
else if (fileExtensions.includes(node_path_1.default.extname(file.name.toString()).substring(1))) {
|
|
32
|
+
results.push(path);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
exports.findFilePathsWithExtensions = findFilePathsWithExtensions;
|