@react-native-oh/react-native-harmony-cli 0.77.18 → 0.77.33

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 (106) hide show
  1. package/dist/assetResolver.js +74 -43
  2. package/dist/autolinking/Autolinking.js +179 -178
  3. package/dist/codegen/core/CodegenError.js +23 -3
  4. package/dist/codegen/core/EventUtils.js +3 -3
  5. package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
  6. package/dist/codegen/core/UberSchema.js +97 -55
  7. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
  8. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
  10. package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
  11. package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
  12. package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
  13. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  14. package/dist/codegen/generators/UberGeneratorV1.js +24 -18
  15. package/dist/codegen/generators/UberGeneratorV2.js +36 -28
  16. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
  17. package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
  18. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -54
  19. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
  20. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
  21. package/dist/codegen/templates/IndexTSTemplate.js +17 -37
  22. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
  23. package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
  24. package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
  25. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
  26. package/dist/commands/bundle-harmony.js +221 -118
  27. package/dist/commands/clean-harmony.js +63 -58
  28. package/dist/commands/codegen-harmony.js +175 -104
  29. package/dist/commands/codegen-lib-harmony.js +116 -76
  30. package/dist/commands/init-harmony.js +196 -151
  31. package/dist/commands/init.js +961 -537
  32. package/dist/commands/link-harmony.js +82 -35
  33. package/dist/commands/run-harmony.js +520 -352
  34. package/dist/commands/verify-package-harmony.js +117 -54
  35. package/dist/core/AbsolutePath.js +49 -33
  36. package/dist/core/CodegenConfig.js +22 -24
  37. package/dist/core/DescriptiveError.js +37 -18
  38. package/dist/core/FileSystem.js +18 -14
  39. package/dist/core/OHPackageJSON5.js +23 -17
  40. package/dist/core/PackageJSON.js +42 -26
  41. package/dist/core/ProjectDependenciesManager.js +92 -40
  42. package/dist/core/ValidationError.js +22 -2
  43. package/dist/core/fs.js +7 -10
  44. package/dist/index.js +1 -1
  45. package/dist/init/templates/AppScopeAppJSON5Template.js +8 -21
  46. package/dist/init/templates/AppScopeStringVarTemplate.js +8 -19
  47. package/dist/init/templates/EntryIndexTemplate.js +8 -56
  48. package/dist/init/templates/EntryStringVarTemplate.js +8 -27
  49. package/dist/init/templates/HvigorConfigJson5Template.js +8 -33
  50. package/dist/init/templates/MetroConfigTemplate.js +8 -38
  51. package/dist/init/templates/OhPackageJson5Template.js +8 -28
  52. package/dist/io/CliExecutor.js +98 -46
  53. package/dist/io/Logger.js +46 -40
  54. package/dist/io/RealFS.js +100 -43
  55. package/dist/io/TarGz.js +8 -11
  56. package/dist/io/__fixtures__.js +141 -79
  57. package/dist/io/fsUtils.js +12 -13
  58. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
  59. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
  60. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
  61. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
  62. package/dist/package-verifier/verify-package.js +133 -56
  63. package/dist/simulator/LaunchSimulator.js +395 -0
  64. package/dist/simulator/index.js +23 -0
  65. package/package.json +2 -11
  66. package/scripts/sync-hvigor.js +27 -0
  67. package/src/autolinking/Autolinking.ts +1 -1
  68. package/src/codegen/generators/UberGeneratorV1.ts +7 -2
  69. package/src/codegen/generators/UberGeneratorV2.ts +6 -1
  70. package/src/commands/codegen-harmony.ts +17 -7
  71. package/src/commands/run-harmony.ts +67 -41
  72. package/src/init/templates/harmony/entry/src/main/module.json5 +7 -0
  73. package/src/simulator/LaunchSimulator.ts +359 -0
  74. package/src/simulator/index.ts +8 -0
  75. package/dist/init/templates/harmony/AppScope/app.json5 +0 -10
  76. package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +0 -8
  77. package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  78. package/dist/init/templates/harmony/build-profile.json5 +0 -36
  79. package/dist/init/templates/harmony/codelinter.json +0 -32
  80. package/dist/init/templates/harmony/entry/build-profile.json5 +0 -18
  81. package/dist/init/templates/harmony/entry/gitignore +0 -7
  82. package/dist/init/templates/harmony/entry/hvigorfile.ts +0 -13
  83. package/dist/init/templates/harmony/entry/oh-package.json5 +0 -9
  84. package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +0 -27
  85. package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +0 -13
  86. package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +0 -4
  87. package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +0 -8
  88. package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +0 -2
  89. package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +0 -11
  90. package/dist/init/templates/harmony/entry/src/main/ets/gitignore +0 -1
  91. package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
  92. package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +0 -16
  93. package/dist/init/templates/harmony/entry/src/main/module.json5 +0 -58
  94. package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +0 -8
  95. package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +0 -16
  96. package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
  97. package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  98. package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +0 -7
  99. package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  100. package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +0 -5
  101. package/dist/init/templates/harmony/entry/src/main/resources/gitignore +0 -1
  102. package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +0 -2
  103. package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +0 -13
  104. package/dist/init/templates/harmony/gitignore +0 -16
  105. package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +0 -22
  106. package/dist/init/templates/harmony/hvigorfile.ts +0 -7
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,18 +8,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
9
  });
