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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +11 -11
  2. package/dist/assetResolver.js +43 -74
  3. package/dist/autolinking/Autolinking.js +178 -179
  4. package/dist/codegen/core/CodegenError.js +3 -23
  5. package/dist/codegen/core/EventUtils.js +3 -3
  6. package/dist/codegen/core/TypeAnnotationToTS.js +24 -28
  7. package/dist/codegen/core/UberSchema.js +57 -96
  8. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +28 -41
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +27 -34
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +25 -33
  11. package/dist/codegen/generators/CppComponentCodeGenerator.js +23 -28
  12. package/dist/codegen/generators/LibGlueCodeGenerator.js +26 -29
  13. package/dist/codegen/generators/NativeModuleCodeGenerator.js +25 -30
  14. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  15. package/dist/codegen/generators/UberGeneratorV1.js +24 -23
  16. package/dist/codegen/generators/UberGeneratorV2.js +34 -35
  17. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +50 -24
  18. package/dist/codegen/templates/BasePackageHTemplate.js +120 -21
  19. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +53 -8
  20. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +75 -27
  21. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +162 -29
  22. package/dist/codegen/templates/IndexTSTemplate.js +37 -17
  23. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +119 -24
  24. package/dist/codegen/templates/TurboModuleCppTemplate.js +38 -15
  25. package/dist/codegen/templates/TurboModuleHTemplate.js +32 -11
  26. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +52 -19
  27. package/dist/commands/bundle-harmony.js +53 -138
  28. package/dist/commands/codegen-harmony.js +105 -165
  29. package/dist/commands/codegen-lib-harmony.js +76 -116
  30. package/dist/commands/create-metro-host-constants.js +18 -47
  31. package/dist/commands/init.js +537 -961
  32. package/dist/commands/link-harmony.js +33 -71
  33. package/dist/commands/pack-harmony.js +47 -108
  34. package/dist/commands/run-harmony.js +372 -518
  35. package/dist/commands/unpack-harmony.js +105 -198
  36. package/dist/commands/verify-package-harmony.js +54 -108
  37. package/dist/core/AbsolutePath.js +31 -47
  38. package/dist/core/CodegenConfig.js +24 -22
  39. package/dist/core/DescriptiveError.js +18 -37
  40. package/dist/core/FileSystem.js +14 -18
  41. package/dist/core/OHPackageJSON5.js +17 -23
  42. package/dist/core/PackageJSON.js +26 -42
  43. package/dist/core/ProjectDependenciesManager.js +40 -92
  44. package/dist/core/ValidationError.js +2 -22
  45. package/dist/core/fs.js +9 -6
  46. package/dist/index.js +1 -1
  47. package/dist/io/CliExecutor.js +46 -98
  48. package/dist/io/Logger.js +40 -46
  49. package/dist/io/RealFS.js +35 -88
  50. package/dist/io/TarGz.js +11 -8
  51. package/dist/io/__fixtures__.js +79 -141
  52. package/dist/io/fsUtils.js +13 -12
  53. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +19 -47
  54. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +13 -41
  55. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +8 -38
  56. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +22 -54
  57. package/dist/package-verifier/verify-package.js +55 -132
  58. package/dist/simulator/LaunchSimulator.js +224 -301
  59. package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
  60. package/jest.config.js +12 -12
  61. package/package.json +78 -78
  62. package/react-native.config.js +17 -17
  63. package/tsconfig.build.json +6 -6
  64. package/tsconfig.json +2 -2
@@ -5,45 +5,43 @@
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
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.LibGlueCodeGenerator = void 0;
10
- var case_1 = require("case");
11
- var BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
12
- var templates_1 = require("../templates");
13
+ const case_1 = __importDefault(require("case"));
14
+ const BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
15
+ const templates_1 = require("../templates");
13
16
  /**
14
17
  * NOTE: This class is coupled with the generated code structure defined in the codegen-harmony-lib.
15
18
  */
16
- var LibGlueCodeGenerator = /** @class */ (function () {
17
- function LibGlueCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines) {
19
+ class LibGlueCodeGenerator {
20
+ constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
18
21
  this.cppOutputPath = cppOutputPath;
19
22
  this.etsOutputPath = etsOutputPath;
20
23
  this.codegenNoticeLines = codegenNoticeLines;
21
24
  }
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) {
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) => {
31
33
  basePackageTemplate.addTurboModule(turboModule);
32
- turboModules_indexTS.addReexport({ from: "./".concat(turboModule.name) });
34
+ turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
33
35
  });
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
- });
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 }));
41
40
  });
