@react-native-oh/react-native-harmony-cli 0.0.40 → 0.0.41
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 +43 -74
- package/dist/autolinking/Autolinking.js +178 -179
- package/dist/codegen/core/CodegenError.js +3 -23
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +24 -28
- package/dist/codegen/core/UberSchema.js +57 -96
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +28 -41
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +27 -34
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +25 -33
- package/dist/codegen/generators/CppComponentCodeGenerator.js +23 -28
- package/dist/codegen/generators/LibGlueCodeGenerator.js +26 -29
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +25 -30
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -23
- package/dist/codegen/generators/UberGeneratorV2.js +34 -35
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +50 -24
- package/dist/codegen/templates/BasePackageHTemplate.js +120 -21
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +53 -8
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +75 -27
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +162 -29
- package/dist/codegen/templates/IndexTSTemplate.js +37 -17
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +119 -24
- package/dist/codegen/templates/TurboModuleCppTemplate.js +38 -15
- package/dist/codegen/templates/TurboModuleHTemplate.js +32 -11
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +52 -19
- package/dist/commands/bundle-harmony.js +53 -138
- package/dist/commands/codegen-harmony.js +105 -165
- package/dist/commands/codegen-lib-harmony.js +76 -116
- package/dist/commands/create-metro-host-constants.js +18 -47
- package/dist/commands/init.js +537 -961
- package/dist/commands/link-harmony.js +33 -71
- package/dist/commands/pack-harmony.js +47 -108
- package/dist/commands/run-harmony.js +372 -518
- package/dist/commands/unpack-harmony.js +105 -198
- package/dist/commands/verify-package-harmony.js +54 -108
- package/dist/core/AbsolutePath.js +31 -47
- package/dist/core/CodegenConfig.js +24 -22
- package/dist/core/DescriptiveError.js +18 -37
- package/dist/core/FileSystem.js +14 -18
- package/dist/core/OHPackageJSON5.js +17 -23
- package/dist/core/PackageJSON.js +26 -42
- package/dist/core/ProjectDependenciesManager.js +40 -92
- package/dist/core/ValidationError.js +2 -22
- package/dist/core/fs.js +9 -6
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +46 -98
- package/dist/io/Logger.js +40 -46
- package/dist/io/RealFS.js +35 -88
- package/dist/io/TarGz.js +11 -8
- package/dist/io/__fixtures__.js +79 -141
- package/dist/io/fsUtils.js +13 -12
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +19 -47
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +13 -41
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +8 -38
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +22 -54
- package/dist/package-verifier/verify-package.js +55 -132
- package/dist/simulator/LaunchSimulator.js +224 -301
- package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
- package/jest.config.js +12 -12
- package/package.json +78 -78
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
|
@@ -14,49 +14,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
-
if (ar || !(i in from)) {
|
|
47
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
-
ar[i] = from[i];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
19
|
};
|
|
53
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
21
|
exports.commandCodegenHarmony = void 0;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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");
|
|
60
27
|
exports.commandCodegenHarmony = {
|
|
61
28
|
name: 'codegen-harmony',
|
|
62
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.',
|
|
@@ -89,88 +56,73 @@ exports.commandCodegenHarmony = {
|
|
|
89
56
|
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.',
|
|
90
57
|
},
|
|
91
58
|
],
|
|
92
|
-
func:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
validateArgs(args);
|
|
105
|
-
etsOutputPath = args.etsOutputPath || args.rnohModulePath;
|
|
106
|
-
isEndWithGenerated = /\/generated\/?$/.test(etsOutputPath);
|
|
107
|
-
etsOutputPath = new core_1.AbsolutePath(etsOutputPath);
|
|
108
|
-
if (!isEndWithGenerated) {
|
|
109
|
-
etsOutputPath = etsOutputPath.copyWithNewSegment('generated');
|
|
110
|
-
}
|
|
111
|
-
enableSafetyCheck = args.safetyCheck;
|
|
112
|
-
cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
|
|
113
|
-
projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
|
|
114
|
-
return [4 /*yield*/, codegen_1.UberSchema.fromProject(fs, projectRootPath, function (codegenVersion, packageName) {
|
|
115
|
-
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION_1, packageName);
|
|
116
|
-
return codegenVersion === 1;
|
|
117
|
-
})];
|
|
118
|
-
case 2:
|
|
119
|
-
uberSchemaFromArkTSLibraries = _a.sent();
|
|
120
|
-
return [4 /*yield*/, collectLibrariesData(fs, projectRootPath, function (codegenVersion, packageName) {
|
|
121
|
-
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION_1, packageName);
|
|
122
|
-
return codegenVersion === 2;
|
|
123
|
-
})];
|
|
124
|
-
case 3:
|
|
125
|
-
cApiLibrariesData = _a.sent();
|
|
126
|
-
codegenNoticeLines = [
|
|
127
|
-
'This code was generated by "react-native codegen-harmony"',
|
|
128
|
-
'',
|
|
129
|
-
'Do not edit this file as changes may cause incorrect behavior and will be',
|
|
130
|
-
'lost once the code is regenerated.',
|
|
131
|
-
];
|
|
132
|
-
uberGeneratorV1 = new codegen_1.UberGeneratorV1(cppOutputPath, etsOutputPath, __spreadArray(__spreadArray([], codegenNoticeLines, true), ['', '@generatorVersion: 1'], false));
|
|
133
|
-
uberGeneratorV2 = new codegen_1.UberGeneratorV2(cppOutputPath, etsOutputPath, __spreadArray(__spreadArray([], codegenNoticeLines, true), ['', '@generatorVersion: 2'], false));
|
|
134
|
-
glueCodeGenerator = new codegen_1.AppBuildTimeGlueCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines);
|
|
135
|
-
fileContentByPath_1 = new Map();
|
|
136
|
-
appendToFileContentByPath = function (fileContent, path) {
|
|
137
|
-
fileContentByPath_1.set(path, fileContent);
|
|
138
|
-
};
|
|
139
|
-
uberGeneratorV1
|
|
140
|
-
.generate(uberSchemaFromArkTSLibraries)
|
|
141
|
-
.forEach(appendToFileContentByPath);
|
|
142
|
-
uberGeneratorV2
|
|
143
|
-
.generate(cApiLibrariesData)
|
|
144
|
-
.forEach(appendToFileContentByPath);
|
|
145
|
-
glueCodeGenerator
|
|
146
|
-
.generate({
|
|
147
|
-
v1: uberGeneratorV1.getGlueCodeData(),
|
|
148
|
-
v2: uberGeneratorV2.getGlueCodeData(),
|
|
149
|
-
})
|
|
150
|
-
.forEach(appendToFileContentByPath);
|
|
151
|
-
if (!args.debug) return [3 /*break*/, 5];
|
|
152
|
-
return [4 /*yield*/, codegen_1.UberSchema.fromProject(fs, projectRootPath)];
|
|
153
|
-
case 4:
|
|
154
|
-
uberSchema_1 = _a.sent();
|
|
155
|
-
logger.debug(function (styles) {
|
|
156
|
-
return styles.gray(JSON.stringify(uberSchema_1.getValue(), null, 2));
|
|
157
|
-
});
|
|
158
|
-
_a.label = 5;
|
|
159
|
-
case 5:
|
|
160
|
-
saveCodegenResult(fs, fileContentByPath_1, cppOutputPath, etsOutputPath, enableSafetyCheck);
|
|
161
|
-
logCodegenResult(logger, fileContentByPath_1, projectRootPath);
|
|
162
|
-
return [3 /*break*/, 7];
|
|
163
|
-
case 6:
|
|
164
|
-
err_1 = _a.sent();
|
|
165
|
-
if (err_1 instanceof core_1.DescriptiveError) {
|
|
166
|
-
logger.descriptiveError(err_1);
|
|
167
|
-
process.exit(1);
|
|
168
|
-
}
|
|
169
|
-
throw err_1;
|
|
170
|
-
case 7: return [2 /*return*/];
|
|
59
|
+
func: (_argv, _config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const logger = new io_1.Logger();
|
|
61
|
+
const fs = new io_1.RealFS();
|
|
62
|
+
try {
|
|
63
|
+
const MAX_SUPPORTED_CODEGEN_VERSION = 2;
|
|
64
|
+
// prepare the input data
|
|
65
|
+
validateArgs(args);
|
|
66
|
+
let etsOutputPath = args.etsOutputPath || args.rnohModulePath;
|
|
67
|
+
const isEndWithGenerated = /\/generated\/?$/.test(etsOutputPath);
|
|
68
|
+
etsOutputPath = new core_1.AbsolutePath(etsOutputPath);
|
|
69
|
+
if (!isEndWithGenerated) {
|
|
70
|
+
etsOutputPath = etsOutputPath.copyWithNewSegment('generated');
|
|
171
71
|
}
|
|
172
|
-
|
|
173
|
-
|
|
72
|
+
const enableSafetyCheck = args.safetyCheck;
|
|
73
|
+
const cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
|
|
74
|
+
const projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
|
|
75
|
+
const uberSchemaFromArkTSLibraries = yield codegen_1.UberSchema.fromProject(fs, projectRootPath, (codegenVersion, packageName) => {
|
|
76
|
+
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
|
|
77
|
+
return codegenVersion === 1;
|
|
78
|
+
});
|
|
79
|
+
const cApiLibrariesData = yield collectLibrariesData(fs, projectRootPath, (codegenVersion, packageName) => {
|
|
80
|
+
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
|
|
81
|
+
return codegenVersion === 2;
|
|
82
|
+
});
|
|
83
|
+
// instantiate objects
|
|
84
|
+
const codegenNoticeLines = [
|
|
85
|
+
'This code was generated by "react-native codegen-harmony"',
|
|
86
|
+
'',
|
|
87
|
+
'Do not edit this file as changes may cause incorrect behavior and will be',
|
|
88
|
+
'lost once the code is regenerated.',
|
|
89
|
+
];
|
|
90
|
+
const uberGeneratorV1 = new codegen_1.UberGeneratorV1(cppOutputPath, etsOutputPath, [...codegenNoticeLines, '', '@generatorVersion: 1']);
|
|
91
|
+
const uberGeneratorV2 = new codegen_1.UberGeneratorV2(cppOutputPath, etsOutputPath, [...codegenNoticeLines, '', '@generatorVersion: 2']);
|
|
92
|
+
const glueCodeGenerator = new codegen_1.AppBuildTimeGlueCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines);
|
|
93
|
+
// generate the code
|
|
94
|
+
const fileContentByPath = new Map();
|
|
95
|
+
const appendToFileContentByPath = (fileContent, path) => {
|
|
96
|
+
fileContentByPath.set(path, fileContent);
|
|
97
|
+
};
|
|
98
|
+
uberGeneratorV1
|
|
99
|
+
.generate(uberSchemaFromArkTSLibraries)
|
|
100
|
+
.forEach(appendToFileContentByPath);
|
|
101
|
+
uberGeneratorV2
|
|
102
|
+
.generate(cApiLibrariesData)
|
|
103
|
+
.forEach(appendToFileContentByPath);
|
|
104
|
+
glueCodeGenerator
|
|
105
|
+
.generate({
|
|
106
|
+
v1: uberGeneratorV1.getGlueCodeData(),
|
|
107
|
+
v2: uberGeneratorV2.getGlueCodeData(),
|
|
108
|
+
})
|
|
109
|
+
.forEach(appendToFileContentByPath);
|
|
110
|
+
// output the results
|
|
111
|
+
if (args.debug) {
|
|
112
|
+
const uberSchema = yield codegen_1.UberSchema.fromProject(fs, projectRootPath);
|
|
113
|
+
logger.debug((styles) => styles.gray(JSON.stringify(uberSchema.getValue(), null, 2)));
|
|
114
|
+
}
|
|
115
|
+
saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck);
|
|
116
|
+
logCodegenResult(logger, fileContentByPath, projectRootPath);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
if (err instanceof core_1.DescriptiveError) {
|
|
120
|
+
logger.descriptiveError(err);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
174
126
|
};
|
|
175
127
|
function validateArgs(args) {
|
|
176
128
|
if (!args.rnohModulePath && !args.etsOutputPath) {
|
|
@@ -185,45 +137,35 @@ function validateArgs(args) {
|
|
|
185
137
|
}
|
|
186
138
|
}
|
|
187
139
|
function collectLibrariesData(fs, projectRootPath, onShouldAcceptCodegenConfig) {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath),
|
|
195
|
-
];
|
|
196
|
-
return [4 /*yield*/, new core_1.ProjectDependenciesManager(fs, projectRootPath).forEachAsync(function (dependency) {
|
|
197
|
-
packageJSONs.push(dependency.readPackageJSON());
|
|
198
|
-
})];
|
|
199
|
-
case 1:
|
|
200
|
-
_b.sent();
|
|
201
|
-
results = [];
|
|
202
|
-
for (_i = 0, packageJSONs_1 = packageJSONs; _i < packageJSONs_1.length; _i++) {
|
|
203
|
-
packageJSON = packageJSONs_1[_i];
|
|
204
|
-
codegenConfigs = packageJSON.getCodegenConfigs();
|
|
205
|
-
for (_a = 0, codegenConfigs_1 = codegenConfigs; _a < codegenConfigs_1.length; _a++) {
|
|
206
|
-
codegenConfig = codegenConfigs_1[_a];
|
|
207
|
-
if (codegenConfig &&
|
|
208
|
-
onShouldAcceptCodegenConfig(codegenConfig.getVersion(), packageJSON.name)) {
|
|
209
|
-
results.push({
|
|
210
|
-
libraryCppName: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
|
|
211
|
-
uberSchema: codegen_1.UberSchema.fromCodegenConfig(codegenConfig),
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return [2 /*return*/, results];
|
|
217
|
-
}
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const packageJSONs = [
|
|
142
|
+
core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath),
|
|
143
|
+
];
|
|
144
|
+
yield new core_1.ProjectDependenciesManager(fs, projectRootPath).forEachAsync((dependency) => {
|
|
145
|
+
packageJSONs.push(dependency.readPackageJSON());
|
|
218
146
|
});
|
|
147
|
+
const results = [];
|
|
148
|
+
for (const packageJSON of packageJSONs) {
|
|
149
|
+
const codegenConfigs = packageJSON.getCodegenConfigs();
|
|
150
|
+
for (const codegenConfig of codegenConfigs) {
|
|
151
|
+
if (codegenConfig &&
|
|
152
|
+
onShouldAcceptCodegenConfig(codegenConfig.getVersion(), packageJSON.name)) {
|
|
153
|
+
results.push({
|
|
154
|
+
libraryCppName: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
|
|
155
|
+
uberSchema: codegen_1.UberSchema.fromCodegenConfig(codegenConfig),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return results;
|
|
219
161
|
});
|
|
220
162
|
}
|
|
221
163
|
function throwErrorIfUnsupportedCodegenVersion(codegenVersion, maxSupportedCodegenVersion, packageName) {
|
|
222
164
|
if (codegenVersion > maxSupportedCodegenVersion) {
|
|
223
165
|
throw new codegen_1.CodegenError({
|
|
224
|
-
whatHappened:
|
|
166
|
+
whatHappened: `Package "${packageName}" requires codegenVersion: ${codegenVersion}, which is not supported (maxSupportedCodegenVersion=${maxSupportedCodegenVersion}).`,
|
|
225
167
|
whatCanUserDo: [
|
|
226
|
-
|
|
168
|
+
`Try downgrading "${packageName}".`,
|
|
227
169
|
'Update the "@react-native-oh/react-native-harmony-cli" package.',
|
|
228
170
|
],
|
|
229
171
|
});
|
|
@@ -234,10 +176,10 @@ function saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath,
|
|
|
234
176
|
prepareDirectory(etsOutputPath, enableSafetyCheck);
|
|
235
177
|
prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
|
|
236
178
|
prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
|
|
237
|
-
fileContentByPath.forEach(
|
|
179
|
+
fileContentByPath.forEach((_fileContent, path) => {
|
|
238
180
|
prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
|
|
239
181
|
});
|
|
240
|
-
fileContentByPath.forEach(
|
|
182
|
+
fileContentByPath.forEach((fileContent, path) => {
|
|
241
183
|
fs.writeTextSync(path, fileContent);
|
|
242
184
|
});
|
|
243
185
|
}
|
|
@@ -245,26 +187,24 @@ function prepareDirectory(path, enableSafetyCheck) {
|
|
|
245
187
|
(0, core_1.maybeMakeDirectories)(path);
|
|
246
188
|
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
247
189
|
throw new core_1.DescriptiveError({
|
|
248
|
-
whatHappened:
|
|
190
|
+
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
249
191
|
whatCanUserDo: ['Run codegen from different location'],
|
|
250
192
|
});
|
|
251
193
|
}
|
|
252
194
|
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
253
195
|
}
|
|
254
196
|
function logCodegenResult(logger, fileContentByPath, projectRootPath) {
|
|
255
|
-
|
|
197
|
+
const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => node_path_1.default.relative(projectRootPath.getValue(), path.getValue()));
|
|
256
198
|
sortedRelativePathStrings.sort();
|
|
257
|
-
sortedRelativePathStrings.forEach(
|
|
258
|
-
logger.debug(
|
|
259
|
-
});
|
|
260
|
-
logger.debug(function () { return ''; });
|
|
261
|
-
logger.info(function (styles) {
|
|
262
|
-
return "Generated ".concat(styles.green(styles.bold(fileContentByPath.size)), " file(s)");
|
|
199
|
+
sortedRelativePathStrings.forEach((pathStr) => {
|
|
200
|
+
logger.debug((styles) => styles.gray(`• ${pathStr}`));
|
|
263
201
|
});
|
|
264
|
-
logger.debug(
|
|
202
|
+
logger.debug(() => '');
|
|
203
|
+
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`);
|
|
204
|
+
logger.debug(() => '');
|
|
265
205
|
}
|
|
266
206
|
function deriveCppDirectoryNameFromNpmPackageName(npmPackageName) {
|
|
267
|
-
|
|
207
|
+
let result = npmPackageName;
|
|
268
208
|
if (npmPackageName.includes('/')) {
|
|
269
209
|
result.replace('@', '');
|
|
270
210
|
result = npmPackageName.replace('/', '__');
|
|
@@ -14,51 +14,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
-
if (ar || !(i in from)) {
|
|
47
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
-
ar[i] = from[i];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
19
|
};
|
|
53
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
21
|
exports.commandCodegenLibHarmony = void 0;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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';
|
|
62
29
|
exports.commandCodegenLibHarmony = {
|
|
63
30
|
name: COMMAND_NAME,
|
|
64
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.',
|
|
@@ -70,17 +37,17 @@ exports.commandCodegenLibHarmony = {
|
|
|
70
37
|
{
|
|
71
38
|
name: '--turbo-modules-spec-paths [path]',
|
|
72
39
|
description: 'Path or paths to Turbo Module spec files. Each path can point to a spec file or a directory containing spec files.',
|
|
73
|
-
parse:
|
|
40
|
+
parse: (val) => val.split(' '),
|
|
74
41
|
},
|
|
75
42
|
{
|
|
76
43
|
name: '--arkts-components-spec-paths [path]',
|
|
77
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.',
|
|
78
|
-
parse:
|
|
45
|
+
parse: (val) => val.split(' '),
|
|
79
46
|
},
|
|
80
47
|
{
|
|
81
48
|
name: '--cpp-components-spec-paths [path]',
|
|
82
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.',
|
|
83
|
-
parse:
|
|
50
|
+
parse: (val) => val.split(' '),
|
|
84
51
|
},
|
|
85
52
|
{
|
|
86
53
|
name: '--cpp-output-path <path>',
|
|
@@ -95,44 +62,43 @@ exports.commandCodegenLibHarmony = {
|
|
|
95
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.',
|
|
96
63
|
},
|
|
97
64
|
],
|
|
98
|
-
func:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
logger.descriptiveError(err);
|
|
113
|
-
return [2 /*return*/];
|
|
114
|
-
}
|
|
115
|
-
throw err;
|
|
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;
|
|
116
79
|
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
})
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
120
83
|
};
|
|
121
84
|
function validateArgsAndRetrieveUberSchemaByType(rawArgs) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
]);
|
|
129
95
|
return {
|
|
130
|
-
args
|
|
96
|
+
args,
|
|
131
97
|
uberSchemaByType: {
|
|
132
|
-
turboModulesUberSchema
|
|
133
|
-
arkTSComponentsUberSchema
|
|
134
|
-
cppComponentsUberSchema
|
|
135
|
-
componentsUberSchema
|
|
98
|
+
turboModulesUberSchema,
|
|
99
|
+
arkTSComponentsUberSchema,
|
|
100
|
+
cppComponentsUberSchema,
|
|
101
|
+
componentsUberSchema,
|
|
136
102
|
},
|
|
137
103
|
};
|
|
138
104
|
}
|
|
@@ -158,28 +124,28 @@ function validateRawArgs(rawArgs) {
|
|
|
158
124
|
}
|
|
159
125
|
return {
|
|
160
126
|
npmPackageName: rawArgs.npmPackageName,
|
|
161
|
-
tmSpecPaths: ((_a = rawArgs.turboModulesSpecPaths) !== null && _a !== void 0 ? _a : []).map(
|
|
162
|
-
arkTSComponentsSpecPaths: ((_b = rawArgs.arktsComponentsSpecPaths) !== null && _b !== void 0 ? _b : []).map(
|
|
163
|
-
cppComponentsSpecPaths: ((_c = rawArgs.cppComponentsSpecPaths) !== null && _c !== void 0 ? _c : []).map(
|
|
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)),
|
|
164
130
|
etsOutputPath: new core_1.AbsolutePath(rawArgs.etsOutputPath),
|
|
165
131
|
cppOutputPath: new core_1.AbsolutePath(rawArgs.cppOutputPath),
|
|
166
132
|
safetyCheck: !!rawArgs.safetyCheck,
|
|
167
133
|
};
|
|
168
134
|
}
|
|
169
135
|
function specPathsToSpecFilePaths(specPaths) {
|
|
170
|
-
|
|
171
|
-
return specPaths.flatMap(
|
|
136
|
+
const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
137
|
+
return specPaths.flatMap((specPath) => {
|
|
172
138
|
if (!node_fs_1.default.existsSync(specPath.getValue())) {
|
|
173
139
|
throw new core_1.DescriptiveError({
|
|
174
|
-
whatHappened:
|
|
175
|
-
whatCanUserDo: [
|
|
140
|
+
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
141
|
+
whatCanUserDo: [`Are you sure provided specPath exists?`],
|
|
176
142
|
});
|
|
177
143
|
}
|
|
178
144
|
if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
|
|
179
145
|
return (0, io_1.findFilePathsWithExtensions)(specPath, SUPPORTED_SPEC_EXTENSIONS);
|
|
180
146
|
}
|
|
181
147
|
else {
|
|
182
|
-
|
|
148
|
+
const ext = specPath.getExtension();
|
|
183
149
|
if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
|
|
184
150
|
return [specPath];
|
|
185
151
|
}
|
|
@@ -187,31 +153,30 @@ function specPathsToSpecFilePaths(specPaths) {
|
|
|
187
153
|
}
|
|
188
154
|
});
|
|
189
155
|
}
|
|
190
|
-
function generateCodeInMemory(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
"This code was generated by \"react-native ".concat(COMMAND_NAME, "\""),
|
|
156
|
+
function generateCodeInMemory({ args, uberSchemaByType: { arkTSComponentsUberSchema, componentsUberSchema, cppComponentsUberSchema, turboModulesUberSchema, }, }) {
|
|
157
|
+
const CODEGEN_NOTICE_LINES = [
|
|
158
|
+
`This code was generated by "react-native ${COMMAND_NAME}"`,
|
|
194
159
|
];
|
|
195
|
-
|
|
196
|
-
|
|
160
|
+
const fileContentByPath = new Map();
|
|
161
|
+
const appendToFileContentByPath = (fileContent, path) => {
|
|
197
162
|
fileContentByPath.set(path, fileContent);
|
|
198
163
|
};
|
|
199
|
-
|
|
164
|
+
const turboModuleGlueCodeData = turboModulesUberSchema
|
|
200
165
|
.findAllSpecSchemasByType('NativeModule')
|
|
201
|
-
.map(
|
|
202
|
-
|
|
166
|
+
.map((specSchema) => {
|
|
167
|
+
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');
|
|
203
168
|
nativeModuleCodeGenerator
|
|
204
169
|
.generate(specSchema)
|
|
205
170
|
.forEach(appendToFileContentByPath);
|
|
206
171
|
return nativeModuleCodeGenerator.getGlueCodeData();
|
|
207
172
|
})
|
|
208
173
|
.flat();
|
|
209
|
-
|
|
174
|
+
const arkTSComponentCodeGeneratorCAPI = new codegen_1.ArkTSComponentCodeGeneratorCAPI(args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components'), args.etsOutputPath.copyWithNewSegment('components'), CODEGEN_NOTICE_LINES, '@rnoh/react-native-openharmony/ts');
|
|
210
175
|
arkTSComponentCodeGeneratorCAPI
|
|
211
176
|
.generate(arkTSComponentsUberSchema)
|
|
212
177
|
.forEach(appendToFileContentByPath);
|
|
213
|
-
|
|
214
|
-
|
|
178
|
+
const libraryCppName = deriveLibraryCppNameFromNpmPackageName(args.npmPackageName);
|
|
179
|
+
const cppComponentCodeGenerator = new codegen_1.CppComponentCodeGenerator((filename) => {
|
|
215
180
|
return args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components', filename);
|
|
216
181
|
}, CODEGEN_NOTICE_LINES);
|
|
217
182
|
cppComponentCodeGenerator
|
|
@@ -220,7 +185,7 @@ function generateCodeInMemory(_a) {
|
|
|
220
185
|
uberSchema: cppComponentsUberSchema,
|
|
221
186
|
})
|
|
222
187
|
.forEach(appendToFileContentByPath);
|
|
223
|
-
new codegen_1.SharedComponentCodeGenerator(
|
|
188
|
+
new codegen_1.SharedComponentCodeGenerator((filename) => {
|
|
224
189
|
return args.cppOutputPath.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
|
|
225
190
|
})
|
|
226
191
|
.generate({
|
|
@@ -230,21 +195,18 @@ function generateCodeInMemory(_a) {
|
|
|
230
195
|
.forEach(appendToFileContentByPath);
|
|
231
196
|
new LibGlueCodeGenerator_1.LibGlueCodeGenerator(args.cppOutputPath, args.etsOutputPath, CODEGEN_NOTICE_LINES)
|
|
232
197
|
.generate({
|
|
233
|
-
libraryCppName
|
|
198
|
+
libraryCppName,
|
|
234
199
|
arkTSComponents: arkTSComponentCodeGeneratorCAPI.getLibGlueCodeData(),
|
|
235
200
|
cppComponents: cppComponentCodeGenerator
|
|
236
201
|
.getGlueCodeData()
|
|
237
|
-
.map(
|
|
238
|
-
var name = _a.name;
|
|
239
|
-
return ({ componentName: name });
|
|
240
|
-
}),
|
|
202
|
+
.map(({ name }) => ({ componentName: name })),
|
|
241
203
|
turboModules: turboModuleGlueCodeData,
|
|
242
204
|
})
|
|
243
205
|
.forEach(appendToFileContentByPath);
|
|
244
206
|
return fileContentByPath;
|
|
245
207
|
}
|
|
246
208
|
function deriveLibraryCppNameFromNpmPackageName(npmPackageName) {
|
|
247
|
-
|
|
209
|
+
let result = npmPackageName;
|
|
248
210
|
if (npmPackageName.includes('/')) {
|
|
249
211
|
result.replace('@', '');
|
|
250
212
|
result = npmPackageName.replace('/', '__');
|
|
@@ -261,10 +223,10 @@ function saveCodegenResultToFileSystem(fileContentByPath, cppOutputPath, etsOutp
|
|
|
261
223
|
prepareDirectory(etsOutputPath, enableSafetyCheck);
|
|
262
224
|
prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
|
|
263
225
|
prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
|
|
264
|
-
fileContentByPath.forEach(
|
|
226
|
+
fileContentByPath.forEach((_fileContent, path) => {
|
|
265
227
|
prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
|
|
266
228
|
});
|
|
267
|
-
fileContentByPath.forEach(
|
|
229
|
+
fileContentByPath.forEach((fileContent, path) => {
|
|
268
230
|
node_fs_1.default.writeFileSync(path.getValue(), fileContent);
|
|
269
231
|
});
|
|
270
232
|
}
|
|
@@ -272,7 +234,7 @@ function prepareDirectory(path, enableSafetyCheck) {
|
|
|
272
234
|
(0, core_1.maybeMakeDirectories)(path);
|
|
273
235
|
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
274
236
|
throw new core_1.DescriptiveError({
|
|
275
|
-
whatHappened:
|
|
237
|
+
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
276
238
|
whatCanUserDo: [
|
|
277
239
|
'Run this command with --no-safety-check flag',
|
|
278
240
|
'Run codegen from different location',
|
|
@@ -282,14 +244,12 @@ function prepareDirectory(path, enableSafetyCheck) {
|
|
|
282
244
|
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
283
245
|
}
|
|
284
246
|
function logCodegenResult(logger, fileContentByPath, rootPath) {
|
|
285
|
-
|
|
247
|
+
const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => path.relativeTo(rootPath).getValue());
|
|
286
248
|
sortedRelativePathStrings.sort();
|
|
287
|
-
sortedRelativePathStrings.forEach(
|
|
288
|
-
logger.info(
|
|
289
|
-
});
|
|
290
|
-
logger.info(function () { return ''; });
|
|
291
|
-
logger.info(function (styles) {
|
|
292
|
-
return "Generated ".concat(styles.green(styles.bold(fileContentByPath.size)), " file(s)");
|
|
249
|
+
sortedRelativePathStrings.forEach((pathStr) => {
|
|
250
|
+
logger.info((styles) => styles.gray(`• ${pathStr}`));
|
|
293
251
|
});
|
|
294
|
-
logger.info(
|
|
252
|
+
logger.info(() => '');
|
|
253
|
+
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`);
|
|
254
|
+
logger.info(() => '');
|
|
295
255
|
}
|