33
10
  };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
36
37
  };
37
38
  Object.defineProperty(exports, "__esModule", { value: true });
38
39
  exports.commandCleanHarmony = void 0;
39
- const core_1 = require("../core");
40
- const json5_1 = __importDefault(require("json5"));
41
- const node_fs_1 = __importDefault(require("node:fs"));
42
- const node_path_1 = __importDefault(require("node:path"));
43
- const node_os_1 = __importDefault(require("node:os"));
44
- const crypto = __importStar(require("node:crypto"));
45
- const COMMAND_NAME = 'clean-harmony';
40
+ var core_1 = require("../core");
41
+ var json5_1 = require("json5");
42
+ var node_fs_1 = require("node:fs");
43
+ var node_path_1 = require("node:path");
44
+ var node_os_1 = require("node:os");
45
+ var crypto = require("node:crypto");
46
+ var COMMAND_NAME = 'clean-harmony';
46
47
  exports.commandCleanHarmony = {
47
48
  name: COMMAND_NAME,
48
49
  description: 'Remove cached files in the OpenHarmony project.',
@@ -53,32 +54,36 @@ exports.commandCleanHarmony = {
53
54
  default: "./harmony"
54
55
  }
55
56
  ],
56
- func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
57
- const harmonyProjectPath = new core_1.AbsolutePath(rawArgs.harmonyProjectPath);
58
- const md5Path = crypto.createHash("md5").update(harmonyProjectPath.getValue()).digest("hex");
59
- const hvigorCachePath = new core_1.AbsolutePath(node_path_1.default.join(node_os_1.default.homedir(), ".hvigor", "project_caches", md5Path));
60
- if (node_fs_1.default.existsSync(hvigorCachePath.getValue())) {
61
- node_fs_1.default.rmSync(hvigorCachePath.getValue(), { recursive: true, force: true });
62
- }
63
- const buildProfilePath = harmonyProjectPath.copyWithNewSegment('build-profile.json5');
64
- const buildProfileContent = (0, core_1.maybeReadFile)(buildProfilePath);
65
- if (buildProfileContent) {
66
- const buildProfile = json5_1.default.parse(buildProfileContent);
67
- if (Array.isArray(buildProfile.modules)) {
68
- buildProfile.modules.forEach((module) => {
69
- if (module && module.srcPath) {
70
- const modulePath = harmonyProjectPath.copyWithNewSegment(module.srcPath);
71
- const cxxPath = modulePath.copyWithNewSegment('.cxx');
72
- const buildPath = modulePath.copyWithNewSegment('build');
73
- if (node_fs_1.default.existsSync(cxxPath.getValue())) {
74
- node_fs_1.default.rmSync(cxxPath.getValue(), { recursive: true, force: true });
75
- }
76
- if (node_fs_1.default.existsSync(buildPath.getValue())) {
77
- node_fs_1.default.rmSync(buildPath.getValue(), { recursive: true, force: true });
57
+ func: function (_argv, _config, rawArgs) { return __awaiter(void 0, void 0, void 0, function () {
58
+ var harmonyProjectPath, md5Path, hvigorCachePath, buildProfilePath, buildProfileContent, buildProfile;
59
+ return __generator(this, function (_a) {
60
+ harmonyProjectPath = new core_1.AbsolutePath(rawArgs.harmonyProjectPath);
61
+ md5Path = crypto.createHash("md5").update(harmonyProjectPath.getValue()).digest("hex");
62
+ hvigorCachePath = new core_1.AbsolutePath(node_path_1.default.join(node_os_1.default.homedir(), ".hvigor", "project_caches", md5Path));
63
+ if (node_fs_1.default.existsSync(hvigorCachePath.getValue())) {
64
+ node_fs_1.default.rmSync(hvigorCachePath.getValue(), { recursive: true, force: true });
65
+ }
66
+ buildProfilePath = harmonyProjectPath.copyWithNewSegment('build-profile.json5');
67
+ buildProfileContent = (0, core_1.maybeReadFile)(buildProfilePath);
68
+ if (buildProfileContent) {
69
+ buildProfile = json5_1.default.parse(buildProfileContent);
70
+ if (Array.isArray(buildProfile.modules)) {
71
+ buildProfile.modules.forEach(function (module) {
72
+ if (module && module.srcPath) {
73
+ var modulePath = harmonyProjectPath.copyWithNewSegment(module.srcPath);
74
+ var cxxPath = modulePath.copyWithNewSegment('.cxx');
75
+ var buildPath = modulePath.copyWithNewSegment('build');
76
+ if (node_fs_1.default.existsSync(cxxPath.getValue())) {
77
+ node_fs_1.default.rmSync(cxxPath.getValue(), { recursive: true, force: true });
78
+ }
79
+ if (node_fs_1.default.existsSync(buildPath.getValue())) {
80
+ node_fs_1.default.rmSync(buildPath.getValue(), { recursive: true, force: true });
81
+ }
78
82
  }
79
- }
80
- });
83
+ });
84
+ }
81
85
  }
82
- }
83
- })
86
+ return [2 /*return*/];
87
+ });
88
+ }); }
84
89
  };
