@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,207 @@
|
|
|
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.commandCodegenHarmony = void 0;
|
|
22
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
23
|
+
const case_1 = __importDefault(require("case"));
|
|
24
|
+
const core_1 = require("../core");
|
|
25
|
+
const codegen_1 = require("../codegen");
|
|
26
|
+
const io_1 = require("../io");
|
|
27
|
+
exports.commandCodegenHarmony = {
|
|
28
|
+
name: 'codegen-harmony',
|
|
29
|
+
description: 'Generates boilerplate, types, and utilities from Turbo Module and Fabric Component specifications. This command is meant to be executed during the application build process.',
|
|
30
|
+
options: [
|
|
31
|
+
{
|
|
32
|
+
name: '--rnoh-module-path <path>',
|
|
33
|
+
description: 'Specifies the relative path to the rnoh OHOS module',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: '--cpp-output-path <path>',
|
|
37
|
+
description: 'Specifies the relative path to the output directory intended for storing generated C++ files',
|
|
38
|
+
default: './harmony/entry/src/main/cpp/generated',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: '--project-root-path <path>',
|
|
42
|
+
description: 'Relative path to package root',
|
|
43
|
+
default: '.',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: '--debug [boolean]',
|
|
47
|
+
description: 'Enables logging details',
|
|
48
|
+
default: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: '--no-safety-check [boolean]',
|
|
52
|
+
description: 'Skips the check that prevents file operations outside the current working directory. This command permanently deletes previously generated files. Files are generated in the path specified by cpp-output-path.',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
func: (_argv, _config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const logger = new io_1.Logger();
|
|
57
|
+
const fs = new io_1.RealFS();
|
|
58
|
+
try {
|
|
59
|
+
const MAX_SUPPORTED_CODEGEN_VERSION = 2;
|
|
60
|
+
// prepare the input data
|
|
61
|
+
validateArgs(args);
|
|
62
|
+
const etsOutputPath = new core_1.AbsolutePath(args.rnohModulePath).copyWithNewSegment('generated');
|
|
63
|
+
const enableSafetyCheck = args.safetyCheck;
|
|
64
|
+
const cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
|
|
65
|
+
const projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
|
|
66
|
+
const uberSchemaFromArkTSLibraries = yield codegen_1.UberSchema.fromProject(fs, projectRootPath, (codegenVersion, packageName) => {
|
|
67
|
+
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
|
|
68
|
+
return codegenVersion === 1;
|
|
69
|
+
});
|
|
70
|
+
const cApiLibrariesData = yield collectLibrariesData(fs, projectRootPath, (codegenVersion, packageName) => {
|
|
71
|
+
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
|
|
72
|
+
return codegenVersion === 2;
|
|
73
|
+
});
|
|
74
|
+
// instantiate objects
|
|
75
|
+
const codegenNoticeLines = [
|
|
76
|
+
'This code was generated by "react-native codegen-harmony"',
|
|
77
|
+
'',
|
|
78
|
+
'Do not edit this file as changes may cause incorrect behavior and will be',
|
|
79
|
+
'lost once the code is regenerated.',
|
|
80
|
+
];
|
|
81
|
+
const uberGeneratorV1 = new codegen_1.UberGeneratorV1(cppOutputPath, etsOutputPath, [...codegenNoticeLines, '', '@generatorVersion: 1']);
|
|
82
|
+
const uberGeneratorV2 = new codegen_1.UberGeneratorV2(cppOutputPath, etsOutputPath, [...codegenNoticeLines, '', '@generatorVersion: 2']);
|
|
83
|
+
const glueCodeGenerator = new codegen_1.AppBuildTimeGlueCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines);
|
|
84
|
+
// generate the code
|
|
85
|
+
const fileContentByPath = new Map();
|
|
86
|
+
const appendToFileContentByPath = (fileContent, path) => {
|
|
87
|
+
fileContentByPath.set(path, fileContent);
|
|
88
|
+
};
|
|
89
|
+
uberGeneratorV1
|
|
90
|
+
.generate(uberSchemaFromArkTSLibraries)
|
|
91
|
+
.forEach(appendToFileContentByPath);
|
|
92
|
+
uberGeneratorV2
|
|
93
|
+
.generate(cApiLibrariesData)
|
|
94
|
+
.forEach(appendToFileContentByPath);
|
|
95
|
+
glueCodeGenerator
|
|
96
|
+
.generate({
|
|
97
|
+
v1: uberGeneratorV1.getGlueCodeData(),
|
|
98
|
+
v2: uberGeneratorV2.getGlueCodeData(),
|
|
99
|
+
})
|
|
100
|
+
.forEach(appendToFileContentByPath);
|
|
101
|
+
// output the results
|
|
102
|
+
if (args.debug) {
|
|
103
|
+
const uberSchema = yield codegen_1.UberSchema.fromProject(fs, projectRootPath);
|
|
104
|
+
logger.debug((styles) => styles.gray(JSON.stringify(uberSchema.getValue(), null, 2)));
|
|
105
|
+
}
|
|
106
|
+
saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck);
|
|
107
|
+
logCodegenResult(logger, fileContentByPath, projectRootPath);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
if (err instanceof core_1.DescriptiveError) {
|
|
111
|
+
logger.descriptiveError(err);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
118
|
+
function validateArgs(args) {
|
|
119
|
+
if (!args.rnohModulePath) {
|
|
120
|
+
throw new core_1.DescriptiveError({
|
|
121
|
+
whatHappened: "--rnoh-module-path argument wasn't provided",
|
|
122
|
+
whatCanUserDo: {
|
|
123
|
+
default: [
|
|
124
|
+
'Please provide a path to the native React Native for Open Harmony module (rnoh) which is probably located somewhere in "<PROJECT_ROOT>/harmony" directory',
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function collectLibrariesData(fs, projectRootPath, onShouldAcceptCodegenConfig) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const packageJSONs = [
|
|
133
|
+
core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath),
|
|
134
|
+
];
|
|
135
|
+
yield new core_1.ProjectDependenciesManager(fs, projectRootPath).forEachAsync((dependency) => {
|
|
136
|
+
packageJSONs.push(dependency.readPackageJSON());
|
|
137
|
+
});
|
|
138
|
+
const results = [];
|
|
139
|
+
for (const packageJSON of packageJSONs) {
|
|
140
|
+
const codegenConfigs = packageJSON.getCodegenConfigs();
|
|
141
|
+
for (const codegenConfig of codegenConfigs) {
|
|
142
|
+
if (codegenConfig &&
|
|
143
|
+
onShouldAcceptCodegenConfig(codegenConfig.getVersion(), packageJSON.name)) {
|
|
144
|
+
results.push({
|
|
145
|
+
libraryCppName: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
|
|
146
|
+
uberSchema: codegen_1.UberSchema.fromCodegenConfig(codegenConfig),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return results;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function throwErrorIfUnsupportedCodegenVersion(codegenVersion, maxSupportedCodegenVersion, packageName) {
|
|
155
|
+
if (codegenVersion > maxSupportedCodegenVersion) {
|
|
156
|
+
throw new codegen_1.CodegenError({
|
|
157
|
+
whatHappened: `Package "${packageName}" requires codegenVersion: ${codegenVersion}, which is not supported (maxSupportedCodegenVersion=${maxSupportedCodegenVersion}).`,
|
|
158
|
+
whatCanUserDo: {
|
|
159
|
+
rnAppDeveloper: [
|
|
160
|
+
`Try downgrading "${packageName}".`,
|
|
161
|
+
'Update the "@rnoh/react-native-harmony-cli" package.',
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck) {
|
|
168
|
+
prepareDirectory(cppOutputPath, enableSafetyCheck);
|
|
169
|
+
prepareDirectory(etsOutputPath, enableSafetyCheck);
|
|
170
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
|
|
171
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
|
|
172
|
+
fileContentByPath.forEach((_fileContent, path) => {
|
|
173
|
+
prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
|
|
174
|
+
});
|
|
175
|
+
fileContentByPath.forEach((fileContent, path) => {
|
|
176
|
+
fs.writeTextSync(path, fileContent);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function prepareDirectory(path, enableSafetyCheck) {
|
|
180
|
+
(0, core_1.maybeMakeDirectories)(path);
|
|
181
|
+
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
182
|
+
throw new core_1.DescriptiveError({
|
|
183
|
+
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
184
|
+
whatCanUserDo: { default: ['Run codegen from different location'] },
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
188
|
+
}
|
|
189
|
+
function logCodegenResult(logger, fileContentByPath, projectRootPath) {
|
|
190
|
+
const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => node_path_1.default.relative(projectRootPath.getValue(), path.getValue()));
|
|
191
|
+
sortedRelativePathStrings.sort();
|
|
192
|
+
sortedRelativePathStrings.forEach((pathStr) => {
|
|
193
|
+
logger.info((styles) => styles.gray(`• ${pathStr}`));
|
|
194
|
+
});
|
|
195
|
+
logger.info(() => '');
|
|
196
|
+
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`, { prefix: true });
|
|
197
|
+
logger.info(() => '');
|
|
198
|
+
}
|
|
199
|
+
function deriveCppDirectoryNameFromNpmPackageName(npmPackageName) {
|
|
200
|
+
let result = npmPackageName;
|
|
201
|
+
if (npmPackageName.includes('/')) {
|
|
202
|
+
result.replace('@', '');
|
|
203
|
+
result = npmPackageName.replace('/', '__');
|
|
204
|
+
}
|
|
205
|
+
result = case_1.default.snake(result);
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
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.commandCodegenLibHarmony = void 0;
|
|
22
|
+
const core_1 = require("../core");
|
|
23
|
+
const io_1 = require("../io");
|
|
24
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
25
|
+
const codegen_1 = require("../codegen");
|
|
26
|
+
const case_1 = __importDefault(require("case"));
|
|
27
|
+
const LibGlueCodeGenerator_1 = require("../codegen/generators/LibGlueCodeGenerator");
|
|
28
|
+
const COMMAND_NAME = 'codegen-lib-harmony';
|
|
29
|
+
exports.commandCodegenLibHarmony = {
|
|
30
|
+
name: COMMAND_NAME,
|
|
31
|
+
description: 'Generates boilerplate, types, and utilities from Turbo Module and Fabric Component specifications. Designed for library developers who want to include generated code in their libraries.',
|
|
32
|
+
options: [
|
|
33
|
+
{
|
|
34
|
+
name: '--npm-package-name <string>',
|
|
35
|
+
description: 'Name of your React Native library. This value is processed and used as a directory name for C++ files to reduce the chances of conflicts between libraries.',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: '--turbo-modules-spec-paths [path]',
|
|
39
|
+
description: 'Path or paths to Turbo Module spec files. Each path can point to a spec file or a directory containing spec files.',
|
|
40
|
+
parse: (val) => val.split(' '),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: '--arkts-components-spec-paths [path]',
|
|
44
|
+
description: 'Path or paths to component spec files used to generate code for components to be implemented on the ArkTS side. Each path can point to a spec file or a directory containing spec files.',
|
|
45
|
+
parse: (val) => val.split(' '),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: '--cpp-components-spec-paths [path]',
|
|
49
|
+
description: 'Path or paths to component spec files used to generate code for components to be implemented on the C++ side. Each path can point to a spec file or a directory containing spec files.',
|
|
50
|
+
parse: (val) => val.split(' '),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: '--cpp-output-path <path>',
|
|
54
|
+
description: 'Specifies the relative path to the output directory intended for storing generated C++ files.',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: '--ets-output-path <path>',
|
|
58
|
+
description: 'Specifies the relative path to the output directory intended for storing generated ETS files.',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: '--no-safety-check [boolean]',
|
|
62
|
+
description: 'Skips the check that prevents file operations outside the current working directory. This command permanently deletes previously generated files. Files are generated in the path specified by cpp-output-path.',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const logger = new io_1.Logger();
|
|
67
|
+
try {
|
|
68
|
+
const { args, uberSchemaByType } = validateArgsAndRetrieveUberSchemaByType(rawArgs);
|
|
69
|
+
const fileContentByPath = generateCodeInMemory({
|
|
70
|
+
args,
|
|
71
|
+
uberSchemaByType,
|
|
72
|
+
});
|
|
73
|
+
saveAndLogCodegenResult(args, logger, fileContentByPath);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (err instanceof core_1.DescriptiveError && !err.isUnexpected()) {
|
|
77
|
+
logger.descriptiveError(err);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
84
|
+
function validateArgsAndRetrieveUberSchemaByType(rawArgs) {
|
|
85
|
+
const args = validateRawArgs(rawArgs);
|
|
86
|
+
const arkTSComponentSpecPaths = specPathsToSpecFilePaths(args.arkTSComponentsSpecPaths);
|
|
87
|
+
const turboModulesUberSchema = codegen_1.UberSchema.fromSpecFilePaths(specPathsToSpecFilePaths(args.tmSpecPaths));
|
|
88
|
+
const arkTSComponentsUberSchema = codegen_1.UberSchema.fromSpecFilePaths(arkTSComponentSpecPaths);
|
|
89
|
+
const cppComponentSpecPaths = specPathsToSpecFilePaths(args.cppComponentsSpecPaths);
|
|
90
|
+
const cppComponentsUberSchema = codegen_1.UberSchema.fromSpecFilePaths(cppComponentSpecPaths);
|
|
91
|
+
const componentsUberSchema = codegen_1.UberSchema.fromSpecFilePaths([
|
|
92
|
+
...arkTSComponentSpecPaths,
|
|
93
|
+
...cppComponentSpecPaths,
|
|
94
|
+
]);
|
|
95
|
+
return {
|
|
96
|
+
args,
|
|
97
|
+
uberSchemaByType: {
|
|
98
|
+
turboModulesUberSchema,
|
|
99
|
+
arkTSComponentsUberSchema,
|
|
100
|
+
cppComponentsUberSchema,
|
|
101
|
+
componentsUberSchema,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function validateRawArgs(rawArgs) {
|
|
106
|
+
var _a, _b, _c;
|
|
107
|
+
if (!rawArgs.npmPackageName) {
|
|
108
|
+
throw new core_1.DescriptiveError({
|
|
109
|
+
whatHappened: '--npm-package-name is required',
|
|
110
|
+
whatCanUserDo: { default: ['Please specify --npm-package-name'] },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (!rawArgs.cppOutputPath) {
|
|
114
|
+
throw new core_1.DescriptiveError({
|
|
115
|
+
whatHappened: '--cpp-output-path is required',
|
|
116
|
+
whatCanUserDo: { default: ['Please specify --cpp-output-path'] },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (!rawArgs.etsOutputPath) {
|
|
120
|
+
throw new core_1.DescriptiveError({
|
|
121
|
+
whatHappened: '--ets-output-path is required',
|
|
122
|
+
whatCanUserDo: { default: ['Please specify --ets-output-path'] },
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
npmPackageName: rawArgs.npmPackageName,
|
|
127
|
+
tmSpecPaths: ((_a = rawArgs.turboModulesSpecPaths) !== null && _a !== void 0 ? _a : []).map((path) => new core_1.AbsolutePath(path)),
|
|
128
|
+
arkTSComponentsSpecPaths: ((_b = rawArgs.arktsComponentsSpecPaths) !== null && _b !== void 0 ? _b : []).map((path) => new core_1.AbsolutePath(path)),
|
|
129
|
+
cppComponentsSpecPaths: ((_c = rawArgs.cppComponentsSpecPaths) !== null && _c !== void 0 ? _c : []).map((path) => new core_1.AbsolutePath(path)),
|
|
130
|
+
etsOutputPath: new core_1.AbsolutePath(rawArgs.etsOutputPath),
|
|
131
|
+
cppOutputPath: new core_1.AbsolutePath(rawArgs.cppOutputPath),
|
|
132
|
+
safetyCheck: !!rawArgs.safetyCheck,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function specPathsToSpecFilePaths(specPaths) {
|
|
136
|
+
const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
137
|
+
return specPaths.flatMap((specPath) => {
|
|
138
|
+
if (!node_fs_1.default.existsSync(specPath.getValue())) {
|
|
139
|
+
throw new core_1.DescriptiveError({
|
|
140
|
+
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
141
|
+
whatCanUserDo: {
|
|
142
|
+
default: [`Are you sure provided specPath exists?`],
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
|
|
147
|
+
return (0, io_1.findFilePathsWithExtensions)(specPath, SUPPORTED_SPEC_EXTENSIONS);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
const ext = specPath.getExtension();
|
|
151
|
+
if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
|
|
152
|
+
return [specPath];
|
|
153
|
+
}
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function generateCodeInMemory({ args, uberSchemaByType: { arkTSComponentsUberSchema, componentsUberSchema, cppComponentsUberSchema, turboModulesUberSchema, }, }) {
|
|
159
|
+
const CODEGEN_NOTICE_LINES = [
|
|
160
|
+
`This code was generated by "react-native ${COMMAND_NAME}"`,
|
|
161
|
+
];
|
|
162
|
+
const fileContentByPath = new Map();
|
|
163
|
+
const appendToFileContentByPath = (fileContent, path) => {
|
|
164
|
+
fileContentByPath.set(path, fileContent);
|
|
165
|
+
};
|
|
166
|
+
const turboModuleGlueCodeData = turboModulesUberSchema
|
|
167
|
+
.findAllSpecSchemasByType('NativeModule')
|
|
168
|
+
.map((specSchema) => {
|
|
169
|
+
const nativeModuleCodeGenerator = new codegen_1.NativeModuleCodeGenerator(args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), args.etsOutputPath.copyWithNewSegment('turboModules'), CODEGEN_NOTICE_LINES, '@rnoh/react-native-openharmony/ts');
|
|
170
|
+
nativeModuleCodeGenerator
|
|
171
|
+
.generate(specSchema)
|
|
172
|
+
.forEach(appendToFileContentByPath);
|
|
173
|
+
return nativeModuleCodeGenerator.getGlueCodeData();
|
|
174
|
+
})
|
|
175
|
+
.flat();
|
|
176
|
+
const arkTSComponentCodeGeneratorCAPI = new codegen_1.ArkTSComponentCodeGeneratorCAPI(args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components'), args.etsOutputPath.copyWithNewSegment('components'), CODEGEN_NOTICE_LINES, '@rnoh/react-native-openharmony/ts');
|
|
177
|
+
arkTSComponentCodeGeneratorCAPI
|
|
178
|
+
.generate(arkTSComponentsUberSchema)
|
|
179
|
+
.forEach(appendToFileContentByPath);
|
|
180
|
+
const libraryCppName = deriveLibraryCppNameFromNpmPackageName(args.npmPackageName);
|
|
181
|
+
const cppComponentCodeGenerator = new codegen_1.CppComponentCodeGenerator((filename) => {
|
|
182
|
+
return args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components', filename);
|
|
183
|
+
}, CODEGEN_NOTICE_LINES);
|
|
184
|
+
cppComponentCodeGenerator
|
|
185
|
+
.generate({
|
|
186
|
+
libraryCppName: libraryCppName,
|
|
187
|
+
uberSchema: cppComponentsUberSchema,
|
|
188
|
+
})
|
|
189
|
+
.forEach(appendToFileContentByPath);
|
|
190
|
+
new codegen_1.SharedComponentCodeGenerator((filename) => {
|
|
191
|
+
return args.cppOutputPath.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
|
|
192
|
+
})
|
|
193
|
+
.generate({
|
|
194
|
+
libraryCppName: libraryCppName,
|
|
195
|
+
uberSchema: componentsUberSchema,
|
|
196
|
+
})
|
|
197
|
+
.forEach(appendToFileContentByPath);
|
|
198
|
+
new LibGlueCodeGenerator_1.LibGlueCodeGenerator(args.cppOutputPath, args.etsOutputPath, CODEGEN_NOTICE_LINES)
|
|
199
|
+
.generate({
|
|
200
|
+
libraryCppName,
|
|
201
|
+
arkTSComponents: arkTSComponentCodeGeneratorCAPI.getLibGlueCodeData(),
|
|
202
|
+
cppComponents: cppComponentCodeGenerator
|
|
203
|
+
.getGlueCodeData()
|
|
204
|
+
.map(({ name }) => ({ componentName: name })),
|
|
205
|
+
turboModules: turboModuleGlueCodeData,
|
|
206
|
+
})
|
|
207
|
+
.forEach(appendToFileContentByPath);
|
|
208
|
+
return fileContentByPath;
|
|
209
|
+
}
|
|
210
|
+
function deriveLibraryCppNameFromNpmPackageName(npmPackageName) {
|
|
211
|
+
let result = npmPackageName;
|
|
212
|
+
if (npmPackageName.includes('/')) {
|
|
213
|
+
result.replace('@', '');
|
|
214
|
+
result = npmPackageName.replace('/', '__');
|
|
215
|
+
}
|
|
216
|
+
result = case_1.default.snake(result);
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
function saveAndLogCodegenResult(args, logger, fileContentByPath) {
|
|
220
|
+
saveCodegenResultToFileSystem(fileContentByPath, args.cppOutputPath, args.etsOutputPath, args.safetyCheck);
|
|
221
|
+
logCodegenResult(logger, fileContentByPath, new core_1.AbsolutePath(''));
|
|
222
|
+
}
|
|
223
|
+
function saveCodegenResultToFileSystem(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck) {
|
|
224
|
+
prepareDirectory(cppOutputPath, enableSafetyCheck);
|
|
225
|
+
prepareDirectory(etsOutputPath, enableSafetyCheck);
|
|
226
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
|
|
227
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
|
|
228
|
+
fileContentByPath.forEach((_fileContent, path) => {
|
|
229
|
+
prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
|
|
230
|
+
});
|
|
231
|
+
fileContentByPath.forEach((fileContent, path) => {
|
|
232
|
+
node_fs_1.default.writeFileSync(path.getValue(), fileContent);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function prepareDirectory(path, enableSafetyCheck) {
|
|
236
|
+
(0, core_1.maybeMakeDirectories)(path);
|
|
237
|
+
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
238
|
+
throw new core_1.DescriptiveError({
|
|
239
|
+
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
240
|
+
whatCanUserDo: {
|
|
241
|
+
default: [
|
|
242
|
+
'Run this command with --no-safety-check flag',
|
|
243
|
+
'Run codegen from different location',
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
249
|
+
}
|
|
250
|
+
function logCodegenResult(logger, fileContentByPath, rootPath) {
|
|
251
|
+
const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => path.relativeTo(rootPath).getValue());
|
|
252
|
+
sortedRelativePathStrings.sort();
|
|
253
|
+
sortedRelativePathStrings.forEach((pathStr) => {
|
|
254
|
+
logger.info((styles) => styles.gray(`• ${pathStr}`));
|
|
255
|
+
});
|
|
256
|
+
logger.info(() => '');
|
|
257
|
+
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`, { prefix: true });
|
|
258
|
+
logger.info(() => '');
|
|
259
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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.commandCreateMetroConstantsHarmony = void 0;
|
|
22
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
23
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
24
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
25
|
+
exports.commandCreateMetroConstantsHarmony = {
|
|
26
|
+
name: 'create-metro-host-constants-harmony',
|
|
27
|
+
description: 'Creates a Typescript file that exports constant with IP of the host machine. That IP is later used to connect to the Metro server from a physical device.',
|
|
28
|
+
options: [
|
|
29
|
+
{
|
|
30
|
+
name: '--output <string>',
|
|
31
|
+
description: 'Output file',
|
|
32
|
+
default: './harmony/entry/src/main/ets/codegen/MetroHostConstants.ts',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
createMetroHostConstants(node_path_1.default.resolve(args.output));
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
function createMetroHostConstants(outputPath) {
|
|
40
|
+
const networkInterfacesByName = node_os_1.default.networkInterfaces();
|
|
41
|
+
const getIP = () => {
|
|
42
|
+
var _a;
|
|
43
|
+
for (let name of Object.keys(networkInterfacesByName)) {
|
|
44
|
+
for (let net of (_a = networkInterfacesByName[name]) !== null && _a !== void 0 ? _a : []) {
|
|
45
|
+
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
|
|
46
|
+
if (net.family === 'IPv4' && !net.internal) {
|
|
47
|
+
return net.address;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
};
|
|
53
|
+
const ip = getIP();
|
|
54
|
+
const tsCode = [
|
|
55
|
+
'// This file is autogenerated. Do not modify it manually.',
|
|
56
|
+
'',
|
|
57
|
+
`export const METRO_SERVER_IP = '${ip}';\n`,
|
|
58
|
+
];
|
|
59
|
+
node_fs_1.default.writeFile(outputPath, tsCode.join('\n'), (err) => {
|
|
60
|
+
if (err) {
|
|
61
|
+
console.error(`Error writing to ${outputPath}:`, err);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.log(`Created file at ${outputPath}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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("./bundle-harmony"), exports);
|
|
24
|
+
__exportStar(require("./pack-harmony"), exports);
|
|
25
|
+
__exportStar(require("./unpack-harmony"), exports);
|
|
26
|
+
__exportStar(require("./create-metro-host-constants"), exports);
|
|
27
|
+
__exportStar(require("./codegen-harmony"), exports);
|
|
28
|
+
__exportStar(require("./verify-package-harmony"), exports);
|
|
29
|
+
__exportStar(require("./codegen-lib-harmony"), exports);
|
|
30
|
+
__exportStar(require("./link-harmony"), exports);
|
|
@@ -0,0 +1,97 @@
|
|
|
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.commandLinkHarmony = void 0;
|
|
19
|
+
const core_1 = require("../core");
|
|
20
|
+
const io_1 = require("../io");
|
|
21
|
+
const autolinking_1 = require("../autolinking");
|
|
22
|
+
const COMMAND_NAME = 'link-harmony';
|
|
23
|
+
exports.commandLinkHarmony = {
|
|
24
|
+
name: COMMAND_NAME,
|
|
25
|
+
description: 'Handles the automatic linking of RNOH libraries. This command is meant to be used by the RNOH HvigorPlugin.',
|
|
26
|
+
options: [
|
|
27
|
+
{
|
|
28
|
+
name: '--harmony-project-path <path>',
|
|
29
|
+
description: 'Specifies the root of your OpenHarmony project.',
|
|
30
|
+
default: './harmony',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: '--node-modules-path <path>',
|
|
34
|
+
description: 'Defines the path to the node_modules directory which holds npm packages.',
|
|
35
|
+
default: './node_modules',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: '--cmake-autolink-path-relative-to-harmony <path>',
|
|
39
|
+
description: 'Path relative to the root of your OpenHarmony project for the generated CMake file involved in autolinking.',
|
|
40
|
+
default: './entry/src/main/cpp/autolinking.cmake',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: '--cpp-rnoh-packages-factory-path-relative-to-harmony <path>',
|
|
44
|
+
description: 'Path relative to the root of your OpenHarmony project, for the generated file used to link packages on C++ side.',
|
|
45
|
+
default: './entry/src/main/cpp/RNOHPackagesFactory.h',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: '--ets-rnoh-packages-factory-path-relative-to-harmony <path>',
|
|
49
|
+
description: 'Path relative to the root of your OpenHarmony project, for the generated file used to link packages on ETS side.',
|
|
50
|
+
default: './entry/src/main/ets/RNOHPackagesFactory.ets',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: '--oh-package-path-relative-to-harmony <path>',
|
|
54
|
+
description: 'Path to the oh-package.json5 relative to the root of your OpenHarmony project.',
|
|
55
|
+
default: './oh-package.json5',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: '--exclude-npm-packages [string]',
|
|
59
|
+
description: "Lists npm package names to be excluded from the autolinking process, separated by semicolons. By default every library is included. Can't be used with --included-npm-packages.",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: '--include-npm-packages [string]',
|
|
63
|
+
description: "Lists npm package names to be included from the autolinking process, separated by semicolons. By default every library is included. Can't be used with --excluded-npm-packages.",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const logger = new io_1.Logger();
|
|
69
|
+
const fs = new io_1.RealFS();
|
|
70
|
+
const autolinking = new autolinking_1.Autolinking(fs, logger);
|
|
71
|
+
try {
|
|
72
|
+
const config = yield autolinking.prepareInput({
|
|
73
|
+
harmonyProjectPath: new core_1.AbsolutePath(rawArgs.harmonyProjectPath),
|
|
74
|
+
nodeModulesPath: new core_1.AbsolutePath(rawArgs.nodeModulesPath),
|
|
75
|
+
cmakeAutolinkPathRelativeToHarmony: rawArgs.cmakeAutolinkPathRelativeToHarmony,
|
|
76
|
+
cppRNOHPackagesFactoryPathRelativeToHarmony: rawArgs.cppRnohPackagesFactoryPathRelativeToHarmony,
|
|
77
|
+
etsRNOHPackagesFactoryPathRelativeToHarmony: rawArgs.etsRnohPackagesFactoryPathRelativeToHarmony,
|
|
78
|
+
ohPackagePathRelativeToHarmony: rawArgs.ohPackagePathRelativeToHarmony,
|
|
79
|
+
excludedNpmPackageNames: new Set(rawArgs.excludeNpmPackages
|
|
80
|
+
? ((_a = rawArgs.excludeNpmPackages) !== null && _a !== void 0 ? _a : '').split(';')
|
|
81
|
+
: undefined),
|
|
82
|
+
includedNpmPackageNames: new Set(rawArgs.includeNpmPackages
|
|
83
|
+
? ((_b = rawArgs.includeNpmPackages) !== null && _b !== void 0 ? _b : '').split(';')
|
|
84
|
+
: undefined),
|
|
85
|
+
});
|
|
86
|
+
const result = autolinking.evaluate(config);
|
|
87
|
+
autolinking.saveAndLogOutput(result);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (err instanceof core_1.DescriptiveError && !err.isUnexpected()) {
|
|
91
|
+
logger.descriptiveError(err);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
};
|