42
- cppComponents.forEach(function (_a) {
43
- var componentName = _a.componentName;
44
- basePackageTemplate.addComponent({ name: componentName, libraryCppName: libraryCppName, isArkTSComponent: false });
41
+ cppComponents.forEach(({ componentName }) => {
42
+ basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: false });
45
43
  });
46
- fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', "".concat(basePackageClassName, ".h")), basePackageTemplate.build());
44
+ fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', `${basePackageClassName}.h`), basePackageTemplate.build());
47
45
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
48
46
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
49
47
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate(this.codegenNoticeLines)
@@ -53,7 +51,6 @@ var LibGlueCodeGenerator = /** @class */ (function () {
53
51
  generated_indexETS.addReexport({ from: './ts' });
54
52
  fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
55
53
  return fileContentByPath;
56
- };
57
- return LibGlueCodeGenerator;
58
- }());
54
+ }
55
+ }
59
56
  exports.LibGlueCodeGenerator = LibGlueCodeGenerator;
@@ -7,55 +7,53 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.NativeModuleCodeGenerator = void 0;
10
- var templates_1 = require("../templates");
11
- var core_1 = require("../core");
10
+ const templates_1 = require("../templates");
11
+ const core_1 = require("../core");
12
12
  /**
13
13
  * Generates boilerplate code for Turbo Modules.
14
14
  */
15
- var NativeModuleCodeGenerator = /** @class */ (function () {
16
- function NativeModuleCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines, rnohImport) {
15
+ class NativeModuleCodeGenerator {
16
+ constructor(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
- NativeModuleCodeGenerator.prototype.getGlueCodeData = function () {
23
+ getGlueCodeData() {
24
24
  return this.glueCodeTurboModulesData;
25
- };
26
- NativeModuleCodeGenerator.prototype.generate = function (schema) {
27
- var result = new Map();
25
+ }
26
+ generate(schema) {
27
+ const 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: ".concat(schema.type),
30
+ whatHappened: `NativeModuleCodeGenerator can't generate code for module type: ${schema.type}`,
31
31
  unexpected: true,
32
32
  });
33
33
  }
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];
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]) => {
41
40
  turboModuleInterfaceTS.addAlias({
42
41
  name: name,
43
42
  type: typeAnnotationToTS.convert(typeAnnotation),
44
43
  });
45
44
  });