@@ -8,23 +8,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
13
46
  };
14
47
  Object.defineProperty(exports, "__esModule", { value: true });
15
48
  exports.commandCodegenHarmony = void 0;
16
- const node_path_1 = __importDefault(require("node:path"));
17
- const case_1 = __importDefault(require("case"));
18
- const core_1 = require("../core");
19
- const codegen_1 = require("../codegen");
20
- const io_1 = require("../io");
49
+ var node_path_1 = require("node:path");
50
+ var case_1 = require("case");
51
+ var core_1 = require("../core");
52
+ var codegen_1 = require("../codegen");
53
+ var io_1 = require("../io");
21
54
  exports.commandCodegenHarmony = {
22
55
  name: 'codegen-harmony',
23
56
  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.',
24
57
  options: [
25
58
  {
26
59
  name: '--rnoh-module-path <path>',
27
- description: 'Specifies the relative path to the rnoh OHOS module',
60
+ description: '[deprecated] Specifies the relative path to the rnoh OHOS module',
61
+ },
62
+ {
63
+ name: '--ets-output-path <path>',
64
+ description: 'Specifies the relative path to the output directory intended for storing generated ETS files.',
28
65
  },
29
66
  {
30
67
  name: '--cpp-output-path <path>',
@@ -46,109 +83,141 @@ exports.commandCodegenHarmony = {
46
83
  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.',
47
84
  },
48
85
  ],
49
- func: (_argv, _config, args) => __awaiter(void 0, void 0, void 0, function* () {
50
- const logger = new io_1.Logger();
51
- const fs = new io_1.RealFS();
52
- try {
53
- const MAX_SUPPORTED_CODEGEN_VERSION = 2;
54
- // prepare the input data
55
- validateArgs(args);
56
- const etsOutputPath = new core_1.AbsolutePath(args.rnohModulePath).copyWithNewSegment('generated');
57
- const enableSafetyCheck = args.safetyCheck;
58
- const cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
59
- const projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
60
- const uberSchemaFromArkTSLibraries = yield codegen_1.UberSchema.fromProject(fs, projectRootPath, (codegenVersion, packageName) => {
61
- throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
62
- return codegenVersion === 1;
63
- });
64
- const cApiLibrariesData = yield collectLibrariesData(fs, projectRootPath, (codegenVersion, packageName) => {
65
- throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
66
- return codegenVersion === 2;
67
- });
68
- // instantiate objects
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);
78
- // generate the code
79
- const fileContentByPath = new Map();
80
- const appendToFileContentByPath = (fileContent, path) => {
81
- fileContentByPath.set(path, fileContent);
82
- };
83
- uberGeneratorV1
84
- .generate(uberSchemaFromArkTSLibraries)
85
- .forEach(appendToFileContentByPath);
86
- uberGeneratorV2
87
- .generate(cApiLibrariesData)
88
- .forEach(appendToFileContentByPath);
89
- glueCodeGenerator
90
- .generate({
91
- v1: uberGeneratorV1.getGlueCodeData(),
92
- v2: uberGeneratorV2.getGlueCodeData(),
93
- })
94
- .forEach(appendToFileContentByPath);
95
- // output the results
96
- if (args.debug) {
97
- const uberSchema = yield codegen_1.UberSchema.fromProject(fs, projectRootPath);
98
- logger.debug((styles) => styles.gray(JSON.stringify(uberSchema.getValue(), null, 2)));
99
- }
100
- saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck);
101
- logCodegenResult(logger, fileContentByPath, projectRootPath);
102
- }
103
- catch (err) {
104
- if (err instanceof core_1.DescriptiveError) {
105
- logger.descriptiveError(err);
106
- process.exit(1);
86
+ func: function (_argv, _config, args) { return __awaiter(void 0, void 0, void 0, function () {
87
+ var logger, fs, MAX_SUPPORTED_CODEGEN_VERSION_1, etsOutputPath, isEndWithGenerated, enableSafetyCheck, cppOutputPath, projectRootPath, uberSchemaFromArkTSLibraries, cApiLibrariesData, codegenNoticeLines, uberGeneratorV1, uberGeneratorV2, glueCodeGenerator, fileContentByPath_1, appendToFileContentByPath, uberSchema_1, err_1;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ logger = new io_1.Logger();
92
+ fs = new io_1.RealFS();
93
+ _a.label = 1;
94
+ case 1:
95
+ _a.trys.push([1, 6, , 7]);
96
+ MAX_SUPPORTED_CODEGEN_VERSION_1 = 2;
97
+ // prepare the input data
98
+ validateArgs(args);
99
+ etsOutputPath = args.etsOutputPath || args.rnohModulePath;
100
+ isEndWithGenerated = /\/generated\/?$/.test(etsOutputPath);
101
+ etsOutputPath = new core_1.AbsolutePath(etsOutputPath);
102
+ if (!isEndWithGenerated) {
103
+ etsOutputPath = etsOutputPath.copyWithNewSegment('generated');
104
+ }
105
+ enableSafetyCheck = args.safetyCheck;
106
+ cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
107
+ projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
108
+ return [4 /*yield*/, codegen_1.UberSchema.fromProject(fs, projectRootPath, function (codegenVersion, packageName) {
109
+ throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION_1, packageName);
110
+ return codegenVersion === 1;
111
+ })];
112
+ case 2:
113
+ uberSchemaFromArkTSLibraries = _a.sent();
114
+ return [4 /*yield*/, collectLibrariesData(fs, projectRootPath, function (codegenVersion, packageName) {
115
+ throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION_1, packageName);
116
+ return codegenVersion === 2;
117
+ })];
118
+ case 3:
119
+ cApiLibrariesData = _a.sent();
120
+ codegenNoticeLines = [
121
+ 'This code was generated by "react-native codegen-harmony"',
122
+ '',
123
+ 'Do not edit this file as changes may cause incorrect behavior and will be',
124
+ 'lost once the code is regenerated.',
125
+ ];
126
+ uberGeneratorV1 = new codegen_1.UberGeneratorV1(cppOutputPath, etsOutputPath, __spreadArray(__spreadArray([], codegenNoticeLines, true), ['', '@generatorVersion: 1'], false));
127
+ uberGeneratorV2 = new codegen_1.UberGeneratorV2(cppOutputPath, etsOutputPath, __spreadArray(__spreadArray([], codegenNoticeLines, true), ['', '@generatorVersion: 2'], false));
128
+ glueCodeGenerator = new codegen_1.AppBuildTimeGlueCodeGenerator(cppOutputPath, etsOutputPath, codegenNoticeLines);
129
+ fileContentByPath_1 = new Map();
130
+ appendToFileContentByPath = function (fileContent, path) {
131
+ fileContentByPath_1.set(path, fileContent);
132
+ };
133
+ uberGeneratorV1
134
+ .generate(uberSchemaFromArkTSLibraries)
135
+ .forEach(appendToFileContentByPath);
136
+ uberGeneratorV2
137
+ .generate(cApiLibrariesData)
138
+ .forEach(appendToFileContentByPath);
139
+ glueCodeGenerator
140
+ .generate({
141
+ v1: uberGeneratorV1.getGlueCodeData(),
142
+ v2: uberGeneratorV2.getGlueCodeData(),
143
+ })
144
+ .forEach(appendToFileContentByPath);
145
+ if (!args.debug) return [3 /*break*/, 5];
146
+ return [4 /*yield*/, codegen_1.UberSchema.fromProject(fs, projectRootPath)];
147
+ case 4:
148
+ uberSchema_1 = _a.sent();
149
+ logger.debug(function (styles) {
150
+ return styles.gray(JSON.stringify(uberSchema_1.getValue(), null, 2));
151
+ });
152
+ _a.label = 5;
153
+ case 5:
154
+ saveCodegenResult(fs, fileContentByPath_1, cppOutputPath, etsOutputPath, enableSafetyCheck);
155
+ logCodegenResult(logger, fileContentByPath_1, projectRootPath);
156
+ return [3 /*break*/, 7];
157
+ case 6:
158
+ err_1 = _a.sent();
159
+ if (err_1 instanceof core_1.DescriptiveError) {
160
+ logger.descriptiveError(err_1);
161
+ process.exit(1);
162
+ }
163
+ throw err_1;
164
+ case 7: return [2 /*return*/];
107
165
  }
108
- throw err;
109
- }
110
- }),
166
+ });
167
+ }); },
111
168
  };
