@react-native-oh/react-native-harmony-cli 0.0.37 → 0.0.40

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 (138) hide show
  1. package/README.md +11 -11
  2. package/dist/assetResolver.js +74 -43
  3. package/dist/autolinking/Autolinking.js +183 -179
  4. package/dist/codegen/core/CodegenError.js +23 -3
  5. package/dist/codegen/core/EventUtils.js +3 -3
  6. package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
  7. package/dist/codegen/core/UberSchema.js +96 -57
  8. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
  11. package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
  12. package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
  13. package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
  14. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  15. package/dist/codegen/generators/UberGeneratorV1.js +24 -18
  16. package/dist/codegen/generators/UberGeneratorV2.js +36 -28
  17. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
  18. package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
  19. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
  20. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
  21. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
  22. package/dist/codegen/templates/IndexTSTemplate.js +17 -37
  23. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
  24. package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
  25. package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
  26. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
  27. package/dist/commands/bundle-harmony.js +138 -53
  28. package/dist/commands/codegen-harmony.js +175 -104
  29. package/dist/commands/codegen-lib-harmony.js +116 -76
  30. package/dist/commands/create-metro-host-constants.js +47 -18
  31. package/dist/commands/init.js +961 -537
  32. package/dist/commands/link-harmony.js +71 -33
  33. package/dist/commands/pack-harmony.js +108 -47
  34. package/dist/commands/run-harmony.js +518 -374
  35. package/dist/commands/unpack-harmony.js +198 -105
  36. package/dist/commands/verify-package-harmony.js +108 -54
  37. package/dist/core/AbsolutePath.js +47 -31
  38. package/dist/core/CodegenConfig.js +22 -24
  39. package/dist/core/DescriptiveError.js +37 -18
  40. package/dist/core/FileSystem.js +18 -14
  41. package/dist/core/OHPackageJSON5.js +23 -17
  42. package/dist/core/PackageJSON.js +42 -26
  43. package/dist/core/ProjectDependenciesManager.js +96 -46
  44. package/dist/core/ValidationError.js +22 -2
  45. package/dist/core/fs.js +6 -9
  46. package/dist/index.js +1 -1
  47. package/dist/io/CliExecutor.js +98 -46
  48. package/dist/io/Logger.js +46 -40
  49. package/dist/io/RealFS.js +88 -35
  50. package/dist/io/TarGz.js +8 -11
  51. package/dist/io/__fixtures__.js +141 -79
  52. package/dist/io/fsUtils.js +12 -13
  53. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
  54. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
  55. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
  56. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
  57. package/dist/package-verifier/verify-package.js +132 -55
  58. package/dist/simulator/LaunchSimulator.js +301 -217
  59. package/jest.config.js +12 -12
  60. package/package.json +78 -70
  61. package/react-native.config.js +17 -17
  62. package/tsconfig.build.json +6 -6
  63. package/tsconfig.json +2 -2
  64. package/.prettierrc +0 -6
  65. package/src/assetResolver.ts +0 -134
  66. package/src/autolinking/Autolinking.test.ts +0 -483
  67. package/src/autolinking/Autolinking.ts +0 -382
  68. package/src/autolinking/index.ts +0 -8
  69. package/src/codegen/core/CodeGenerator.ts +0 -16
  70. package/src/codegen/core/CodegenError.ts +0 -10
  71. package/src/codegen/core/EventUtils.ts +0 -23
  72. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  73. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  74. package/src/codegen/core/UberSchema.ts +0 -152
  75. package/src/codegen/core/index.ts +0 -12
  76. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -124
  77. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  78. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  79. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  80. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  81. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  82. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  83. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  84. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  85. package/src/codegen/generators/index.ts +0 -15
  86. package/src/codegen/index.ts +0 -9
  87. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  88. package/src/codegen/templates/BasePackageHTemplate.ts +0 -159
  89. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  90. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  91. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  92. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  93. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -150
  94. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  95. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  96. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  97. package/src/codegen/templates/index.ts +0 -16
  98. package/src/commands/bundle-harmony.ts +0 -134
  99. package/src/commands/codegen-harmony.ts +0 -297
  100. package/src/commands/codegen-lib-harmony.ts +0 -389
  101. package/src/commands/create-metro-host-constants.ts +0 -55
  102. package/src/commands/index.ts +0 -16
  103. package/src/commands/init.ts +0 -755
  104. package/src/commands/link-harmony.ts +0 -102
  105. package/src/commands/pack-harmony.ts +0 -128
  106. package/src/commands/run-harmony.ts +0 -506
  107. package/src/commands/types.ts +0 -21
  108. package/src/commands/unpack-harmony.ts +0 -238
  109. package/src/commands/verify-package-harmony.ts +0 -113
  110. package/src/core/AbsolutePath.ts +0 -66
  111. package/src/core/CodegenConfig.ts +0 -67
  112. package/src/core/DescriptiveError.ts +0 -68
  113. package/src/core/FileSystem.ts +0 -57
  114. package/src/core/OHPackageJSON5.ts +0 -30
  115. package/src/core/PackageJSON.ts +0 -104
  116. package/src/core/ProjectDependenciesManager.ts +0 -103
  117. package/src/core/ValidationError.ts +0 -8
  118. package/src/core/ValueObject.ts +0 -9
  119. package/src/core/fs.ts +0 -38
  120. package/src/core/index.ts +0 -17
  121. package/src/index.ts +0 -33
  122. package/src/io/CliExecutor.ts +0 -69
  123. package/src/io/Logger.ts +0 -112
  124. package/src/io/RealFS.ts +0 -62
  125. package/src/io/TarGz.ts +0 -33
  126. package/src/io/__fixtures__.ts +0 -139
  127. package/src/io/fsUtils.ts +0 -44
  128. package/src/io/index.ts +0 -11
  129. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  130. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  131. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  132. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  133. package/src/package-verifier/checks/index.ts +0 -11
  134. package/src/package-verifier/index.ts +0 -9
  135. package/src/package-verifier/types.ts +0 -19
  136. package/src/package-verifier/verify-package.ts +0 -123
  137. package/src/simulator/LaunchSimulator.ts +0 -352
  138. package/src/simulator/index.ts +0 -8