46
- Object.entries(schema.enumMap).map(function (_a) {
47
- var name = _a[0], enumSpec = _a[1];
45
+ Object.entries(schema.enumMap).map(([name, enumSpec]) => {
48
46
  turboModuleInterfaceTS.addEnum({
49
- name: name,
50
- members: enumSpec.members.map(function (member) { return ({
47
+ name,
48
+ members: enumSpec.members.map((member) => ({
51
49
  name: member.name,
52
50
  value: typeof member.value === 'string'
53
51
  ? (0, core_1.wrapWithQuotes)(member.value)
54
52
  : member.value.toString(),
55
- }); }),
53
+ })),
56
54
  });
57
55
  });
58
- schema.spec.properties.map(function (prop) {
56
+ schema.spec.properties.map((prop) => {
59
57
  if (prop.typeAnnotation.type === 'FunctionTypeAnnotation') {
60
58
  turboModuleCpp.addMethod({
61
59
  name: prop.name,
@@ -67,18 +65,15 @@ var NativeModuleCodeGenerator = /** @class */ (function () {
67
65
  name: prop.name,
68
66
  returnType: typeAnnotationToTS.convert(prop.typeAnnotation.returnTypeAnnotation),
69
67
  stringifiedArgs: prop.typeAnnotation.params
70
- .map(function (param) {
71
- return "".concat(param.name, ": ").concat(typeAnnotationToTS.convert(param.typeAnnotation));
72
- })
68
+ .map((param) => `${param.name}: ${typeAnnotationToTS.convert(param.typeAnnotation)}`)
73
69
  .join(', '),
74
70
  });
75
71
  }
76
72
  });
77
- result.set(this.cppOutputPath.copyWithNewSegment("".concat(schema.moduleName, ".cpp")), turboModuleCpp.build());
78
- result.set(this.etsOutputPath.copyWithNewSegment("".concat(schema.moduleName, ".ts")), turboModuleInterfaceTS.build());
73
+ result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.cpp`), turboModuleCpp.build());
74
+ result.set(this.etsOutputPath.copyWithNewSegment(`${schema.moduleName}.ts`), turboModuleInterfaceTS.build());
79
75
  this.glueCodeTurboModulesData.push({ name: schema.moduleName });
80
76
  return result;
81
- };
82
- return NativeModuleCodeGenerator;
83
- }());
77
+ }
78
+ }
84
79
  exports.NativeModuleCodeGenerator = NativeModuleCodeGenerator;
@@ -5,18 +5,19 @@
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
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.SharedComponentCodeGenerator = void 0;
10
- var RNCodegen_1 = require("@react-native/codegen/lib/generators/RNCodegen");
11
- var SharedComponentCodeGenerator = /** @class */ (function () {
12
- function SharedComponentCodeGenerator(onGetSharedOutputPath) {
13
+ const RNCodegen_1 = __importDefault(require("@react-native/codegen/lib/generators/RNCodegen"));
14
+ class SharedComponentCodeGenerator {
15
+ constructor(onGetSharedOutputPath) {
13
16
  this.onGetSharedOutputPath = onGetSharedOutputPath;
14
17
  }
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 = [
18
+ generate({ libraryCppName, uberSchema, }) {
19
+ const fileContentByPath = new Map();
20
+ const generatorFns = [
20
21
  RNCodegen_1.default.allGenerators.generatePropsH,
21
22
  RNCodegen_1.default.allGenerators.generatePropsCpp,
22
23
  RNCodegen_1.default.allGenerators.generateEventEmitterH,
@@ -27,14 +28,13 @@ var SharedComponentCodeGenerator = /** @class */ (function () {
27
28
  RNCodegen_1.default.allGenerators.generateShadowNodeH,
28
29
  RNCodegen_1.default.allGenerators.generateShadowNodeCpp,
29
30
  ];
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);
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);
34
35
  });
35
36
  });
36
37
  return fileContentByPath;
37
- };
38
- return SharedComponentCodeGenerator;
39
- }());
38
+ }
39
+ }
40
40
  exports.SharedComponentCodeGenerator = SharedComponentCodeGenerator;
@@ -5,49 +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
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.UberGeneratorV1 = void 0;
10
- var path_1 = require("path");
11
- var core_1 = require("../core");
12
- var NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
13
- var ArkTSComponentCodeGeneratorArkTS_1 = require("./ArkTSComponentCodeGeneratorArkTS");
13
+ const path_1 = __importDefault(require("path"));
14
+ const core_1 = require("../core");
15
+ const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
16
+ const ArkTSComponentCodeGeneratorArkTS_1 = require("./ArkTSComponentCodeGeneratorArkTS");
14
17
  // The name of rnoh OHOS module
15
- var RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
18
+ const RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
16
19
  /**
17
20
  * Generates code for libraries built on top of RNOH's ArkTS architecture.
18
21
  */
19
- var UberGeneratorV1 = /** @class */ (function () {
20
- function UberGeneratorV1(cppOutputPath, etsOutputPath, codegenNoticeLines) {
22
+ class UberGeneratorV1 {
23
+ constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
21
24
  this.cppOutputPath = cppOutputPath;
22
25
  this.etsOutputPath = etsOutputPath;
23
26
  this.codegenNoticeLines = codegenNoticeLines;
24
27
  this.glueCodeData = { components: [], turboModules: [] };
25
28
  }
26
- UberGeneratorV1.prototype.getGlueCodeData = function () {
29
+ getGlueCodeData() {
27
30
  return this.glueCodeData;
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
+ }
32
+ generate(uberSchema) {
33
+ const fileContentByPath = new Map();
34
+ const isRNOHModulePath = this.etsOutputPath.getValue().endsWith(`${RNOH_OHOS_NAME}/generated`.replace(/\//g, path_1.default.sep));
35
+ const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS_1.ArkTSComponentCodeGeneratorArkTS(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('components'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
36
+ const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
37
+ const generatorBySpecType = {
35
38
  Component: componentCodeGenerator,
36
39
  NativeModule: nativeModuleCodeGenerator,
37
40
  };
38
- for (var _i = 0, _a = uberSchema
41
+ for (const [_fileName, specSchema] of uberSchema
39
42
  .getSpecSchemaByFilenameMap()
40
- .entries(); _i < _a.length; _i++) {
41
- var _b = _a[_i], _fileName = _b[0], specSchema = _b[1];
43
+ .entries()) {
42
44
  if (!(specSchema.type in generatorBySpecType)) {
43
45
  throw new core_1.CodegenError({
44
- whatHappened: "Could not find a code generator for a specification of type '".concat(specSchema.type, "'"),
46
+ whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
45
47
  unexpected: true,
46
48
  });
47
49
  }
48
50
  generatorBySpecType[specSchema.type]
49
51
  .generate(specSchema)
50
- .forEach(function (fileContent, filePath) {
52
+ .forEach((fileContent, filePath) => {
51
53
  fileContentByPath.set(filePath, fileContent);
52
54
  });
53
55
  }
@@ -56,7 +58,6 @@ var UberGeneratorV1 = /** @class */ (function () {
56
58
  turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
57
59
  };
58
60
  return fileContentByPath;
59
- };
60
- return UberGeneratorV1;
61
- }());
61
+ }
62
+ }
62
63
  exports.UberGeneratorV1 = UberGeneratorV1;
@@ -5,81 +5,80 @@
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
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.UberGeneratorV2 = void 0;
10
- var path_1 = require("path");
11
- var CppComponentCodeGenerator_1 = require("./CppComponentCodeGenerator");
12
- var NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
13
- var SharedComponentCodeGenerator_1 = require("./SharedComponentCodeGenerator");
13
+ const path_1 = __importDefault(require("path"));
14
+ const CppComponentCodeGenerator_1 = require("./CppComponentCodeGenerator");
15
+ const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
16
+ const SharedComponentCodeGenerator_1 = require("./SharedComponentCodeGenerator");
14
17
  // The name of rnoh OHOS module
15
- var RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
18
+ const RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
16
19
  /**
17
20
  * Generates code for libraries built on top of RNOH's C-API architecture.
18
21
  */
19
- var UberGeneratorV2 = /** @class */ (function () {
20
- function UberGeneratorV2(cppOutputPath, etsOutputPath, codegenNoticeLines) {
22
+ class UberGeneratorV2 {
23
+ constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
21
24
  this.cppOutputPath = cppOutputPath;
22
25
  this.etsOutputPath = etsOutputPath;
23
26
  this.codegenNoticeLines = codegenNoticeLines;
24
27
  this.glueCodeData = new Map();
25
28
  }
26
- UberGeneratorV2.prototype.getGlueCodeData = function () {
29
+ getGlueCodeData() {
27
30
  return this.glueCodeData;
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, {
31
+ }
32
+ generate(npmPackagesInfo) {
33
+ const fileContentByPath = new Map();
34
+ npmPackagesInfo.forEach(({ libraryCppName, uberSchema }) => {
35
+ this.glueCodeData.set(libraryCppName, {
35
36
  components: [],
36
37
  turboModules: [],
37
38
  });
38
- var libraryGlueCodeData = _this.glueCodeData.get(libraryCppName);
39
- var libraryCppOutput = _this.cppOutputPath.copyWithNewSegment(libraryCppName);
40
- var sharedComponentCodeGenerator = new SharedComponentCodeGenerator_1.SharedComponentCodeGenerator(function (filename) {
39
+ const libraryGlueCodeData = this.glueCodeData.get(libraryCppName);
40
+ const libraryCppOutput = this.cppOutputPath.copyWithNewSegment(libraryCppName);
41
+ const sharedComponentCodeGenerator = new SharedComponentCodeGenerator_1.SharedComponentCodeGenerator((filename) => {
41
42
  return libraryCppOutput.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
42
43
  });
43
- var cppComponentCodeGenerator = new CppComponentCodeGenerator_1.CppComponentCodeGenerator(function (filename) {
44
+ const cppComponentCodeGenerator = new CppComponentCodeGenerator_1.CppComponentCodeGenerator((filename) => {
44
45
  return libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'components', filename);
45
- }, _this.codegenNoticeLines);
46
+ }, this.codegenNoticeLines);
46
47
  cppComponentCodeGenerator
47
- .generate({ libraryCppName: libraryCppName, uberSchema: uberSchema })
48
- .forEach(function (fileContent, path) {
48
+ .generate({ libraryCppName, uberSchema })
49
+ .forEach((fileContent, path) => {
49
50
  fileContentByPath.set(path, fileContent);
50
51
  });
51
52
  cppComponentCodeGenerator
52
53
  .getGlueCodeData()
53
- .forEach(function (componentGlueCodeData) {
54
+ .forEach((componentGlueCodeData) => {
54
55
  libraryGlueCodeData.components.push(componentGlueCodeData);
55
56
  });
56
57
  sharedComponentCodeGenerator
57
- .generate({ libraryCppName: libraryCppName, uberSchema: uberSchema })
58
- .forEach(function (fileContent, path) {
58
+ .generate({ libraryCppName, uberSchema })
59
+ .forEach((fileContent, path) => {
59
60
  fileContentByPath.set(path, fileContent);
60
61
  });
61
- for (var _i = 0, _b = uberSchema
62
+ for (const [_fileName, specSchema] of uberSchema
62
63
  .getSpecSchemaByFilenameMap()
63
- .entries(); _i < _b.length; _i++) {
64
- var _c = _b[_i], _fileName = _c[0], specSchema = _c[1];
64
+ .entries()) {
65
65
  if (specSchema.type === 'NativeModule') {
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"));
66
+ const isRNOHModulePath = this.etsOutputPath.getValue().endsWith(`${RNOH_OHOS_NAME}/generated`.replace(/\//g, path_1.default.sep));
67
+ const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
68
68
  nativeModuleCodeGenerator
69
69
  .generate(specSchema)
70
- .forEach(function (fileContent, filePath) {
70
+ .forEach((fileContent, filePath) => {
71
71
  fileContentByPath.set(filePath, fileContent);
72
72
  });
73
73
  nativeModuleCodeGenerator
74
74
  .getGlueCodeData()
75
- .forEach(function (turboModuleGlueCodeData) {
75
+ .forEach((turboModuleGlueCodeData) => {
76
76
  libraryGlueCodeData.turboModules.push(turboModuleGlueCodeData);
77
77
  });
78
78
  }
79
79
  }
80
80
  });
81
81
  return fileContentByPath;
82
- };
83
- return UberGeneratorV2;
84
- }());
82
+ }
83
+ }
85
84
  exports.UberGeneratorV2 = UberGeneratorV2;
@@ -5,51 +5,77 @@
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
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.BaseComponentInstanceHTemplate = void 0;
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) {
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) {
15
49
  this.componentName = componentName;
16
50
  this.libraryName = libraryName;
17
51
  this.codegenNoticeLines = codegenNoticeLines;
18
52
  this.commands = [];
19
53
  }
20
- BaseComponentInstanceHTemplate.prototype.addCommand = function (command) {
54
+ addCommand(command) {
21
55
  this.commands.push(command);
22
- };
23
- BaseComponentInstanceHTemplate.prototype.build = function () {
56
+ }
57
+ build() {
24
58
  return mustache_1.default.render(TEMPLATE, {
25
- codegenNoticeLines: this.codegenNoticeLines.map(function (line) { return ({
26
- line: line,
27
- }); }),
59
+ codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
60
+ line,
61
+ })),
28
62
  name: this.componentName,
29
63
  libraryName: this.libraryName,
30
- commands: this.commands.map(function (_a) {
31
- var name = _a.name, args = _a.args;
64
+ commands: this.commands.map(({ name, args }) => {
32
65
  return {
33
66
  commandName: name,
34
67
  CommandName: case_1.default.pascal(name),
35
68
  argsDeclaration: args
36
- .map(function (_a) {
37
- var name = _a.name, typeAnnotation = _a.typeAnnotation;
38
- return "".concat(cppTypeFromTypeAnnotation(typeAnnotation), " ").concat(name);
39
- })
69
+ .map(({ name, typeAnnotation }) => `${cppTypeFromTypeAnnotation(typeAnnotation)} ${name}`)
40
70
  .join(', '),
41
71
  argsFromDynamic: args
42
- .map(function (_a, index) {
43
- var typeAnnotation = _a.typeAnnotation;
44
- return "args[".concat(index, "]").concat(dynamicExtractorFromTypeAnnotation(typeAnnotation));
45
- })
72
+ .map(({ typeAnnotation }, index) => `args[${index}]${dynamicExtractorFromTypeAnnotation(typeAnnotation)}`)
46
73
  .join(', '),
47
74
  };
48
75
  }),
49
76
  });
50
- };
51
- return BaseComponentInstanceHTemplate;
52
- }());
77
+ }
78
+ }
53
79
  exports.BaseComponentInstanceHTemplate = BaseComponentInstanceHTemplate;
54
80
  function cppTypeFromTypeAnnotation(typeAnnotation) {
55
81
  switch (typeAnnotation.type) {