@react-native-oh/react-native-harmony-cli 0.84.1 → 0.84.2

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.
Files changed (103) hide show
  1. package/README.md +4 -4
  2. package/dist/codegen/generators/LibGlueCodeGenerator.js +16 -6
  3. package/dist/commands/codegen-lib-harmony.js +78 -40
  4. package/harmony/{rnoh-hvigor-plugin-0.84.1.tgz → rnoh-hvigor-plugin-0.84.2.tgz} +0 -0
  5. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/00a68392 +0 -0
  6. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0544a6cc +0 -0
  7. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0f36b2db +0 -0
  8. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12f23f1e +0 -0
  9. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/13d95d98 +0 -0
  10. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1629e86b +0 -0
  11. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/180c8379 +0 -0
  12. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1a697147 +0 -0
  13. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1a8271b1 +0 -0
  14. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1b7fa689 +0 -0
  15. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/255a9f13 +0 -0
  16. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/268d155b +0 -0
  17. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/27db9aa4 +0 -0
  18. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/28db79ed +0 -0
  19. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2dc2bbcb +0 -0
  20. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2df5f8c5 +0 -0
  21. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2f88aedb +0 -0
  22. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/31b3a7ea +0 -0
  23. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/36335b1c +0 -0
  24. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/38fca641 +0 -0
  25. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/397722eb +0 -0
  26. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/397b6432 +0 -0
  27. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3b17421f +0 -0
  28. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/454f5e18 +0 -0
  29. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/45ec6cce +0 -0
  30. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/482d51b1 +0 -0
  31. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4ac5cd67 +0 -0
  32. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4d40499a +0 -0
  33. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4dcad919 +0 -0
  34. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4fc31929 +0 -0
  35. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/54edc8f5 +0 -0
  36. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/558a5405 +0 -0
  37. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/58d2b670 +0 -0
  38. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5ec7feca +0 -0
  39. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/62180f3e +0 -0
  40. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/63981360 +0 -0
  41. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/64096c89 +0 -0
  42. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/64af560b +0 -0
  43. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6585e783 +0 -0
  44. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6954304f +0 -0
  45. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/69fd6235 +0 -0
  46. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6d3a0478 +0 -0
  47. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6e131db7 +0 -0
  48. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/778cd8f1 +0 -0
  49. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/788206b6 +0 -0
  50. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7882dc26 +0 -0
  51. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7b3c14f7 +0 -0
  52. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7cdfe667 +0 -0
  53. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8048c487 +0 -0
  54. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8332d9a3 +0 -0
  55. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/84e5b603 +0 -0
  56. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/854d8127 +0 -0
  57. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/88c97376 +0 -0
  58. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/90d5f644 +0 -0
  59. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/967e25ac +0 -0
  60. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/969896c2 +0 -0
  61. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9790193e +0 -0
  62. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/97ae40c5 +0 -0
  63. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9a5bf482 +0 -0
  64. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a07adeb9 +0 -0
  65. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a427f355 +0 -0
  66. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a9dd7eb7 +0 -0
  67. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a9e9d79e +0 -0
  68. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ab920855 +0 -0
  69. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ab9e3038 +0 -0
  70. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/af054988 +0 -0
  71. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/afe03e51 +0 -0
  72. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b3b83913 +0 -0
  73. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b4db7b4d +0 -0
  74. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b5225355 +0 -0
  75. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b8c00f06 +0 -0
  76. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b917a081 +0 -0
  77. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b9e2f3bd +0 -0
  78. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bd70db0e +0 -0
  79. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bdbda648 +0 -0
  80. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/be1e5469 +0 -0
  81. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c9462295 +0 -0
  82. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ca6e5efa +0 -0
  83. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/caf52beb +0 -0
  84. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cb268960 +0 -0
  85. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cca16b15 +0 -0
  86. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cfc1c937 +0 -0
  87. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d10e6e05 +0 -0
  88. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d172fc04 +0 -0
  89. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d4e94e50 +0 -0
  90. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d59f8d2c +0 -0
  91. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/da964053 +0 -0
  92. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e0bb712a +0 -0
  93. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e3e6ca34 +0 -0
  94. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e50f7385 +0 -0
  95. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f1a1d282 +0 -0
  96. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f2514c3c +0 -0
  97. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f66207cf +0 -0
  98. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f8d129ce +0 -0
  99. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/fb1e9558 +0 -0
  100. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ff7e3608 +0 -0
  101. package/package.json +1 -1
  102. package/src/codegen/generators/LibGlueCodeGenerator.ts +23 -12
  103. package/src/commands/codegen-lib-harmony.ts +110 -56
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://gitcode.com/openharmony-sig/ohos_react_native) for more detail.
3
+ Please refer to: [RNOH repo](https://gitcode.com/CPF-RN/ohos_react_native) for more detail.
4
4
 
5
5
  # Documentation
6
6
 
7
- - [中文](https://gitcode.com/openharmony-sig/ohos_react_native/blob/0.82/docs/zh-cn/README.md)
8
- - [English](https://gitcode.com/openharmony-sig/ohos_react_native/blob/0.82/docs/en/README.md)
7
+ - [中文](https://gitcode.com/CPF-RN/ohos_react_native/blob/0.82/docs/zh-cn/README.md)
8
+ - [English](https://gitcode.com/CPF-RN/ohos_react_native/blob/0.82/docs/en/README.md)
9
9
 
10
10
  # License
11
11
 
12
- This library is licensed under The [MIT License (MIT)](https://gitcode.com/openharmony-sig/ohos_react_native)
12
+ This library is licensed under The [MIT License (MIT)](https://gitcode.com/CPF-RN/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
- fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
46
- fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
47
- fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate(this.codegenNoticeLines)
48
- .addReexport({ from: './components/ts', as: 'RNC' })
49
- .addReexport({ from: './turboModules/ts', as: 'TM' })
50
- .build());
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: ((_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)),
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 turboModuleGlueCodeData = turboModulesUberSchema
165
- .findAllSpecSchemasByType('NativeModule')
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');
168
- nativeModuleCodeGenerator
169
- .generate(specSchema)
170
- .forEach(appendToFileContentByPath);
171
- return nativeModuleCodeGenerator.getGlueCodeData();
172
- })
173
- .flat();
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
- arkTSComponentCodeGeneratorCAPI
176
- .generate(arkTSComponentsUberSchema)
177
- .forEach(appendToFileContentByPath);
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
- cppComponentCodeGenerator
183
- .generate({
184
- libraryCppName: libraryCppName,
185
- uberSchema: cppComponentsUberSchema,
186
- })
187
- .forEach(appendToFileContentByPath);
188
- new codegen_1.SharedComponentCodeGenerator((filename) => {
189
- return args.cppOutputPath.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
190
- })
191
- .generate({
192
- libraryCppName: libraryCppName,
193
- uberSchema: componentsUberSchema,
194
- })
195
- .forEach(appendToFileContentByPath);
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: arkTSComponentCodeGeneratorCAPI.getLibGlueCodeData(),
200
- cppComponents: cppComponentCodeGenerator
201
- .getGlueCodeData()
202
- .map(({ name }) => ({ componentName: name })),
203
- turboModules: turboModuleGlueCodeData,
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
- prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
225
- prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
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.84.1",
3
+ "version": "0.84.2",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -73,20 +73,31 @@ export class LibGlueCodeGenerator implements CodeGenerator<LibGlueCodeData> {
73
73
  ),
74
74
  basePackageTemplate.build()
75
75
  );
76
- fileContentByPath.set(
77
- this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
78
- components_indexTS.build()
79
- );
80
- fileContentByPath.set(
81
- this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
82
- turboModules_indexTS.build()
83
- );
76
+ const hasFabricComponents =
77
+ arkTSComponents.length > 0 || cppComponents.length > 0;
78
+ const hasTurboModules = turboModules.length > 0;
79
+ if (hasFabricComponents) {
80
+ fileContentByPath.set(
81
+ this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
82
+ components_indexTS.build()
83
+ );
84
+ }
85
+ if (hasTurboModules) {
86
+ fileContentByPath.set(
87
+ this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
88
+ turboModules_indexTS.build()
89
+ );
90
+ }
91
+ const rootTS = new IndexTSTemplate(this.codegenNoticeLines);
92
+ if (hasFabricComponents) {
93
+ rootTS.addReexport({ from: './components/ts', as: 'RNC' });
94
+ }
95
+ if (hasTurboModules) {
96
+ rootTS.addReexport({ from: './turboModules/ts', as: 'TM' });
97
+ }
84
98
  fileContentByPath.set(
85
99
  this.etsOutputPath.copyWithNewSegment('ts.ts'),
86
- new IndexTSTemplate(this.codegenNoticeLines)
87
- .addReexport({ from: './components/ts', as: 'RNC' })
88
- .addReexport({ from: './turboModules/ts', as: 'TM' })
89
- .build()
100
+ rootTS.build()
90
101
  );
91
102
  generated_indexETS.addReexport({ from: './ts' });
92
103
  fileContentByPath.set(
@@ -26,6 +26,9 @@ import { LibGlueCodeGenerator } from '../codegen/generators/LibGlueCodeGenerator
26
26
 
27
27
  const COMMAND_NAME = 'codegen-lib-harmony';
28
28
 
29
+ const VALID_GENERATE_TYPES = ['all', 'turbo-module', 'fabric'] as const;
30
+ type GenerateType = (typeof VALID_GENERATE_TYPES)[number];
31
+
29
32
  export const commandCodegenLibHarmony: Command = {
30
33
  name: COMMAND_NAME,
31
34
  description:
@@ -69,6 +72,14 @@ export const commandCodegenLibHarmony: Command = {
69
72
  description:
70
73
  '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.',
71
74
  },
75
+ {
76
+ name: '--generate-type <string>',
77
+ description:
78
+ 'Controls which type of code to generate. ' +
79
+ 'Possible values: "all" (default, generates both TurboModule and Fabric code), ' +
80
+ '"turbo-module" (generates only TurboModule code), ' +
81
+ '"fabric" (generates only Fabric component code).',
82
+ },
72
83
  ],
73
84
  func: async (_argv, _config, rawArgs: any) => {
74
85
  const logger = new Logger();
@@ -98,6 +109,7 @@ type RawArgs = {
98
109
  cppOutputPath?: string;
99
110
  etsOutputPath?: string;
100
111
  safetyCheck?: boolean;
112
+ generateType?: string;
101
113
  };
102
114
 
103
115
  function validateArgsAndRetrieveUberSchemaByType(rawArgs: RawArgs) {
@@ -141,6 +153,7 @@ type Args = {
141
153
  cppOutputPath: AbsolutePath;
142
154
  etsOutputPath: AbsolutePath;
143
155
  safetyCheck: boolean;
156
+ generateType: GenerateType;
144
157
  };
145
158
 
146
159
  function validateRawArgs(rawArgs: RawArgs): Args {
@@ -162,6 +175,15 @@ function validateRawArgs(rawArgs: RawArgs): Args {
162
175
  whatCanUserDo: ['Please specify --ets-output-path'],
163
176
  });
164
177
  }
178
+ const generateType = (rawArgs.generateType ?? 'all') as GenerateType;
179
+ if (!VALID_GENERATE_TYPES.includes(generateType)) {
180
+ throw new DescriptiveError({
181
+ whatHappened: `Invalid --generate-type value: "${rawArgs.generateType}". Valid values are: ${VALID_GENERATE_TYPES.join(', ')}`,
182
+ whatCanUserDo: [
183
+ `Please specify one of: ${VALID_GENERATE_TYPES.join(', ')}`,
184
+ ],
185
+ });
186
+ }
165
187
  return {
166
188
  npmPackageName: rawArgs.npmPackageName!,
167
189
  tmSpecPaths: (rawArgs.turboModulesSpecPaths ?? []).map(
@@ -176,6 +198,7 @@ function validateRawArgs(rawArgs: RawArgs): Args {
176
198
  etsOutputPath: new AbsolutePath(rawArgs.etsOutputPath!),
177
199
  cppOutputPath: new AbsolutePath(rawArgs.cppOutputPath!),
178
200
  safetyCheck: !!rawArgs.safetyCheck,
201
+ generateType,
179
202
  };
180
203
  }
181
204
 
@@ -220,25 +243,36 @@ function generateCodeInMemory({
220
243
  fileContentByPath.set(path, fileContent);
221
244
  };
222
245
 
223
- const turboModuleGlueCodeData = turboModulesUberSchema
224
- .findAllSpecSchemasByType('NativeModule')
225
- .map((specSchema) => {
226
- const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
227
- args.cppOutputPath.copyWithNewSegment(
228
- 'RNOH',
229
- 'generated',
230
- 'turbo_modules'
231
- ),
232
- args.etsOutputPath.copyWithNewSegment('turboModules'),
233
- CODEGEN_NOTICE_LINES,
234
- '@rnoh/react-native-openharmony/ts'
235
- );
236
- nativeModuleCodeGenerator
237
- .generate(specSchema)
238
- .forEach(appendToFileContentByPath);
239
- return nativeModuleCodeGenerator.getGlueCodeData();
240
- })
241
- .flat();
246
+ const { generateType } = args;
247
+ const shouldGenerateTurboModule =
248
+ generateType === 'all' || generateType === 'turbo-module';
249
+ const shouldGenerateFabric =
250
+ generateType === 'all' || generateType === 'fabric';
251
+
252
+ let turboModuleGlueCodeData: ReturnType<
253
+ NativeModuleCodeGenerator['getGlueCodeData']
254
+ > = [];
255
+ if (shouldGenerateTurboModule) {
256
+ turboModuleGlueCodeData = turboModulesUberSchema
257
+ .findAllSpecSchemasByType('NativeModule')
258
+ .map((specSchema) => {
259
+ const nativeModuleCodeGenerator = new NativeModuleCodeGenerator(
260
+ args.cppOutputPath.copyWithNewSegment(
261
+ 'RNOH',
262
+ 'generated',
263
+ 'turbo_modules'
264
+ ),
265
+ args.etsOutputPath.copyWithNewSegment('turboModules'),
266
+ CODEGEN_NOTICE_LINES,
267
+ '@rnoh/react-native-openharmony/ts'
268
+ );
269
+ nativeModuleCodeGenerator
270
+ .generate(specSchema)
271
+ .forEach(appendToFileContentByPath);
272
+ return nativeModuleCodeGenerator.getGlueCodeData();
273
+ })
274
+ .flat();
275
+ }
242
276
 
243
277
  const arkTSComponentCodeGeneratorCAPI = new ArkTSComponentCodeGeneratorCAPI(
244
278
  args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components'),
@@ -246,9 +280,12 @@ function generateCodeInMemory({
246
280
  CODEGEN_NOTICE_LINES,
247
281
  '@rnoh/react-native-openharmony/ts'
248
282
  );
249
- arkTSComponentCodeGeneratorCAPI
250
- .generate(arkTSComponentsUberSchema)
251
- .forEach(appendToFileContentByPath);
283
+
284
+ if (shouldGenerateFabric) {
285
+ arkTSComponentCodeGeneratorCAPI
286
+ .generate(arkTSComponentsUberSchema)
287
+ .forEach(appendToFileContentByPath);
288
+ }
252
289
 
253
290
  const libraryCppName = deriveLibraryCppNameFromNpmPackageName(
254
291
  args.npmPackageName
@@ -264,27 +301,29 @@ function generateCodeInMemory({
264
301
  },
265
302
  CODEGEN_NOTICE_LINES
266
303
  );
267
- cppComponentCodeGenerator
268
- .generate({
269
- libraryCppName: libraryCppName,
270
- uberSchema: cppComponentsUberSchema,
271
- })
272
- .forEach(appendToFileContentByPath);
304
+ if (shouldGenerateFabric) {
305
+ cppComponentCodeGenerator
306
+ .generate({
307
+ libraryCppName: libraryCppName,
308
+ uberSchema: cppComponentsUberSchema,
309
+ })
310
+ .forEach(appendToFileContentByPath);
273
311
 
274
- new SharedComponentCodeGenerator((filename) => {
275
- return args.cppOutputPath.copyWithNewSegment(
276
- 'react',
277
- 'renderer',
278
- 'components',
279
- libraryCppName,
280
- filename
281
- );
282
- })
283
- .generate({
284
- libraryCppName: libraryCppName,
285
- uberSchema: componentsUberSchema,
312
+ new SharedComponentCodeGenerator((filename) => {
313
+ return args.cppOutputPath.copyWithNewSegment(
314
+ 'react',
315
+ 'renderer',
316
+ 'components',
317
+ libraryCppName,
318
+ filename
319
+ );
286
320
  })
287
- .forEach(appendToFileContentByPath);
321
+ .generate({
322
+ libraryCppName: libraryCppName,
323
+ uberSchema: componentsUberSchema,
324
+ })
325
+ .forEach(appendToFileContentByPath);
326
+ }
288
327
 
289
328
  new LibGlueCodeGenerator(
290
329
  args.cppOutputPath,
@@ -293,11 +332,15 @@ function generateCodeInMemory({
293
332
  )
294
333
  .generate({
295
334
  libraryCppName,
296
- arkTSComponents: arkTSComponentCodeGeneratorCAPI.getLibGlueCodeData(),
297
- cppComponents: cppComponentCodeGenerator
298
- .getGlueCodeData()
299
- .map(({ name }) => ({ componentName: name })),
300
- turboModules: turboModuleGlueCodeData,
335
+ arkTSComponents: shouldGenerateFabric
336
+ ? arkTSComponentCodeGeneratorCAPI.getLibGlueCodeData()
337
+ : [],
338
+ cppComponents: shouldGenerateFabric
339
+ ? cppComponentCodeGenerator
340
+ .getGlueCodeData()
341
+ .map(({ name }) => ({ componentName: name }))
342
+ : [],
343
+ turboModules: shouldGenerateTurboModule ? turboModuleGlueCodeData : [],
301
344
  })
302
345
  .forEach(appendToFileContentByPath);
303
346
 
@@ -325,7 +368,8 @@ function saveAndLogCodegenResult(
325
368
  fileContentByPath,
326
369
  args.cppOutputPath,
327
370
  args.etsOutputPath,
328
- args.safetyCheck
371
+ args.safetyCheck,
372
+ args.generateType
329
373
  );
330
374
  logCodegenResult(logger, fileContentByPath, new AbsolutePath(''));
331
375
  }
@@ -334,18 +378,28 @@ function saveCodegenResultToFileSystem(
334
378
  fileContentByPath: Map<AbsolutePath, string>,
335
379
  cppOutputPath: AbsolutePath,
336
380
  etsOutputPath: AbsolutePath,
337
- enableSafetyCheck: boolean
381
+ enableSafetyCheck: boolean,
382
+ generateType: GenerateType
338
383
  ) {
384
+ const shouldGenerateTurboModule =
385
+ generateType === 'all' || generateType === 'turbo-module';
386
+ const shouldGenerateFabric =
387
+ generateType === 'all' || generateType === 'fabric';
388
+
339
389
  prepareDirectory(cppOutputPath, enableSafetyCheck);
340
390
  prepareDirectory(etsOutputPath, enableSafetyCheck);
341
- prepareDirectory(
342
- etsOutputPath.copyWithNewSegment('components'),
343
- enableSafetyCheck
344
- );
345
- prepareDirectory(
346
- etsOutputPath.copyWithNewSegment('turboModules'),
347
- enableSafetyCheck
348
- );
391
+ if (shouldGenerateFabric) {
392
+ prepareDirectory(
393
+ etsOutputPath.copyWithNewSegment('components'),
394
+ enableSafetyCheck
395
+ );
396
+ }
397
+ if (shouldGenerateTurboModule) {
398
+ prepareDirectory(
399
+ etsOutputPath.copyWithNewSegment('turboModules'),
400
+ enableSafetyCheck
401
+ );
402
+ }
349
403
  fileContentByPath.forEach((_fileContent, path) => {
350
404
  prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
351
405
  });