@@ -5,43 +5,45 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE-MIT file in the root directory of this source tree.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.LibGlueCodeGenerator = void 0;
13
- const case_1 = __importDefault(require("case"));
14
- const BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
15
- const templates_1 = require("../templates");
10
+ var case_1 = require("case");
11
+ var BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
12
+ var templates_1 = require("../templates");
16
13
  /**
17
14
  * NOTE: This class is coupled with the generated code structure defined in the codegen-harmony-lib.
18
15
  */
19
- class LibGlueCodeGenerator {
20
- constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
16
+ var LibGlueCodeGenerator = /** @class */ (function () {
17
+ function LibGlueCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines) {
21
18
  this.cppOutputPath = cppOutputPath;
22
19
  this.etsOutputPath = etsOutputPath;
23
20
  this.codegenNoticeLines = codegenNoticeLines;
24
21
  }
25
- generate({ libraryCppName, turboModules, arkTSComponents, cppComponents, }) {
26
- const fileContentByPath = new Map();
27
- const basePackageClassName = `Base${case_1.default.pascal(libraryCppName)}Package`;
28
- const turboModules_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
29
- const components_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
30
- const generated_indexETS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
31
- const basePackageTemplate = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
32
- turboModules.forEach((turboModule) => {
22
+ LibGlueCodeGenerator.prototype.generate = function (_a) {
23
+ var libraryCppName = _a.libraryCppName, turboModules = _a.turboModules, arkTSComponents = _a.arkTSComponents, cppComponents = _a.cppComponents;
24
+ var fileContentByPath = new Map();
25
+ var basePackageClassName = "Base".concat(case_1.default.pascal(libraryCppName), "Package");
26
+ var turboModules_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
27
+ var components_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
28
+ var generated_indexETS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
29
+ var basePackageTemplate = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
30
+ turboModules.forEach(function (turboModule) {
33
31
  basePackageTemplate.addTurboModule(turboModule);
34
- turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
32
+ turboModules_indexTS.addReexport({ from: "./".concat(turboModule.name) });
35
33
  });
36
- arkTSComponents.forEach(({ componentName, eventNames }) => {
37
- components_indexTS.addReexport({ from: `./${componentName}` });
38
- basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: true });
39
- eventNames.forEach((eventName) => basePackageTemplate.addArkTSEvent({ name: eventName }));
34
+ arkTSComponents.forEach(function (_a) {
35
+ var componentName = _a.componentName, eventNames = _a.eventNames;
36
+ components_indexTS.addReexport({ from: "./".concat(componentName) });
37
+ basePackageTemplate.addComponent({ name: componentName, libraryCppName: libraryCppName, isArkTSComponent: true });
38
+ eventNames.forEach(function (eventName) {
39
+ return basePackageTemplate.addArkTSEvent({ name: eventName });
40
+ });
40
41
  });
41
- cppComponents.forEach(({ componentName }) => {
42
- basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: false });
42
+ cppComponents.forEach(function (_a) {
43
+ var componentName = _a.componentName;
44
+ basePackageTemplate.addComponent({ name: componentName, libraryCppName: libraryCppName, isArkTSComponent: false });
43
45
  });
44
- fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', `${basePackageClassName}.h`), basePackageTemplate.build());
46
+ fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', "".concat(basePackageClassName, ".h")), basePackageTemplate.build());
45
47
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
46
48
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
47
49
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate(this.codegenNoticeLines)
@@ -51,6 +53,7 @@ class LibGlueCodeGenerator {
51
53
  generated_indexETS.addReexport({ from: './ts' });
52
54
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
53
55
  return fileContentByPath;
54
- }
55
- }
56
+ };
57
+ return LibGlueCodeGenerator;
58
+ }());
56
59
  exports.LibGlueCodeGenerator = LibGlueCodeGenerator;
@@ -7,53 +7,55 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.NativeModuleCodeGenerator = void 0;
10
- const templates_1 = require("../templates");
11
- const core_1 = require("../core");
10
+ var templates_1 = require("../templates");
11
+ var core_1 = require("../core");
12
12
  /**
13
13
  * Generates boilerplate code for Turbo Modules.
14
14
  */
15
- class NativeModuleCodeGenerator {
16
- constructor(cppOutputPath, etsOutputPath, codegenNoticeLines, rnohImport) {
15
+ var NativeModuleCodeGenerator = /** @class */ (function () {
16
+ function NativeModuleCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines, rnohImport) {
17
17
  this.cppOutputPath = cppOutputPath;
18
18
  this.etsOutputPath = etsOutputPath;
19
19
  this.codegenNoticeLines = codegenNoticeLines;
20
20
  this.rnohImport = rnohImport;
21
21
  this.glueCodeTurboModulesData = [];
22
22
  }
23
- getGlueCodeData() {
23
+ NativeModuleCodeGenerator.prototype.getGlueCodeData = function () {
24
24
  return this.glueCodeTurboModulesData;
25
- }
26
- generate(schema) {
27
- const result = new Map();
25
+ };
26
+ NativeModuleCodeGenerator.prototype.generate = function (schema) {
27
+ var result = new Map();
28
28
  if (schema.type !== 'NativeModule') {
29
29
  throw new core_1.CodegenError({
30
- whatHappened: `NativeModuleCodeGenerator can't generate code for module type: ${schema.type}`,
30
+ whatHappened: "NativeModuleCodeGenerator can't generate code for module type: ".concat(schema.type),
31
31
  unexpected: true,
32
32
  });
33
33
  }
34
- const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
35
- const turboModuleInterfaceTS = new templates_1.TurboModuleInterfaceTS(schema.moduleName, this.codegenNoticeLines, this.rnohImport);
36
- const turboModuleH = new templates_1.TurboModuleHTemplate(schema.moduleName, this.codegenNoticeLines).build();
37
- result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`), turboModuleH);
38
- const turboModuleCpp = new templates_1.TurboModuleCppTemplate(schema.moduleName, this.codegenNoticeLines);
39
- Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
34
+ var typeAnnotationToTS = new core_1.TypeAnnotationToTS();
35
+ var turboModuleInterfaceTS = new templates_1.TurboModuleInterfaceTS(schema.moduleName, this.codegenNoticeLines, this.rnohImport);
36
+ var turboModuleH = new templates_1.TurboModuleHTemplate(schema.moduleName, this.codegenNoticeLines).build();
37
+ result.set(this.cppOutputPath.copyWithNewSegment("".concat(schema.moduleName, ".h")), turboModuleH);
38
+ var turboModuleCpp = new templates_1.TurboModuleCppTemplate(schema.moduleName, this.codegenNoticeLines);
39
+ Object.entries(schema.aliasMap).map(function (_a) {
40
+ var name = _a[0], typeAnnotation = _a[1];
40
41
  turboModuleInterfaceTS.addAlias({
41
42
  name: name,
42
43
  type: typeAnnotationToTS.convert(typeAnnotation),
43
44
  });
44
45
  });
45
- Object.entries(schema.enumMap).map(([name, enumSpec]) => {
46
+ Object.entries(schema.enumMap).map(function (_a) {
47
+ var name = _a[0], enumSpec = _a[1];
46
48
  turboModuleInterfaceTS.addEnum({
47
- name,
48
- members: enumSpec.members.map((member) => ({
49
+ name: name,
50
+ members: enumSpec.members.map(function (member) { return ({
49
51
  name: member.name,
50
52
  value: typeof member.value === 'string'
51
53
  ? (0, core_1.wrapWithQuotes)(member.value)
52
54
  : member.value.toString(),
53
- })),
55
+ }); }),
54
56
  });
55
57
  });
56
- schema.spec.properties.map((prop) => {
58
+ schema.spec.properties.map(function (prop) {
57
59
  if (prop.typeAnnotation.type === 'FunctionTypeAnnotation') {
58
60
  turboModuleCpp.addMethod({
59
61
  name: prop.name,
@@ -65,15 +67,18 @@ class NativeModuleCodeGenerator {
65
67
  name: prop.name,
66
68
  returnType: typeAnnotationToTS.convert(prop.typeAnnotation.returnTypeAnnotation),
67
69
  stringifiedArgs: prop.typeAnnotation.params
68
- .map((param) => `${param.name}: ${typeAnnotationToTS.convert(param.typeAnnotation)}`)
70
+ .map(function (param) {
71
+ return "".concat(param.name, ": ").concat(typeAnnotationToTS.convert(param.typeAnnotation));
72
+ })
69
73
  .join(', '),
70
74
  });
71
75
  }
72
76
  });
73
- result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.cpp`), turboModuleCpp.build());
74
- result.set(this.etsOutputPath.copyWithNewSegment(`${schema.moduleName}.ts`), turboModuleInterfaceTS.build());
77
+ result.set(this.cppOutputPath.copyWithNewSegment("".concat(schema.moduleName, ".cpp")), turboModuleCpp.build());
78
+ result.set(this.etsOutputPath.copyWithNewSegment("".concat(schema.moduleName, ".ts")), turboModuleInterfaceTS.build());
75
79
  this.glueCodeTurboModulesData.push({ name: schema.moduleName });
76
80
  return result;
77
- }
78
- }
81
+ };
82
+ return NativeModuleCodeGenerator;
83
+ }());
79
84
  exports.NativeModuleCodeGenerator = NativeModuleCodeGenerator;
