@react-native-oh/react-native-harmony-cli 0.0.26-9 → 0.0.27

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 (51) hide show
  1. package/dist/codegen/core/UberSchema.js +3 -0
  2. package/dist/codegen/generators/{GlueCodeGenerator.js → AppBuildTimeGlueCodeGenerator.js} +11 -10
  3. package/dist/codegen/generators/{ComponentCodeGeneratorArkTS.js → ArkTSComponentCodeGeneratorArkTS.js} +8 -6
  4. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +74 -0
  5. package/dist/codegen/generators/{ComponentCodeGeneratorCAPI.js → CppComponentCodeGenerator.js} +10 -33
  6. package/dist/codegen/generators/LibGlueCodeGenerator.js +50 -0
  7. package/dist/codegen/generators/NativeModuleCodeGenerator.js +6 -5
  8. package/dist/codegen/generators/SharedComponentCodeGenerator.js +34 -0
  9. package/dist/codegen/generators/UberGeneratorV1.js +7 -6
  10. package/dist/codegen/generators/UberGeneratorV2.js +25 -14
  11. package/dist/codegen/generators/index.js +5 -3
  12. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +9 -7
  13. package/dist/codegen/templates/{GeneratedPackageHTemplate.js → BasePackageHTemplate.js} +40 -11
  14. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +2 -1
  15. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +9 -11
  16. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +11 -8
  17. package/dist/codegen/templates/IndexTSTemplate.js +12 -9
  18. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +1 -0
  19. package/dist/codegen/templates/TurboModuleCppTemplate.js +10 -10
  20. package/dist/codegen/templates/TurboModuleHTemplate.js +10 -10
  21. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +11 -10
  22. package/dist/commands/codegen-harmony.js +11 -5
  23. package/dist/commands/codegen-lib-harmony.js +253 -0
  24. package/dist/commands/index.js +1 -0
  25. package/dist/index.js +1 -0
  26. package/package.json +1 -1
  27. package/src/codegen/core/UberSchema.ts +4 -0
  28. package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +13 -9
  29. package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +11 -5
  30. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +112 -0
  31. package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +14 -43
  32. package/src/codegen/generators/LibGlueCodeGenerator.ts +91 -0
  33. package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -5
  34. package/src/codegen/generators/SharedComponentCodeGenerator.ts +50 -0
  35. package/src/codegen/generators/UberGeneratorV1.ts +12 -8
  36. package/src/codegen/generators/UberGeneratorV2.ts +32 -16
  37. package/src/codegen/generators/index.ts +5 -3
  38. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +12 -7
  39. package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +45 -12
  40. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +2 -1
  41. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +8 -10
  42. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +13 -8
  43. package/src/codegen/templates/IndexTSTemplate.ts +11 -9
  44. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +1 -0
  45. package/src/codegen/templates/TurboModuleCppTemplate.ts +9 -9
  46. package/src/codegen/templates/TurboModuleHTemplate.ts +9 -9
  47. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +13 -9
  48. package/src/commands/codegen-harmony.ts +24 -7
  49. package/src/commands/codegen-lib-harmony.ts +387 -0
  50. package/src/commands/index.ts +1 -0
  51. package/src/index.ts +2 -0
@@ -6,17 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ComponentJSIBinderHTemplate = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const TEMPLATE = `
9
- #pragma once
10
-
11
9
  /**
12
- * This code was generated by "react-native codegen-harmony"
13
- *
14
- * Do not edit this file as changes may cause incorrect behavior and will be
15
- * lost once the code is regenerated.
16
- *
17
- * @generatorVersion: {{generatorVersion}}
10
+ {{#codegenNoticeLines}}
11
+ * {{{line}}}
12
+ {{/codegenNoticeLines}}
18
13
  */
19
14
 
15
+ #pragma once
20
16
  #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
21
17
 
22
18
  namespace rnoh {
@@ -49,9 +45,9 @@ class {{name}}JSIBinder : public ViewComponentJSIBinder {
49
45
  } // namespace rnoh
50
46
  `;