112
169
  function validateArgs(args) {
113
- if (!args.rnohModulePath) {
170
+ if (!args.rnohModulePath && !args.etsOutputPath) {
114
171
  throw new core_1.DescriptiveError({
115
- whatHappened: "--rnoh-module-path argument wasn't provided",
172
+ whatHappened: '--ets-output-path is required',
116
173
  whatCanUserDo: [
117
- 'Please provide a path to the native React Native for Open Harmony module (rnoh) which is probably located somewhere in "<PROJECT_ROOT>/harmony" directory',
174
+ 'Please provide an output path for the ETS file.',
175
+ 'It is recommended to place it in the same directory as the custom component or TurboModule.',
176
+ 'Do not place it inside @rnoh/react-native-openharmony, otherwise a jscrash may occur when using react_native_openharmony_release2.har.'
118
177
  ],
119
178
  });
120
179
  }
121
180
  }
122
181
  function collectLibrariesData(fs, projectRootPath, onShouldAcceptCodegenConfig) {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- const packageJSONs = [
125
- core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath),
126
- ];
127
- yield new core_1.ProjectDependenciesManager(fs, projectRootPath).forEachAsync((dependency) => {
128
- packageJSONs.push(dependency.readPackageJSON());
129
- });
130
- const results = [];
131
- for (const packageJSON of packageJSONs) {
132
- const codegenConfigs = packageJSON.getCodegenConfigs();
133
- for (const codegenConfig of codegenConfigs) {
134
- if (codegenConfig &&
135
- onShouldAcceptCodegenConfig(codegenConfig.getVersion(), packageJSON.name)) {
136
- results.push({
137
- libraryCppName: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
138
- uberSchema: codegen_1.UberSchema.fromCodegenConfig(codegenConfig),
139
- });
140
- }
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ var packageJSONs, results, _i, packageJSONs_1, packageJSON, codegenConfigs, _a, codegenConfigs_1, codegenConfig;
184
+ return __generator(this, function (_b) {
185
+ switch (_b.label) {
186
+ case 0:
187
+ packageJSONs = [
188
+ core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath),
189
+ ];
190
+ return [4 /*yield*/, new core_1.ProjectDependenciesManager(fs, projectRootPath).forEachAsync(function (dependency) {
191
+ packageJSONs.push(dependency.readPackageJSON());
192
+ })];
193
+ case 1:
194
+ _b.sent();
195
+ results = [];
196
+ for (_i = 0, packageJSONs_1 = packageJSONs; _i < packageJSONs_1.length; _i++) {
197
+ packageJSON = packageJSONs_1[_i];
198
+ codegenConfigs = packageJSON.getCodegenConfigs();
199
+ for (_a = 0, codegenConfigs_1 = codegenConfigs; _a < codegenConfigs_1.length; _a++) {
200
+ codegenConfig = codegenConfigs_1[_a];
201
+ if (codegenConfig &&
202
+ onShouldAcceptCodegenConfig(codegenConfig.getVersion(), packageJSON.name)) {
203
+ results.push({
204
+ libraryCppName: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
205
+ uberSchema: codegen_1.UberSchema.fromCodegenConfig(codegenConfig),
206
+ });
207
+ }
208
+ }
209
+ }
210
+ return [2 /*return*/, results];
141
211
  }
142
- }
143
- return results;
212
+ });
144
213
  });