@@ -5,19 +5,18 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE-MIT file in the root directory of this source tree.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.SharedComponentCodeGenerator = void 0;
13
- const RNCodegen_1 = __importDefault(require("@react-native/codegen/lib/generators/RNCodegen"));
14
- class SharedComponentCodeGenerator {
15
- constructor(onGetSharedOutputPath) {
10
+ var RNCodegen_1 = require("@react-native/codegen/lib/generators/RNCodegen");
11
+ var SharedComponentCodeGenerator = /** @class */ (function () {
12
+ function SharedComponentCodeGenerator(onGetSharedOutputPath) {
16
13
  this.onGetSharedOutputPath = onGetSharedOutputPath;
17
14
  }
18
- generate({ libraryCppName, uberSchema, }) {
19
- const fileContentByPath = new Map();
20
- const generatorFns = [
15
+ SharedComponentCodeGenerator.prototype.generate = function (_a) {
16
+ var _this = this;
17
+ var libraryCppName = _a.libraryCppName, uberSchema = _a.uberSchema;
18
+ var fileContentByPath = new Map();
19
+ var generatorFns = [
21
20
  RNCodegen_1.default.allGenerators.generatePropsH,
22
21
  RNCodegen_1.default.allGenerators.generatePropsCpp,
23
22
  RNCodegen_1.default.allGenerators.generateEventEmitterH,
@@ -28,13 +27,14 @@ class SharedComponentCodeGenerator {
28
27
  RNCodegen_1.default.allGenerators.generateShadowNodeH,
29
28
  RNCodegen_1.default.allGenerators.generateShadowNodeCpp,
30
29
  ];
31
- generatorFns.forEach((generate) => {
32
- const filesOutput = generate(libraryCppName, uberSchema.getValue(), 'UNUSED_packageName', true);
33
- filesOutput.forEach((fileContent, filename) => {
34
- fileContentByPath.set(this.onGetSharedOutputPath(filename), fileContent);
30
+ generatorFns.forEach(function (generate) {
31
+ var filesOutput = generate(libraryCppName, uberSchema.getValue(), 'UNUSED_packageName', true);
32
+ filesOutput.forEach(function (fileContent, filename) {
33
+ fileContentByPath.set(_this.onGetSharedOutputPath(filename), fileContent);
35
34
  });
36
35
  });
37
36
  return fileContentByPath;
38
- }
39
- }
37
+ };
38
+ return SharedComponentCodeGenerator;
39
+ }());
40
40
  exports.SharedComponentCodeGenerator = SharedComponentCodeGenerator;
@@ -7,42 +7,47 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.UberGeneratorV1 = void 0;
10
- const core_1 = require("../core");
11
- const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
12
- const ArkTSComponentCodeGeneratorArkTS_1 = require("./ArkTSComponentCodeGeneratorArkTS");
10
+ var path_1 = require("path");
11
+ var core_1 = require("../core");
12
+ var NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
13
+ var ArkTSComponentCodeGeneratorArkTS_1 = require("./ArkTSComponentCodeGeneratorArkTS");
14
+ // The name of rnoh OHOS module
15
+ var RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
13
16
  /**
14
17
  * Generates code for libraries built on top of RNOH's ArkTS architecture.
15
18
  */
16
- class UberGeneratorV1 {
17
- constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
19
+ var UberGeneratorV1 = /** @class */ (function () {
20
+ function UberGeneratorV1(cppOutputPath, etsOutputPath, codegenNoticeLines) {
18
21
  this.cppOutputPath = cppOutputPath;
19
22
  this.etsOutputPath = etsOutputPath;
20
23
  this.codegenNoticeLines = codegenNoticeLines;
21
24
  this.glueCodeData = { components: [], turboModules: [] };
22
25
  }
23
- getGlueCodeData() {
26
+ UberGeneratorV1.prototype.getGlueCodeData = function () {
24
27
  return this.glueCodeData;
25
- }
26
- generate(uberSchema) {
27
- const fileContentByPath = new Map();
28
- const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS_1.ArkTSComponentCodeGeneratorArkTS(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('components'), this.codegenNoticeLines, '../../ts');
29
- const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, '../../ts');
30
- const generatorBySpecType = {
28
+ };
29
+ UberGeneratorV1.prototype.generate = function (uberSchema) {
30
+ var fileContentByPath = new Map();
31
+ var isRNOHModulePath = this.etsOutputPath.getValue().endsWith("".concat(RNOH_OHOS_NAME, "/generated").replace(/\//g, path_1.default.sep));
32
+ var componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS_1.ArkTSComponentCodeGeneratorArkTS(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('components'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : "".concat(RNOH_OHOS_NAME, "/ts"));
33
+ var nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : "".concat(RNOH_OHOS_NAME, "/ts"));
34
+ var generatorBySpecType = {
31
35
  Component: componentCodeGenerator,
32
36
  NativeModule: nativeModuleCodeGenerator,
33
37
  };
34
- for (const [_fileName, specSchema] of uberSchema
38
+ for (var _i = 0, _a = uberSchema
35
39
  .getSpecSchemaByFilenameMap()
36
- .entries()) {
40
+ .entries(); _i < _a.length; _i++) {
41
+ var _b = _a[_i], _fileName = _b[0], specSchema = _b[1];
37
42
  if (!(specSchema.type in generatorBySpecType)) {
38
43
  throw new core_1.CodegenError({
39
- whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
44
+ whatHappened: "Could not find a code generator for a specification of type '".concat(specSchema.type, "'"),
40
45
  unexpected: true,
41
46
  });
42
47
  }
43
48
  generatorBySpecType[specSchema.type]
44
49
  .generate(specSchema)
45
- .forEach((fileContent, filePath) => {
50
+ .forEach(function (fileContent, filePath) {
46
51
  fileContentByPath.set(filePath, fileContent);
47
52
  });
48
53
  }
@@ -51,6 +56,7 @@ class UberGeneratorV1 {
51
56
  turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
52
57
  };
53
58
  return fileContentByPath;
54
- }
55
- }
59
+ };
60
+ return UberGeneratorV1;
61
+ }());
56
62
  exports.UberGeneratorV1 = UberGeneratorV1;
@@ -7,71 +7,79 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.UberGeneratorV2 = void 0;
10
- const CppComponentCodeGenerator_1 = require("./CppComponentCodeGenerator");
11
- const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
12
- const SharedComponentCodeGenerator_1 = require("./SharedComponentCodeGenerator");
10
+ var path_1 = require("path");
11
+ var CppComponentCodeGenerator_1 = require("./CppComponentCodeGenerator");
12
+ var NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
13
+ var SharedComponentCodeGenerator_1 = require("./SharedComponentCodeGenerator");
14
+ // The name of rnoh OHOS module
15
+ var RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
13
16
  /**
14
17
  * Generates code for libraries built on top of RNOH's C-API architecture.
15
18
  */
16
- class UberGeneratorV2 {
17
- constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
19
+ var UberGeneratorV2 = /** @class */ (function () {
20
+ function UberGeneratorV2(cppOutputPath, etsOutputPath, codegenNoticeLines) {
18
21
  this.cppOutputPath = cppOutputPath;
19
22
  this.etsOutputPath = etsOutputPath;
20
23
  this.codegenNoticeLines = codegenNoticeLines;
21
24
  this.glueCodeData = new Map();
22
25
  }
23
- getGlueCodeData() {
26
+ UberGeneratorV2.prototype.getGlueCodeData = function () {
24
27
  return this.glueCodeData;
25
- }
26
- generate(npmPackagesInfo) {
27
- const fileContentByPath = new Map();
28
- npmPackagesInfo.forEach(({ libraryCppName, uberSchema }) => {
29
- this.glueCodeData.set(libraryCppName, {
28
+ };
29
+ UberGeneratorV2.prototype.generate = function (npmPackagesInfo) {
30
+ var _this = this;
31
+ var fileContentByPath = new Map();
32
+ npmPackagesInfo.forEach(function (_a) {
33
+ var libraryCppName = _a.libraryCppName, uberSchema = _a.uberSchema;
34
+ _this.glueCodeData.set(libraryCppName, {
30
35
  components: [],
31
36
  turboModules: [],
32
37
  });
33
- const libraryGlueCodeData = this.glueCodeData.get(libraryCppName);
34
- const libraryCppOutput = this.cppOutputPath.copyWithNewSegment(libraryCppName);
35
- const sharedComponentCodeGenerator = new SharedComponentCodeGenerator_1.SharedComponentCodeGenerator((filename) => {
38
+ var libraryGlueCodeData = _this.glueCodeData.get(libraryCppName);
39
+ var libraryCppOutput = _this.cppOutputPath.copyWithNewSegment(libraryCppName);
40
+ var sharedComponentCodeGenerator = new SharedComponentCodeGenerator_1.SharedComponentCodeGenerator(function (filename) {
36
41
  return libraryCppOutput.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
37
42
  });
38
- const cppComponentCodeGenerator = new CppComponentCodeGenerator_1.CppComponentCodeGenerator((filename) => {
43
+ var cppComponentCodeGenerator = new CppComponentCodeGenerator_1.CppComponentCodeGenerator(function (filename) {
39
44
  return libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'components', filename);
40
- }, this.codegenNoticeLines);
45
+ }, _this.codegenNoticeLines);
41
46
  cppComponentCodeGenerator
42
- .generate({ libraryCppName, uberSchema })
43
- .forEach((fileContent, path) => {
47
+ .generate({ libraryCppName: libraryCppName, uberSchema: uberSchema })
48
+ .forEach(function (fileContent, path) {
44
49
  fileContentByPath.set(path, fileContent);
45
50
  });
46
51
  cppComponentCodeGenerator
47
52
  .getGlueCodeData()
48
- .forEach((componentGlueCodeData) => {
53
+ .forEach(function (componentGlueCodeData) {
49
54
  libraryGlueCodeData.components.push(componentGlueCodeData);
50
55
  });
51
56
  sharedComponentCodeGenerator
52
- .generate({ libraryCppName, uberSchema })
53
- .forEach((fileContent, path) => {
57
+ .generate({ libraryCppName: libraryCppName, uberSchema: uberSchema })
58
+ .forEach(function (fileContent, path) {
54
59
  fileContentByPath.set(path, fileContent);
55
60
  });
56
- for (const [_fileName, specSchema] of uberSchema
61
+ for (var _i = 0, _b = uberSchema
57
62
  .getSpecSchemaByFilenameMap()
58
- .entries()) {
63
+ .entries(); _i < _b.length; _i++) {
64
+ var _c = _b[_i], _fileName = _c[0], specSchema = _c[1];
59
65
  if (specSchema.type === 'NativeModule') {
60
- const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, '../../ts');
66
+ var isRNOHModulePath = _this.etsOutputPath.getValue().endsWith("".concat(RNOH_OHOS_NAME, "/generated").replace(/\//g, path_1.default.sep));
67
+ var nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), _this.etsOutputPath.copyWithNewSegment('turboModules'), _this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : "".concat(RNOH_OHOS_NAME, "/ts"));
61
68
  nativeModuleCodeGenerator
62
69
  .generate(specSchema)
63
- .forEach((fileContent, filePath) => {
70
+ .forEach(function (fileContent, filePath) {
64
71
  fileContentByPath.set(filePath, fileContent);
65
72
  });
66
73
  nativeModuleCodeGenerator
67
74
  .getGlueCodeData()
68
- .forEach((turboModuleGlueCodeData) => {
75
+ .forEach(function (turboModuleGlueCodeData) {
69
76
  libraryGlueCodeData.turboModules.push(turboModuleGlueCodeData);
70
77
  });
71
78
  }
72
79
  }
73
80
  });
74
81
  return fileContentByPath;
75
- }
76
- }
82
+ };
83
+ return UberGeneratorV2;
84
+ }());
77
85
  exports.UberGeneratorV2 = UberGeneratorV2;
@@ -5,77 +5,51 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE-MIT file in the root directory of this source tree.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.BaseComponentInstanceHTemplate = void 0;
13
- const mustache_1 = __importDefault(require("mustache"));
14
- const case_1 = __importDefault(require("case"));
15
- const TEMPLATE = `
16
- /**
17
- {{#codegenNoticeLines}}
18
- * {{{line}}}
19
- {{/codegenNoticeLines}}
20
- */
21
-
22
- #pragma once
23
-
24
- #include "RNOH/CppComponentInstance.h"
25
- #include <react/renderer/components/{{libraryName}}/ShadowNodes.h>
26
-
27
- namespace rnoh {
28
- class Base{{name}}ComponentInstance
29
- : public CppComponentInstance<facebook::react::{{name}}ShadowNode> {
30
- public:
31
- using CppComponentInstance::CppComponentInstance;
32
-
33
- void handleCommand(std::string const &commandName, folly::dynamic const &args) override {
34
- {{#commands}}
35
- if (commandName == "{{commandName}}") {
36
- this->on{{CommandName}}Command({{argsFromDynamic}});
37
- }
38
- {{/commands}}
39
- }
40
-
41
- {{#commands}}
42
- virtual void on{{CommandName}}Command({{argsDeclaration}}) = 0;
43
- {{/commands}}
44
- };
45
- } // namespace rnoh
46
- `;
47
- class BaseComponentInstanceHTemplate {
48
- constructor(componentName, libraryName, codegenNoticeLines) {
10
+ var mustache_1 = require("mustache");
11
+ var case_1 = require("case");
12
+ var TEMPLATE = "\n/**\n{{#codegenNoticeLines}}\n * {{{line}}}\n{{/codegenNoticeLines}}\n */\n\n#pragma once\n\n#include \"RNOH/CppComponentInstance.h\"\n#include <react/renderer/components/{{libraryName}}/ShadowNodes.h>\n\nnamespace rnoh {\n class Base{{name}}ComponentInstance\n : public CppComponentInstance<facebook::react::{{name}}ShadowNode> {\n public:\n using CppComponentInstance::CppComponentInstance;\n\n void handleCommand(std::string const &commandName, folly::dynamic const &args) override {\n {{#commands}}\n if (commandName == \"{{commandName}}\") {\n this->on{{CommandName}}Command({{argsFromDynamic}});\n }\n {{/commands}}\n }\n \n {{#commands}}\n virtual void on{{CommandName}}Command({{argsDeclaration}}) = 0;\n {{/commands}}\n };\n} // namespace rnoh\n";
13
+ var BaseComponentInstanceHTemplate = /** @class */ (function () {
14
+ function BaseComponentInstanceHTemplate(componentName, libraryName, codegenNoticeLines) {
49
15
  this.componentName = componentName;
50
16
  this.libraryName = libraryName;
51
17
  this.codegenNoticeLines = codegenNoticeLines;
52
18
  this.commands = [];
53
19
  }
54
- addCommand(command) {
20
+ BaseComponentInstanceHTemplate.prototype.addCommand = function (command) {
55
21
  this.commands.push(command);
56
- }
57
- build() {
22
+ };
23
+ BaseComponentInstanceHTemplate.prototype.build = function () {
58
24
  return mustache_1.default.render(TEMPLATE, {
59
- codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
60
- line,
61
- })),
25
+ codegenNoticeLines: this.codegenNoticeLines.map(function (line) { return ({
26
+ line: line,
27
+ }); }),
62
28
  name: this.componentName,
63
29
  libraryName: this.libraryName,
64
- commands: this.commands.map(({ name, args }) => {
30
+ commands: this.commands.map(function (_a) {
31
+ var name = _a.name, args = _a.args;
65
32
  return {
66
33
  commandName: name,
67
34
  CommandName: case_1.default.pascal(name),
68
35
  argsDeclaration: args
69
- .map(({ name, typeAnnotation }) => `${cppTypeFromTypeAnnotation(typeAnnotation)} ${name}`)
36
+ .map(function (_a) {
37
+ var name = _a.name, typeAnnotation = _a.typeAnnotation;
38
+ return "".concat(cppTypeFromTypeAnnotation(typeAnnotation), " ").concat(name);
39
+ })
70
40
  .join(', '),
71
41
  argsFromDynamic: args
72
- .map(({ typeAnnotation }, index) => `args[${index}]${dynamicExtractorFromTypeAnnotation(typeAnnotation)}`)
42
+ .map(function (_a, index) {
43
+ var typeAnnotation = _a.typeAnnotation;
44
+ return "args[".concat(index, "]").concat(dynamicExtractorFromTypeAnnotation(typeAnnotation));
45
+ })
73
46
  .join(', '),
74
47
  };
75
48
  }),
76
49
  });
77
- }
78
- }
50
+ };
51
+ return BaseComponentInstanceHTemplate;
52
+ }());
79
53
  exports.BaseComponentInstanceHTemplate = BaseComponentInstanceHTemplate;
80
54
  function cppTypeFromTypeAnnotation(typeAnnotation) {
81
55
  switch (typeAnnotation.type) {