@react-native-oh/react-native-harmony-cli 0.72.140 → 0.72.142
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
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @react-native-oh/react-native-harmony-cli
|
|
2
2
|
|
|
3
|
-
Please refer to: [RNOH repo](https://
|
|
3
|
+
Please refer to: [RNOH repo](https://gitee.com/openharmony-sig/ohos_react_native) for more detail.
|
|
4
4
|
|
|
5
5
|
# Documentation
|
|
6
6
|
|
|
7
|
-
- [中文](https://
|
|
8
|
-
- [English](https://
|
|
7
|
+
- [中文](https://gitee.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/README.md)
|
|
8
|
+
- [English](https://gitee.com/openharmony-sig/ohos_react_native/blob/master/docs/en/README.md)
|
|
9
9
|
|
|
10
10
|
# License
|
|
11
11
|
|
|
12
|
-
This library is licensed under The [MIT License (MIT)](https://
|
|
12
|
+
This library is licensed under The [MIT License (MIT)](https://gitee.com/openharmony-sig/ohos_react_native)
|
|
@@ -42,12 +42,22 @@ class LibGlueCodeGenerator {
|
|
|
42
42
|
basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: false });
|
|
43
43
|
});
|
|
44
44
|
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', `${basePackageClassName}.h`), basePackageTemplate.build());
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
const hasFabricComponents = arkTSComponents.length > 0 || cppComponents.length > 0;
|
|
46
|
+
const hasTurboModules = turboModules.length > 0;
|
|
47
|
+
if (hasFabricComponents) {
|
|
48
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
49
|
+
}
|
|
50
|
+
if (hasTurboModules) {
|
|
51
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
|
|
52
|
+
}
|
|
53
|
+
const rootTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
54
|
+
if (hasFabricComponents) {
|
|
55
|
+
rootTS.addReexport({ from: './components/ts', as: 'RNC' });
|
|
56
|
+
}
|
|
57
|
+
if (hasTurboModules) {
|
|
58
|
+
rootTS.addReexport({ from: './turboModules/ts', as: 'TM' });
|
|
59
|
+
}
|
|
60
|
+
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), rootTS.build());
|
|
51
61
|
generated_indexETS.addReexport({ from: './ts' });
|
|
52
62
|
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
|
|
53
63
|
return fileContentByPath;
|
|
@@ -26,6 +26,7 @@ const codegen_1 = require("../codegen");
|
|
|
26
26
|
const case_1 = __importDefault(require("case"));
|
|
27
27
|
const LibGlueCodeGenerator_1 = require("../codegen/generators/LibGlueCodeGenerator");
|
|
28
28
|
const COMMAND_NAME = 'codegen-lib-harmony';
|
|
29
|
+
const VALID_GENERATE_TYPES = ['all', 'turbo-module', 'fabric'];
|
|
29
30
|
exports.commandCodegenLibHarmony = {
|
|
30
31
|
name: COMMAND_NAME,
|
|
31
32
|
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.',
|
|
@@ -61,6 +62,13 @@ exports.commandCodegenLibHarmony = {
|
|
|
61
62
|
name: '--no-safety-check [boolean]',
|
|
62
63
|
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
|
+
{
|
|
66
|
+
name: '--generate-type <string>',
|
|
67
|
+
description: 'Controls which type of code to generate. ' +
|
|
68
|
+
'Possible values: "all" (default, generates both TurboModule and Fabric code), ' +
|
|
69
|
+
'"turbo-module" (generates only TurboModule code), ' +
|
|
70
|
+
'"fabric" (generates only Fabric component code).',
|
|
71
|
+
},
|
|
64
72
|
],
|
|
65
73
|
func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
74
|
const logger = new io_1.Logger();
|
|
@@ -103,7 +111,7 @@ function validateArgsAndRetrieveUberSchemaByType(rawArgs) {
|
|
|
103
111
|
};
|
|
104
112
|
}
|
|
105
113
|
function validateRawArgs(rawArgs) {
|
|
106
|
-
var _a, _b, _c;
|
|
114
|
+
var _a, _b, _c, _d;
|
|
107
115
|
if (!rawArgs.npmPackageName) {
|
|
108
116
|
throw new core_1.DescriptiveError({
|
|
109
117
|
whatHappened: '--npm-package-name is required',
|
|
@@ -122,14 +130,24 @@ function validateRawArgs(rawArgs) {
|
|
|
122
130
|
whatCanUserDo: ['Please specify --ets-output-path'],
|
|
123
131
|
});
|
|
124
132
|
}
|
|
133
|
+
const generateType = ((_a = rawArgs.generateType) !== null && _a !== void 0 ? _a : 'all');
|
|
134
|
+
if (!VALID_GENERATE_TYPES.includes(generateType)) {
|
|
135
|
+
throw new core_1.DescriptiveError({
|
|
136
|
+
whatHappened: `Invalid --generate-type value: "${rawArgs.generateType}". Valid values are: ${VALID_GENERATE_TYPES.join(', ')}`,
|
|
137
|
+
whatCanUserDo: [
|
|
138
|
+
`Please specify one of: ${VALID_GENERATE_TYPES.join(', ')}`,
|
|
139
|
+
],
|
|
140
|
+
});
|
|
141
|
+
}
|
|
125
142
|
return {
|
|
126
143
|
npmPackageName: rawArgs.npmPackageName,
|
|
127
|
-
tmSpecPaths: ((
|
|
128
|
-
arkTSComponentsSpecPaths: ((
|
|
129
|
-
cppComponentsSpecPaths: ((
|
|
144
|
+
tmSpecPaths: ((_b = rawArgs.turboModulesSpecPaths) !== null && _b !== void 0 ? _b : []).map((path) => new core_1.AbsolutePath(path)),
|
|
145
|
+
arkTSComponentsSpecPaths: ((_c = rawArgs.arktsComponentsSpecPaths) !== null && _c !== void 0 ? _c : []).map((path) => new core_1.AbsolutePath(path)),
|
|
146
|
+
cppComponentsSpecPaths: ((_d = rawArgs.cppComponentsSpecPaths) !== null && _d !== void 0 ? _d : []).map((path) => new core_1.AbsolutePath(path)),
|
|
130
147
|
etsOutputPath: new core_1.AbsolutePath(rawArgs.etsOutputPath),
|
|
131
148
|
cppOutputPath: new core_1.AbsolutePath(rawArgs.cppOutputPath),
|
|
132
149
|
safetyCheck: !!rawArgs.safetyCheck,
|
|
150
|
+
generateType,
|
|
133
151
|
};
|
|
134
152
|
}
|
|
135
153
|
function specPathsToSpecFilePaths(specPaths) {
|
|
@@ -161,46 +179,60 @@ function generateCodeInMemory({ args, uberSchemaByType: { arkTSComponentsUberSch
|
|
|
161
179
|
const appendToFileContentByPath = (fileContent, path) => {
|
|
162
180
|
fileContentByPath.set(path, fileContent);
|
|
163
181
|
};
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
const { generateType } = args;
|
|
183
|
+
const shouldGenerateTurboModule = generateType === 'all' || generateType === 'turbo-module';
|
|
184
|
+
const shouldGenerateFabric = generateType === 'all' || generateType === 'fabric';
|
|
185
|
+
let turboModuleGlueCodeData = [];
|
|
186
|
+
if (shouldGenerateTurboModule) {
|
|
187
|
+
turboModuleGlueCodeData = turboModulesUberSchema
|
|
188
|
+
.findAllSpecSchemasByType('NativeModule')
|
|
189
|
+
.map((specSchema) => {
|
|
190
|
+
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');
|
|
191
|
+
nativeModuleCodeGenerator
|
|
192
|
+
.generate(specSchema)
|
|
193
|
+
.forEach(appendToFileContentByPath);
|
|
194
|
+
return nativeModuleCodeGenerator.getGlueCodeData();
|
|
195
|
+
})
|
|
196
|
+
.flat();
|
|
197
|
+
}
|
|
174
198
|
const arkTSComponentCodeGeneratorCAPI = new codegen_1.ArkTSComponentCodeGeneratorCAPI(args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components'), args.etsOutputPath.copyWithNewSegment('components'), CODEGEN_NOTICE_LINES, '@rnoh/react-native-openharmony/ts');
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
199
|
+
if (shouldGenerateFabric) {
|
|
200
|
+
arkTSComponentCodeGeneratorCAPI
|
|
201
|
+
.generate(arkTSComponentsUberSchema)
|
|
202
|
+
.forEach(appendToFileContentByPath);
|
|
203
|
+
}
|
|
178
204
|
const libraryCppName = deriveLibraryCppNameFromNpmPackageName(args.npmPackageName);
|
|
179
205
|
const cppComponentCodeGenerator = new codegen_1.CppComponentCodeGenerator((filename) => {
|
|
180
206
|
return args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components', filename);
|
|
181
207
|
}, CODEGEN_NOTICE_LINES);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
208
|
+
if (shouldGenerateFabric) {
|
|
209
|
+
cppComponentCodeGenerator
|
|
210
|
+
.generate({
|
|
211
|
+
libraryCppName: libraryCppName,
|
|
212
|
+
uberSchema: cppComponentsUberSchema,
|
|
213
|
+
})
|
|
214
|
+
.forEach(appendToFileContentByPath);
|
|
215
|
+
new codegen_1.SharedComponentCodeGenerator((filename) => {
|
|
216
|
+
return args.cppOutputPath.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
|
|
217
|
+
})
|
|
218
|
+
.generate({
|
|
219
|
+
libraryCppName: libraryCppName,
|
|
220
|
+
uberSchema: componentsUberSchema,
|
|
221
|
+
})
|
|
222
|
+
.forEach(appendToFileContentByPath);
|
|
223
|
+
}
|
|
196
224
|
new LibGlueCodeGenerator_1.LibGlueCodeGenerator(args.cppOutputPath, args.etsOutputPath, CODEGEN_NOTICE_LINES)
|
|
197
225
|
.generate({
|
|
198
226
|
libraryCppName,
|
|
199
|
-
arkTSComponents:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
227
|
+
arkTSComponents: shouldGenerateFabric
|
|
228
|
+
? arkTSComponentCodeGeneratorCAPI.getLibGlueCodeData()
|
|
229
|
+
: [],
|
|
230
|
+
cppComponents: shouldGenerateFabric
|
|
231
|
+
? cppComponentCodeGenerator
|
|
232
|
+
.getGlueCodeData()
|
|
233
|
+
.map(({ name }) => ({ componentName: name }))
|
|
234
|
+
: [],
|
|
235
|
+
turboModules: shouldGenerateTurboModule ? turboModuleGlueCodeData : [],
|
|
204
236
|
})
|
|
205
237
|
.forEach(appendToFileContentByPath);
|
|
206
238
|
return fileContentByPath;
|
|
@@ -215,14 +247,20 @@ function deriveLibraryCppNameFromNpmPackageName(npmPackageName) {
|
|
|
215
247
|
return result;
|
|
216
248
|
}
|
|
217
249
|
function saveAndLogCodegenResult(args, logger, fileContentByPath) {
|
|
218
|
-
saveCodegenResultToFileSystem(fileContentByPath, args.cppOutputPath, args.etsOutputPath, args.safetyCheck);
|
|
250
|
+
saveCodegenResultToFileSystem(fileContentByPath, args.cppOutputPath, args.etsOutputPath, args.safetyCheck, args.generateType);
|
|
219
251
|
logCodegenResult(logger, fileContentByPath, new core_1.AbsolutePath(''));
|
|
220
252
|
}
|
|
221
|
-
function saveCodegenResultToFileSystem(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck) {
|
|
253
|
+
function saveCodegenResultToFileSystem(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck, generateType) {
|
|
254
|
+
const shouldGenerateTurboModule = generateType === 'all' || generateType === 'turbo-module';
|
|
255
|
+
const shouldGenerateFabric = generateType === 'all' || generateType === 'fabric';
|
|
222
256
|
prepareDirectory(cppOutputPath, enableSafetyCheck);
|
|
223
257
|
prepareDirectory(etsOutputPath, enableSafetyCheck);
|
|
224
|
-
|
|
225
|
-
|
|
258
|
+
if (shouldGenerateFabric) {
|
|
259
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
|
|
260
|
+
}
|
|
261
|
+
if (shouldGenerateTurboModule) {
|
|
262
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
|
|
263
|
+
}
|
|
226
264
|
fileContentByPath.forEach((_fileContent, path) => {
|
|
227
265
|
prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
|
|
228
266
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-oh/react-native-harmony-cli",
|
|
3
|
-
"version": "0.72.
|
|
3
|
+
"version": "0.72.142",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"tmp": "^0.2.1",
|
|
72
72
|
"metro": "0.82.5"
|
|
73
73
|
},
|
|
74
|
-
"homepage": "https://gitcode.com/
|
|
74
|
+
"homepage": "https://gitcode.com/CPF-RN/ohos_react_native",
|
|
75
75
|
"repository": {
|
|
76
76
|
"type": "gitcode",
|
|
77
|
-
"url": "https://gitcode.com/
|
|
77
|
+
"url": "https://gitcode.com/CPF-RN/ohos_react_native"
|
|
78
78
|
}
|
|
79
79
|
}
|