145
214
  }
146
215
  function throwErrorIfUnsupportedCodegenVersion(codegenVersion, maxSupportedCodegenVersion, packageName) {
147
216
  if (codegenVersion > maxSupportedCodegenVersion) {
148
217
  throw new codegen_1.CodegenError({
149
- whatHappened: `Package "${packageName}" requires codegenVersion: ${codegenVersion}, which is not supported (maxSupportedCodegenVersion=${maxSupportedCodegenVersion}).`,
218
+ whatHappened: "Package \"".concat(packageName, "\" requires codegenVersion: ").concat(codegenVersion, ", which is not supported (maxSupportedCodegenVersion=").concat(maxSupportedCodegenVersion, ")."),
150
219
  whatCanUserDo: [
151
- `Try downgrading "${packageName}".`,
220
+ "Try downgrading \"".concat(packageName, "\"."),
152
221
  'Update the "@react-native-oh/react-native-harmony-cli" package.',
153
222
  ],
154
223
  });
@@ -159,10 +228,10 @@ function saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath,
159
228
  prepareDirectory(etsOutputPath, enableSafetyCheck);
160
229
  prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
161
230
  prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
162
- fileContentByPath.forEach((_fileContent, path) => {
231
+ fileContentByPath.forEach(function (_fileContent, path) {
163
232
  prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
164
233
  });
165
- fileContentByPath.forEach((fileContent, path) => {
234
+ fileContentByPath.forEach(function (fileContent, path) {
166
235
  fs.writeTextSync(path, fileContent);
167
236
  });
168
237
  }
@@ -170,24 +239,26 @@ function prepareDirectory(path, enableSafetyCheck) {
170
239
  (0, core_1.maybeMakeDirectories)(path);
171
240
  if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
172
241
  throw new core_1.DescriptiveError({
173
- whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
242
+ whatHappened: "Tried to remove files in ".concat(path.getValue(), "\nand that path is outside current working directory"),
174
243
  whatCanUserDo: ['Run codegen from different location'],
175
244
  });
176
245
  }
177
246
  (0, core_1.maybeRemoveFilesInDirectory)(path);
178
247
  }
179
248
  function logCodegenResult(logger, fileContentByPath, projectRootPath) {
180
- const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => node_path_1.default.relative(projectRootPath.getValue(), path.getValue()));
249
+ var sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map(function (path) { return node_path_1.default.relative(projectRootPath.getValue(), path.getValue()); });
181
250
  sortedRelativePathStrings.sort();
182
- sortedRelativePathStrings.forEach((pathStr) => {
183
- logger.debug((styles) => styles.gray(`• ${pathStr}`));
251
+ sortedRelativePathStrings.forEach(function (pathStr) {
252
+ logger.debug(function (styles) { return styles.gray("\u2022 ".concat(pathStr)); });
253
+ });
254
+ logger.debug(function () { return ''; });
255
+ logger.info(function (styles) {
256
+ return "Generated ".concat(styles.green(styles.bold(fileContentByPath.size)), " file(s)");
184
257
  });
185
- logger.debug(() => '');
186
- logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`);
187
- logger.debug(() => '');
258
+ logger.debug(function () { return ''; });
188
259
  }
189
260
  function deriveCppDirectoryNameFromNpmPackageName(npmPackageName) {
190
- let result = npmPackageName;
261
+ var result = npmPackageName;
191
262
  if (npmPackageName.includes('/')) {
192
263
  result.replace('@', '');
193
264
  result = npmPackageName.replace('/', '__');