51
47
  class ComponentJSIBinderHTemplate {
52
- constructor(name, generatorVersion) {
48
+ constructor(name, codegenNoticeLines) {
53
49
  this.name = name;
54
- this.generatorVersion = generatorVersion;
50
+ this.codegenNoticeLines = codegenNoticeLines;
55
51
  this.props = [];
56
52
  this.events = [];
57
53
  }
@@ -63,8 +59,10 @@ class ComponentJSIBinderHTemplate {
63
59
  }
64
60
  build() {
65
61
  return mustache_1.default.render(TEMPLATE.trimStart(), {
62
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
63
+ line,
64
+ })),
66
65
  name: this.name,
67
- generatorVersion: this.generatorVersion,
68
66
  props: this.props.map((prop) => ({
69
67
  name: prop.name,
70
68
  type: prop.isObject ? '"Object"' : 'true',
@@ -7,12 +7,9 @@ exports.ComponentUtilsTSTemplate = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const TEMPLATE = `
9
9
  /**
10
- * This code was generated by "react-native codegen-harmony"
11
- *
12
- * Do not edit this file as changes may cause incorrect behavior and will be
13
- * lost once the code is regenerated.
14
- *
15
- * @generatorVersion: 1
10
+ {{#codegenNoticeLines}}
11
+ * {{{line}}}
12
+ {{/codegenNoticeLines}}
16
13
  */
17
14
 
18
15
  import {
@@ -26,7 +23,7 @@ import {
26
23
  Tag,
27
24
  RNComponentCommandReceiver,
28
25
  ViewPropsSelector,
29
- } from '../../ts';
26
+ } from '{{{rnohImport}}}';
30
27
 
31
28
 
32
29
  export namespace {{name}} {
@@ -143,8 +140,10 @@ const COLOR_VALUE_GETTER_TEMPLATE = ` if (this.rawProps.{{name}}) {
143
140
  return new Color({ r: 0, g: 0, b: 0, a: 255})
144
141
  }`;
145
142
  class ComponentUtilsTSTemplate {
146
- constructor(name) {
143
+ constructor(name, codegenNoticeLines, rnohImport) {
147
144
  this.name = name;
145
+ this.codegenNoticeLines = codegenNoticeLines;
146
+ this.rnohImport = rnohImport;
148
147
  this.props = [];
149
148
  this.events = [];
150
149
  this.commands = [];
@@ -162,7 +161,11 @@ class ComponentUtilsTSTemplate {
162
161
  }
163
162
  build() {
164
163
  return mustache_1.default.render(TEMPLATE.trimStart(), {
164
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
165
+ line,
166
+ })),
165
167
  name: this.name,
168
+ rnohImport: this.rnohImport,
166
169
  props: this.props.map((prop) => ({
167
170
  name: prop.name,
168
171
  type: prop.tsType,
@@ -7,27 +7,27 @@ exports.IndexTSTemplate = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const TEMPLATE = `
9
9
  /**
10
- * This code was generated by "react-native codegen-harmony"
11
- *
12
- * Do not edit this file as changes may cause incorrect behavior and will be
13
- * lost once the code is regenerated.
10
+ {{#codegenNoticeLines}}
11
+ * {{{line}}}
12
+ {{/codegenNoticeLines}}
14
13
  */
14
+
15
15
  {{#reexports}}
16
16
  export * {{as}}from "{{{from}}}"
17
17
  {{/reexports}}
18
18
  `;
19
19
  const TEMPLATE_EMPTY = `
20
20
  /**
21
- * This code was generated by "react-native codegen-harmony"
22
- *
23
- * Do not edit this file as changes may cause incorrect behavior and will be
24
- * lost once the code is regenerated.
21
+ {{#codegenNoticeLines}}
22
+ * {{{line}}}
23
+ {{/codegenNoticeLines}}
25
24
  */
26
25
 
27
26
  export {}
28
27
  `;
29
28
  class IndexTSTemplate {
30
- constructor() {
29
+ constructor(codegenNoticeLines) {
30
+ this.codegenNoticeLines = codegenNoticeLines;
31
31
  this.reexports = [];
32
32
  }
33
33
  addReexport(reexport) {
@@ -39,6 +39,9 @@ class IndexTSTemplate {
39
39
  return mustache_1.default.render(TEMPLATE_EMPTY, {});
40
40
  }
41
41
  return mustache_1.default.render(TEMPLATE.trimStart(), {
42
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
43
+ line,
44
+ })),
42
45
  reexports: this.reexports.map((reexport) => ({
43
46
  from: reexport.from,
44
47
  as: reexport.as ? `as ${reexport.as} ` : '',
@@ -14,6 +14,7 @@ const TEMPLATE = `
14
14
  *
15
15
  * @generatorVersion: 1
16
16
  */
17
+
17
18
  #pragma once
18
19
 
19
20
  #include "RNOH/Package.h"
@@ -7,13 +7,11 @@ exports.TurboModuleCppTemplate = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const TEMPLATE = `
9
9
  /**
10
- * This code was generated by "react-native codegen-harmony"
11
- *
12
- * Do not edit this file as changes may cause incorrect behavior and will be
13
- * lost once the code is regenerated.
14
- *
15
- * @generatorVersion: {{generatorVersion}}
10
+ {{#codegenNoticeLines}}
11
+ * {{{line}}}
12
+ {{/codegenNoticeLines}}
16
13
  */
14
+
17
15
  #include "{{className}}.h"
18
16
 
19
17
  namespace rnoh {
@@ -30,18 +28,20 @@ using namespace facebook;
30
28
  } // namespace rnoh
31
29
  `;
32
30
  class TurboModuleCppTemplate {
33
- constructor(name, generatorVersion) {
31
+ constructor(name, codegenNoticeLines) {
34
32
  this.name = name;
35
- this.generatorVersion = generatorVersion;
33
+ this.codegenNoticeLines = codegenNoticeLines;
36
34
  this.methods = [];
37
35
  }
38
36
  addMethod(method) {
39
37
  this.methods.push(method);
40
38
  }
41
39
  build() {
42
- return mustache_1.default.render(TEMPLATE, {
40
+ return mustache_1.default.render(TEMPLATE.trimStart(), {
41
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
42
+ line,
43
+ })),
43
44
  className: this.name,
44
- generatorVersion: this.generatorVersion,
45
45
  methods: this.methods.map((method) => ({
46
46
  name: method.name,
47
47
  argsCount: method.argsCount,
@@ -7,13 +7,11 @@ exports.TurboModuleHTemplate = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const TEMPLATE = `
9
9
  /**
10
- * This code was generated by "react-native codegen-harmony"
11
- *
12
- * Do not edit this file as changes may cause incorrect behavior and will be
13
- * lost once the code is regenerated.
14
- *
15
- * @generatorVersion: {{generatorVersion}}
10
+ {{#codegenNoticeLines}}
11
+ * {{{line}}}
12
+ {{/codegenNoticeLines}}
16
13
  */
14
+
17
15
  #pragma once
18
16
 
19
17
  #include "RNOH/ArkTSTurboModule.h"
@@ -28,14 +26,16 @@ class JSI_EXPORT {{className}} : public ArkTSTurboModule {
28
26
  } // namespace rnoh
29
27
  `;
30
28
  class TurboModuleHTemplate {
31
- constructor(name, generatorVersion) {
29
+ constructor(name, codegenNoticeLines) {
32
30
  this.name = name;
33
- this.generatorVersion = generatorVersion;
31
+ this.codegenNoticeLines = codegenNoticeLines;
34
32
  }
35
33
  build() {
36
- return mustache_1.default.render(TEMPLATE, {
34
+ return mustache_1.default.render(TEMPLATE.trimStart(), {
37
35
  className: this.name,
38
- generatorVersion: this.generatorVersion,
36
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
37
+ line,
38
+ })),
39
39
  });
40
40
  }
41
41
  }
@@ -7,15 +7,12 @@ exports.TurboModuleInterfaceTS = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const TEMPLATE = `
9
9
  /**
10
- * This code was generated by "react-native codegen-harmony"
11
- *
12
- * Do not edit this file as changes may cause incorrect behavior and will be
13
- * lost once the code is regenerated.
14
- *
15
- * @generatorVersion: {{generatorVersion}}
10
+ {{#codegenNoticeLines}}
11
+ * {{{line}}}
12
+ {{/codegenNoticeLines}}
16
13
  */
17
14
 
18
- import { Tag } from "../../ts"
15
+ import { Tag } from "{{{rnohImport}}}"
19
16
 
20
17
  export namespace {{name}} {
21
18
  export const NAME = '{{name}}' as const
@@ -41,9 +38,10 @@ export namespace {{name}} {
41
38
  }
42
39
  `;
43
40
  class TurboModuleInterfaceTS {
44
- constructor(name, generatorVersion) {
41
+ constructor(name, codegenNoticeLines, rnohImport) {
45
42
  this.name = name;
46
- this.generatorVersion = generatorVersion;
43
+ this.codegenNoticeLines = codegenNoticeLines;
44
+ this.rnohImport = rnohImport;
47
45
  this.methods = [];
48
46
  this.aliases = [];
49
47
  this.enumModels = [];
@@ -59,10 +57,13 @@ class TurboModuleInterfaceTS {
59
57
  }
60
58
  build() {
61
59
  return mustache_1.default.render(TEMPLATE.trimStart(), {
60
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
61
+ line,
62
+ })),
62
63
  name: this.name,
63
64
  aliases: this.aliases,
64
65
  enums: this.enumModels,
65
- generatorVersion: this.generatorVersion,
66
+ rnohImport: this.rnohImport,
66
67
  methods: this.methods.map((method) => ({
67
68
  name: method.name,
68
69
  stringifiedArgs: method.stringifiedArgs,
@@ -21,7 +21,7 @@ const codegen_1 = require("../codegen");
21
21
  const io_1 = require("../io");
22
22
  exports.commandCodegenHarmony = {
23
23
  name: 'codegen-harmony',
24
- description: 'Generates a glue layer and native utilities from Turbo Module or Fabric Components specifications',
24
+ 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.',
25
25
  options: [
26
26
  {
27
27
  name: '--rnoh-module-path <path>',
@@ -66,9 +66,15 @@ exports.commandCodegenHarmony = {
66
66
  return codegenVersion === 2;
67
67
  });
68
68
  // instantiate objects
69
- const uberGeneratorV1 = new codegen_1.UberGeneratorV1(cppOutputPath, etsOutputPath);
70
- const uberGeneratorV2 = new codegen_1.UberGeneratorV2(cppOutputPath, etsOutputPath);
71
- const glueCodeGenerator = new codegen_1.GlueCodeGenerator(cppOutputPath, etsOutputPath);
69
+ const codegenNoticeLines = [
70
+ 'This code was generated by "react-native codegen-harmony"',
71
+ '',
72
+ 'Do not edit this file as changes may cause incorrect behavior and will be',
73
+ 'lost once the code is regenerated.',
74
+ ];
75
+ const uberGeneratorV1 = new codegen_1.UberGeneratorV1(cppOutputPath, etsOutputPath, [...codegenNoticeLines, '', '@generatorVersion: 1']);
76
+ const uberGeneratorV2 = new codegen_1.UberGeneratorV2(cppOutputPath, etsOutputPath, [...codegenNoticeLines, '', '@generatorVersion: 2']);
77
+ const glueCodeGenerator = new codegen_1.AppBuildTimeGlueCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines);
72
78
  // generate the code
73
79
  const fileContentByPath = new Map();
74
80
  const appendToFileContentByPath = (fileContent, path) => {
@@ -130,7 +136,7 @@ function collectLibrariesData(projectRootPath, onShouldAcceptCodegenConfig) {
130
136
  if (codegenConfig &&
131
137
  onShouldAcceptCodegenConfig(codegenConfig.getVersion(), packageJSON.name)) {
132
138
  results.push({
133
- name: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
139
+ libraryCppName: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
134
140
  uberSchema: codegen_1.UberSchema.fromCodegenConfig(codegenConfig),
135
141
  });
136
142
  }
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.commandCodegenLibHarmony = void 0;
16
+ const core_1 = require("../core");
17
+ const io_1 = require("../io");
18
+ const node_fs_1 = __importDefault(require("node:fs"));
19
+ const codegen_1 = require("../codegen");
20
+ const case_1 = __importDefault(require("case"));
21
+ const LibGlueCodeGenerator_1 = require("../codegen/generators/LibGlueCodeGenerator");
22
+ const COMMAND_NAME = 'codegen-lib-harmony';
23
+ exports.commandCodegenLibHarmony = {
24
+ name: COMMAND_NAME,
25
+ 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.',
26
+ options: [
27
+ {
28
+ name: '--npm-package-name <string>',
29
+ 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.',
30
+ },
31
+ {
32
+ name: '--turbo-modules-spec-paths [path]',
33
+ description: 'Path or paths to Turbo Module spec files. Each path can point to a spec file or a directory containing spec files.',
34
+ parse: (val) => val.split(' '),
35
+ },
36
+ {
37
+ name: '--arkts-components-spec-paths [path]',
38
+ 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.',
39
+ parse: (val) => val.split(' '),
40
+ },
41
+ {
42
+ name: '--cpp-components-spec-paths [path]',
43
+ 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.',
44
+ parse: (val) => val.split(' '),
45
+ },
46
+ {
47
+ name: '--cpp-output-path <path>',
48
+ description: 'Specifies the relative path to the output directory intended for storing generated C++ files.',
49
+ },
50
+ {
51
+ name: '--ets-output-path <path>',
52
+ description: 'Specifies the relative path to the output directory intended for storing generated ETS files.',
53
+ },
54
+ {
55
+ name: '--no-safety-check [boolean]',
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.',
57
+ },
58
+ ],
59
+ func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
60
+ const logger = new io_1.Logger();
61
+ try {
62
+ const { args, uberSchemaByType } = validateArgsAndRetrieveUberSchemaByType(rawArgs);
63
+ const fileContentByPath = generateCodeInMemory({
64
+ args,
65
+ uberSchemaByType,
66
+ });
67
+ saveAndLogCodegenResult(args, logger, fileContentByPath);
68
+ }
69
+ catch (err) {
70
+ if (err instanceof core_1.DescriptiveError && !err.isUnexpected()) {
71
+ logger.descriptiveError(err);
72
+ return;
73
+ }
74
+ throw err;
75
+ }
76
+ }),
77
+ };
78
+ function validateArgsAndRetrieveUberSchemaByType(rawArgs) {
79
+ const args = validateRawArgs(rawArgs);
80
+ const arkTSComponentSpecPaths = specPathsToSpecFilePaths(args.arkTSComponentsSpecPaths);
81
+ const turboModulesUberSchema = codegen_1.UberSchema.fromSpecFilePaths(specPathsToSpecFilePaths(args.tmSpecPaths));
82
+ const arkTSComponentsUberSchema = codegen_1.UberSchema.fromSpecFilePaths(arkTSComponentSpecPaths);
83
+ const cppComponentSpecPaths = specPathsToSpecFilePaths(args.cppComponentsSpecPaths);
84
+ const cppComponentsUberSchema = codegen_1.UberSchema.fromSpecFilePaths(cppComponentSpecPaths);
85
+ const componentsUberSchema = codegen_1.UberSchema.fromSpecFilePaths([
86
+ ...arkTSComponentSpecPaths,
87
+ ...cppComponentSpecPaths,
88
+ ]);
89
+ return {
90
+ args,
91
+ uberSchemaByType: {
92
+ turboModulesUberSchema,
93
+ arkTSComponentsUberSchema,
94
+ cppComponentsUberSchema,
95
+ componentsUberSchema,
96
+ },
97
+ };
98
+ }
99
+ function validateRawArgs(rawArgs) {
100
+ var _a, _b, _c;
101
+ if (!rawArgs.npmPackageName) {
102
+ throw new core_1.DescriptiveError({
103
+ whatHappened: '--npm-package-name is required',
104
+ whatCanUserDo: { default: ['Please specify --npm-package-name'] },
105
+ });
106
+ }
107
+ if (!rawArgs.cppOutputPath) {
108
+ throw new core_1.DescriptiveError({
109
+ whatHappened: '--cpp-output-path is required',
110
+ whatCanUserDo: { default: ['Please specify --cpp-output-path'] },
111
+ });
112
+ }
113
+ if (!rawArgs.etsOutputPath) {
114
+ throw new core_1.DescriptiveError({
115
+ whatHappened: '--ets-output-path is required',
116
+ whatCanUserDo: { default: ['Please specify --ets-output-path'] },
117
+ });
118
+ }
119
+ return {
120
+ npmPackageName: rawArgs.npmPackageName,
121
+ tmSpecPaths: ((_a = rawArgs.turboModulesSpecPaths) !== null && _a !== void 0 ? _a : []).map((path) => new core_1.AbsolutePath(path)),
122
+ arkTSComponentsSpecPaths: ((_b = rawArgs.arktsComponentsSpecPaths) !== null && _b !== void 0 ? _b : []).map((path) => new core_1.AbsolutePath(path)),
123
+ cppComponentsSpecPaths: ((_c = rawArgs.cppComponentsSpecPaths) !== null && _c !== void 0 ? _c : []).map((path) => new core_1.AbsolutePath(path)),
124
+ etsOutputPath: new core_1.AbsolutePath(rawArgs.etsOutputPath),
125
+ cppOutputPath: new core_1.AbsolutePath(rawArgs.cppOutputPath),
126
+ safetyCheck: !!rawArgs.safetyCheck,
127
+ };
128
+ }
129
+ function specPathsToSpecFilePaths(specPaths) {
130
+ const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
131
+ return specPaths.flatMap((specPath) => {
132
+ if (!node_fs_1.default.existsSync(specPath.getValue())) {
133
+ throw new core_1.DescriptiveError({
134
+ whatHappened: `No such file or directory: ${specPath.getValue()}`,
135
+ whatCanUserDo: {
136
+ default: [`Are you sure provided specPath exists?`],
137
+ },
138
+ });
139
+ }
140
+ if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
141
+ return (0, io_1.findFilePathsWithExtensions)(specPath, SUPPORTED_SPEC_EXTENSIONS);
142
+ }
143
+ else {
144
+ const ext = specPath.getExtension();
145
+ if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
146
+ return [specPath];
147
+ }
148
+ return [];
149
+ }
150
+ });
151
+ }
152
+ function generateCodeInMemory({ args, uberSchemaByType: { arkTSComponentsUberSchema, componentsUberSchema, cppComponentsUberSchema, turboModulesUberSchema, }, }) {
153
+ const CODEGEN_NOTICE_LINES = [
154
+ `This code was generated by "react-native ${COMMAND_NAME}"`,
155
+ ];
156
+ const fileContentByPath = new Map();
157
+ const appendToFileContentByPath = (fileContent, path) => {
158
+ fileContentByPath.set(path, fileContent);
159
+ };
160
+ const turboModuleGlueCodeData = turboModulesUberSchema
161
+ .findAllSpecSchemasByType('NativeModule')
162
+ .map((specSchema) => {
163
+ 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');
164
+ nativeModuleCodeGenerator
165
+ .generate(specSchema)
166
+ .forEach(appendToFileContentByPath);
167
+ return nativeModuleCodeGenerator.getGlueCodeData();
168
+ })
169
+ .flat();
170
+ const arkTSComponentCodeGeneratorCAPI = new codegen_1.ArkTSComponentCodeGeneratorCAPI(args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components'), args.etsOutputPath.copyWithNewSegment('components'), CODEGEN_NOTICE_LINES, '@rnoh/react-native-openharmony/ts');
171
+ arkTSComponentCodeGeneratorCAPI
172
+ .generate(arkTSComponentsUberSchema)
173
+ .forEach(appendToFileContentByPath);
174
+ const libraryCppName = deriveLibraryCppNameFromNpmPackageName(args.npmPackageName);
175
+ const cppComponentCodeGenerator = new codegen_1.CppComponentCodeGenerator((filename) => {
176
+ return args.cppOutputPath.copyWithNewSegment('RNOH', 'generated', 'components', filename);
177
+ }, CODEGEN_NOTICE_LINES);
178
+ cppComponentCodeGenerator
179
+ .generate({
180
+ libraryCppName: libraryCppName,
181
+ uberSchema: cppComponentsUberSchema,
182
+ })
183
+ .forEach(appendToFileContentByPath);
184
+ new codegen_1.SharedComponentCodeGenerator((filename) => {
185
+ return args.cppOutputPath.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
186
+ })
187
+ .generate({
188
+ libraryCppName: libraryCppName,
189
+ uberSchema: componentsUberSchema,
190
+ })
191
+ .forEach(appendToFileContentByPath);
192
+ new LibGlueCodeGenerator_1.LibGlueCodeGenerator(args.cppOutputPath, args.etsOutputPath, CODEGEN_NOTICE_LINES)
193
+ .generate({
194
+ libraryCppName,
195
+ arkTSComponents: arkTSComponentCodeGeneratorCAPI.getLibGlueCodeData(),
196
+ cppComponents: cppComponentCodeGenerator
197
+ .getGlueCodeData()
198
+ .map(({ name }) => ({ componentName: name })),
199
+ turboModules: turboModuleGlueCodeData,
200
+ })
201
+ .forEach(appendToFileContentByPath);
202
+ return fileContentByPath;
203
+ }
204
+ function deriveLibraryCppNameFromNpmPackageName(npmPackageName) {
205
+ let result = npmPackageName;
206
+ if (npmPackageName.includes('/')) {
207
+ result.replace('@', '');
208
+ result = npmPackageName.replace('/', '__');
209
+ }
210
+ result = case_1.default.snake(result);
211
+ return result;
212
+ }
213
+ function saveAndLogCodegenResult(args, logger, fileContentByPath) {
214
+ saveCodegenResultToFileSystem(fileContentByPath, args.cppOutputPath, args.etsOutputPath, args.safetyCheck);
215
+ logCodegenResult(logger, fileContentByPath, new core_1.AbsolutePath(''));
216
+ }
217
+ function saveCodegenResultToFileSystem(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck) {
218
+ prepareDirectory(cppOutputPath, enableSafetyCheck);
219
+ prepareDirectory(etsOutputPath, enableSafetyCheck);
220
+ prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
221
+ prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
222
+ fileContentByPath.forEach((_fileContent, path) => {
223
+ prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
224
+ });
225
+ fileContentByPath.forEach((fileContent, path) => {
226
+ node_fs_1.default.writeFileSync(path.getValue(), fileContent);
227
+ });
228
+ }
229
+ function prepareDirectory(path, enableSafetyCheck) {
230
+ (0, core_1.maybeMakeDirectories)(path);
231
+ if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
232
+ throw new core_1.DescriptiveError({
233
+ whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
234
+ whatCanUserDo: {
235
+ default: [
236
+ 'Run this command with --no-safety-check flag',
237
+ 'Run codegen from different location',
238
+ ],
239
+ },
240
+ });
241
+ }
242
+ (0, core_1.maybeRemoveFilesInDirectory)(path);
243
+ }
244
+ function logCodegenResult(logger, fileContentByPath, rootPath) {
245
+ const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => path.relativeTo(rootPath).getValue());
246
+ sortedRelativePathStrings.sort();
247
+ sortedRelativePathStrings.forEach((pathStr) => {
248
+ logger.info((styles) => styles.gray(`• ${pathStr}`));
249
+ });
250
+ logger.info(() => '');
251
+ logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`, { prefix: true });
252
+ logger.info(() => '');
253
+ }
@@ -20,3 +20,4 @@ __exportStar(require("./unpack-harmony"), exports);
20
20
  __exportStar(require("./create-metro-host-constants"), exports);
21
21
  __exportStar(require("./codegen-harmony"), exports);
22
22
  __exportStar(require("./verify-package-harmony"), exports);
23
+ __exportStar(require("./codegen-lib-harmony"), exports);
package/dist/index.js CHANGED
@@ -10,5 +10,6 @@ exports.config = {
10
10
  commands_1.commandCreateMetroConstantsHarmony,
11
11
  commands_1.commandCodegenHarmony,
12
12
  commands_1.commandVerifyPackageHarmony,
13
+ commands_1.commandCodegenLibHarmony,
13
14
  ],
14
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-oh/react-native-harmony-cli",
3
- "version": "0.0.26-9",
3
+ "version": "0.0.27",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -33,6 +33,10 @@ type FindSpecSchemaByType<
33
33
  * Contains component and turbo module (NativeModule) schemas. The "Uber" word is used here to highlight that SpecSchemas don't extend this class.
34
34
  */
35
35
  export class UberSchema implements ValueObject {
36
+ static fromSpecFilePaths(specPaths: AbsolutePath[]): UberSchema {
37
+ return new UberSchema(createRawUberSchemaFromSpecFilePaths(specPaths));
38
+ }
39
+
36
40
  static fromCodegenConfig(codegenConfig: CodegenConfig): UberSchema {
37
41
  try {
38
42
  return new UberSchema(
@@ -2,11 +2,11 @@ import Case from 'case';
2
2
  import { AbsolutePath } from '../../core';
3
3
  import { CodeGenerator } from '../core';
4
4
  import { IndexTSTemplate, RNOHGeneratedPackageHTemplate } from '../templates';
5
- import { BasePackageHTemplate } from '../templates/GeneratedPackageHTemplate';
5
+ import { BasePackageHTemplate } from '../templates/BasePackageHTemplate';
6
6
 
7
7
  export type GlueCodeComponentDataV1 = { name: string; eventNames: string[] };
8
8
 
9
- export type GlueCodeComponentDataV2 = { name: string; libraryName: string };
9
+ export type GlueCodeComponentDataV2 = { name: string; libraryCppName: string };
10
10
 
11
11
  export type GlueCodeTurboModuleData = { name: string };
12
12
 
@@ -33,18 +33,21 @@ export type GlueCodeData = {
33
33
  * Generates code based on UberGenerators results. If UberGenerators produce "leaves" (concrete turbo module or component classes),
34
34
  * this class generates "branches" (barrel files like index.ts) and "trunks" (package file or files).
35
35
  */
36
- export class GlueCodeGenerator implements CodeGenerator<GlueCodeData> {
36
+ export class AppBuildTimeGlueCodeGenerator
37
+ implements CodeGenerator<GlueCodeData>
38
+ {
37
39
  constructor(
38
40
  private cppOutputPath: AbsolutePath,
39
- private etsOutputPath: AbsolutePath
41
+ private etsOutputPath: AbsolutePath,
42
+ private codegenNoticeLines: string[]
40
43
  ) {}
41
44
 
42
45
  generate({ v1, v2 }: GlueCodeData): Map<AbsolutePath, string> {
43
46
  const fileContentByPath = new Map<AbsolutePath, string>();
44
47
  const generatedPackageH_v1 = new RNOHGeneratedPackageHTemplate();
45
- const components_indexTS = new IndexTSTemplate();
46
- const turboModules_indexTS = new IndexTSTemplate();
47
- const generated_indexETS = new IndexTSTemplate();
48
+ const components_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
49
+ const turboModules_indexTS = new IndexTSTemplate(this.codegenNoticeLines);
50
+ const generated_indexETS = new IndexTSTemplate(this.codegenNoticeLines);
48
51
 
49
52
  generated_indexETS.addReexport({ from: './ts' });
50
53
  v1.components.forEach(({ name, eventNames }) => {
@@ -62,7 +65,8 @@ export class GlueCodeGenerator implements CodeGenerator<GlueCodeData> {
62
65
  v2.forEach(({ components, turboModules }, libraryName) => {
63
66
  const basePackageClassName = `Base${Case.pascal(libraryName)}Package`;
64
67
  const generatedPackageH_v2 = new BasePackageHTemplate(
65
- basePackageClassName
68
+ basePackageClassName,
69
+ this.codegenNoticeLines
66
70
  );
67
71
  components.forEach((component) => {
68
72
  generatedPackageH_v2.addComponent(component);
@@ -87,7 +91,7 @@ export class GlueCodeGenerator implements CodeGenerator<GlueCodeData> {
87
91
  );
88
92
  fileContentByPath.set(
89
93
  this.etsOutputPath.copyWithNewSegment('ts.ts'),
90
- new IndexTSTemplate()
94
+ new IndexTSTemplate(this.codegenNoticeLines)
91
95
  .addReexport({ from: './components/ts', as: 'RNC' })
92
96
  .addReexport({ from: './turboModules/ts', as: 'TM' })
93
97
  .build()