@react-native-oh/react-native-harmony-cli 0.0.16 → 0.0.23

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 (77) hide show
  1. package/dist/codegen/core/Codegen.js +35 -0
  2. package/dist/codegen/core/CodegenError.js +7 -0
  3. package/dist/codegen/core/EventUtils.js +19 -0
  4. package/dist/codegen/core/TypeAnnotationToTS.js +132 -0
  5. package/dist/codegen/core/UberSchema.js +74 -0
  6. package/dist/codegen/core/index.js +21 -0
  7. package/dist/codegen/generators/ComponentCodeGenerator.js +66 -0
  8. package/dist/codegen/generators/NativeModuleCodeGenerator.js +64 -0
  9. package/dist/codegen/generators/PackageCodeGenerator.js +52 -0
  10. package/dist/codegen/generators/index.js +19 -0
  11. package/dist/codegen/index.js +18 -0
  12. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +55 -0
  13. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +78 -0
  14. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +181 -0
  15. package/dist/codegen/templates/IndexTSTemplate.js +31 -0
  16. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +117 -0
  17. package/dist/codegen/templates/TurboModuleCppTemplate.js +45 -0
  18. package/dist/codegen/templates/TurboModuleHTemplate.js +32 -0
  19. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +64 -0
  20. package/dist/codegen/templates/index.js +24 -0
  21. package/dist/commands/codegen-harmony.js +110 -0
  22. package/dist/commands/create-metro-host-constants.js +61 -0
  23. package/dist/commands/index.js +2 -0
  24. package/dist/commands/pack-harmony.js +4 -1
  25. package/dist/commands/unpack-harmony.js +86 -43
  26. package/dist/core/AbsolutePath.js +41 -0
  27. package/dist/core/CodegenConfig.js +53 -0
  28. package/dist/core/DescriptiveError.js +49 -0
  29. package/dist/core/PackageJSON.js +53 -0
  30. package/dist/core/ProjectDependenciesManager.js +70 -0
  31. package/dist/core/ValueObject.js +2 -0
  32. package/dist/core/fs.js +36 -0
  33. package/dist/core/index.js +7 -0
  34. package/dist/index.js +7 -1
  35. package/dist/io/Logger.js +71 -0
  36. package/dist/io/fsUtils.js +23 -0
  37. package/dist/io/index.js +18 -0
  38. package/package.json +6 -1
  39. package/src/codegen/core/Codegen.ts +44 -0
  40. package/src/codegen/core/CodegenError.ts +3 -0
  41. package/src/codegen/core/EventUtils.ts +18 -0
  42. package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -0
  43. package/src/codegen/core/TypeAnnotationToTS.ts +188 -0
  44. package/src/codegen/core/UberSchema.ts +99 -0
  45. package/src/codegen/core/index.ts +5 -0
  46. package/src/codegen/generators/ComponentCodeGenerator.ts +98 -0
  47. package/src/codegen/generators/NativeModuleCodeGenerator.ts +95 -0
  48. package/src/codegen/generators/PackageCodeGenerator.ts +73 -0
  49. package/src/codegen/generators/index.ts +3 -0
  50. package/src/codegen/index.ts +2 -0
  51. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +49 -0
  52. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +85 -0
  53. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +202 -0
  54. package/src/codegen/templates/IndexTSTemplate.ts +33 -0
  55. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +124 -0
  56. package/src/codegen/templates/TurboModuleCppTemplate.ts +47 -0
  57. package/src/codegen/templates/TurboModuleHTemplate.ts +26 -0
  58. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +81 -0
  59. package/src/codegen/templates/index.ts +8 -0
  60. package/src/commands/codegen-harmony.ts +143 -0
  61. package/src/commands/create-metro-host-constants.ts +48 -0
  62. package/src/commands/index.ts +2 -0
  63. package/src/commands/pack-harmony.ts +4 -1
  64. package/src/commands/unpack-harmony.ts +133 -58
  65. package/src/core/AbsolutePath.ts +43 -0
  66. package/src/core/CodegenConfig.ts +54 -0
  67. package/src/core/DescriptiveError.ts +61 -0
  68. package/src/core/PackageJSON.ts +63 -0
  69. package/src/core/ProjectDependenciesManager.ts +77 -0
  70. package/src/core/ValueObject.ts +2 -0
  71. package/src/core/fs.ts +31 -0
  72. package/src/core/index.ts +7 -0
  73. package/src/index.ts +9 -1
  74. package/src/io/Logger.ts +68 -0
  75. package/src/io/fsUtils.ts +24 -0
  76. package/src/io/index.ts +2 -0
  77. package/tsconfig.build.json +2 -1
@@ -55,6 +55,9 @@ exports.commandPackHarmony = {
55
55
  function pack(harmonyDirPath, ohModuleDirPath, packageJSONPath) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  syncVersions(packageJSONPath, path_1.default.join(ohModuleDirPath, 'oh-package.json5'));
58
+ if (!fs_1.default.existsSync(harmonyDirPath)) {
59
+ fs_1.default.mkdirSync(harmonyDirPath, { recursive: true });
60
+ }
58
61
  yield createTGZFromDir(ohModuleDirPath, path_1.default.join(harmonyDirPath, `${path_1.default.parse(ohModuleDirPath).name}.tar.gz`));
59
62
  yield createTGZFromDir(harmonyDirPath, path_1.default.join(path_1.default.dirname(harmonyDirPath), 'harmony.tar.gz'));
60
63
  });
@@ -64,7 +67,7 @@ function syncVersions(packageJSONFilePath, ohPackageJSONFilePath) {
64
67
  if (fs_1.default.existsSync(ohPackageJSONFilePath)) {
65
68
  const ohPackageJSONFileContent = json5_1.default.parse(fs_1.default.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' }));
66
69
  ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
67
- fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent));
70
+ fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent, null, 2));
68
71
  }
69
72
  }
70
73
  function createTGZFromDir(dirPath, outputFilePath) {
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.commandUnpackHarmony = void 0;
16
+ const io_1 = require("../io");
16
17
  const path_1 = __importDefault(require("path"));
17
18
  const fs_1 = __importDefault(require("fs"));
18
19
  const zlib_1 = __importDefault(require("zlib"));
@@ -21,22 +22,22 @@ const json5_1 = __importDefault(require("json5"));
21
22
  const core_1 = require("../core");
22
23
  exports.commandUnpackHarmony = {
23
24
  name: 'unpack-harmony',
24
- description: 'Pack native code. Used for package development.',
25
+ description: 'Unpacks native code.',
25
26
  options: [
26
27
  {
27
- name: '--node-modules-path <string>',
28
- description: 'Path to node_modules directory',
29
- default: './node_modules',
28
+ name: '--project-root-path <path>',
29
+ description: 'Relative path to package root',
30
+ default: '.',
30
31
  },
31
32
  {
32
33
  name: '--output-dir <string>',
33
34
  description: 'Output directory to which OH modules should be unpacked to',
34
- default: './harmony/react_native_modules',
35
+ default: './harmony/rnoh_modules',
35
36
  },
36
37
  ],
37
38
  func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
38
39
  try {
39
- yield unpack(path_1.default.resolve(args.nodeModulesPath), path_1.default.resolve(args.outputDir));
40
+ yield unpack(new core_1.AbsolutePath(args.projectRootPath), new core_1.AbsolutePath(args.outputDir));
40
41
  }
41
42
  catch (err) {
42
43
  if (err instanceof core_1.ValidationError) {
@@ -49,35 +50,82 @@ exports.commandUnpackHarmony = {
49
50
  }
50
51
  }),
51
52
  };
52
- function unpack(nodeModulesPath, outputDirPath) {
53
+ function unpack(projectRootPath, outputDirPath) {
53
54
  return __awaiter(this, void 0, void 0, function* () {
54
- const nodeModuleNames = fs_1.default.readdirSync(nodeModulesPath);
55
- for (const nodeModuleName of nodeModuleNames) {
56
- const nodeModulePath = path_1.default.join(nodeModulesPath, nodeModuleName);
57
- const nodePackageVersion = getNodePackageVersion(nodeModulePath);
58
- const harmonyArchivePath = path_1.default.join(nodeModulePath, 'harmony.tar.gz');
59
- const pkgHarmonyDirPath = path_1.default.join(nodeModulePath, 'harmony');
60
- const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
61
- if (nodePackageVersion &&
62
- shouldUnpackHarmonyArchive(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, nodePackageVersion)) {
63
- console.log(`[UNPACKING] ${nodeModuleName}/harmony.tar.gz`);
64
- yield unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
55
+ const logger = new io_1.Logger();
56
+ const projectDependenciesManager = new core_1.ProjectDependenciesManager(projectRootPath);
57
+ logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
58
+ prefix: true,
59
+ });
60
+ let unpackedArchivesCount = 0;
61
+ let skippedArchivesCount = 0;
62
+ yield projectDependenciesManager.forEachAsync((dependency) => __awaiter(this, void 0, void 0, function* () {
63
+ const packageJSON = dependency.readPackageJSON();
64
+ const harmonyArchivePath = dependency
65
+ .getRootPath()
66
+ .copyWithNewSegment('harmony.tar.gz');
67
+ const pkgHarmonyDirPath = dependency
68
+ .getRootPath()
69
+ .copyWithNewSegment('harmony');
70
+ const harmonyTarGzPathStr = dependency
71
+ .getRootPath()
72
+ .copyWithNewSegment('harmony.tar.gz')
73
+ .relativeTo(projectRootPath)
74
+ .getValue();
75
+ if (packageJSON.version &&
76
+ shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, packageJSON.version)) {
77
+ if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue())) {
78
+ /**
79
+ * After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
80
+ */
81
+ logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`);
82
+ yield unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
83
+ unpackedArchivesCount++;
84
+ }
85
+ else {
86
+ skippedArchivesCount++;
87
+ logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
88
+ }
89
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
65
90
  for (const ohModuleInfo of ohModulesInfo) {
66
- console.log(`[UNPACKING] ${nodeModuleName}/harmony/${ohModuleInfo.archiveFileName}`);
91
+ const moduleArchivePathStr = dependency
92
+ .getRootPath()
93
+ .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
94
+ .relativeTo(projectRootPath)
95
+ .getValue();
96
+ logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`);
97
+ unpackedArchivesCount++;
67
98
  yield unpackTarGz(ohModuleInfo.archivePath, ohModuleInfo.computedModulePath);
68
99
  }
69
100
  }
70
- }
101
+ else {
102
+ if (fs_1.default.existsSync(harmonyArchivePath.getValue())) {
103
+ skippedArchivesCount++;
104
+ logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
105
+ }
106
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
107
+ for (const ohModuleInfo of ohModulesInfo) {
108
+ const moduleArchivePathStr = dependency
109
+ .getRootPath()
110
+ .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
111
+ .relativeTo(projectRootPath)
112
+ .getValue();
113
+ skippedArchivesCount++;
114
+ logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(moduleArchivePathStr)}`);
115
+ }
116
+ }
117
+ }));
118
+ logger.info((styles) => `\nUnpacked: ${styles.cyan(unpackedArchivesCount)}, Skipped: ${styles.yellow(skippedArchivesCount)}`);
71
119
  });
72
120
  }
73
- function shouldUnpackHarmonyArchive(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, nodePackageVersion) {
74
- if (!fs_1.default.existsSync(harmonyArchivePath))
121
+ function shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, nodePackageVersion) {
122
+ if (!fs_1.default.existsSync(harmonyArchivePath.getValue()))
75
123
  return false;
76
- if (!fs_1.default.existsSync(pkgHarmonyDirPath))
124
+ if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
77
125
  return true;
78
126
  const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
79
127
  for (const ohModuleInfo of ohModulesInfo) {
80
- if (!fs_1.default.existsSync(ohModuleInfo.computedModulePath) ||
128
+ if (!fs_1.default.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
81
129
  getOhPackageVersion(ohModuleInfo.computedModulePath) !==
82
130
  nodePackageVersion) {
83
131
  return true;
@@ -85,32 +133,27 @@ function shouldUnpackHarmonyArchive(harmonyArchivePath, pkgHarmonyDirPath, outpu
85
133
  }
86
134
  return false;
87
135
  }
88
- function getNodePackageVersion(nodeModulePath) {
89
- const packageJSONPath = path_1.default.join(nodeModulePath, 'package.json');
90
- if (!fs_1.default.existsSync(packageJSONPath))
91
- return null;
92
- const content = fs_1.default.readFileSync(packageJSONPath, { encoding: 'utf-8' });
93
- return JSON.parse(content)['version'];
94
- }
95
136
  function getOhPackageVersion(modulePath) {
96
- const ohPackagePath = path_1.default.join(modulePath, 'oh-package.json5');
97
- if (!fs_1.default.existsSync(ohPackagePath))
137
+ const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
138
+ if (!fs_1.default.existsSync(ohPackagePath.getValue()))
98
139
  return null;
99
- const content = fs_1.default.readFileSync(ohPackagePath, { encoding: 'utf-8' });
140
+ const content = fs_1.default.readFileSync(ohPackagePath.getValue(), {
141
+ encoding: 'utf-8',
142
+ });
100
143
  return json5_1.default.parse(content)['version'];
101
144
  }
102
145
  function getOhModulesInfo(pkgHarmonyDirPath, outputDirPath) {
103
146
  const results = [];
104
- if (!fs_1.default.existsSync(pkgHarmonyDirPath))
147
+ if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
105
148
  return [];
106
- const names = fs_1.default.readdirSync(pkgHarmonyDirPath);
149
+ const names = fs_1.default.readdirSync(pkgHarmonyDirPath.getValue());
107
150
  for (const name of names) {
108
151
  if (name.endsWith('.tar.gz')) {
109
- const archivePath = path_1.default.join(pkgHarmonyDirPath, name);
152
+ const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
110
153
  const computedModuleName = path_1.default
111
- .parse(archivePath)
154
+ .parse(archivePath.getValue())
112
155
  .name.split('.')[0];
113
- const computedModulePath = path_1.default.join(outputDirPath, computedModuleName);
156
+ const computedModulePath = outputDirPath.copyWithNewSegment(computedModuleName);
114
157
  results.push({
115
158
  archivePath,
116
159
  archiveFileName: name,
@@ -122,12 +165,12 @@ function getOhModulesInfo(pkgHarmonyDirPath, outputDirPath) {
122
165
  return results;
123
166
  }
124
167
  function unpackTarGz(archivePath, outputDirPath) {
125
- if (!fs_1.default.existsSync(outputDirPath)) {
126
- fs_1.default.mkdirSync(outputDirPath, { recursive: true });
168
+ if (!fs_1.default.existsSync(outputDirPath.getValue())) {
169
+ fs_1.default.mkdirSync(outputDirPath.getValue(), { recursive: true });
127
170
  }
128
- const readStream = fs_1.default.createReadStream(archivePath);
171
+ const readStream = fs_1.default.createReadStream(archivePath.getValue());
129
172
  const writeStream = tar_1.default.extract({
130
- cwd: outputDirPath,
173
+ cwd: outputDirPath.getValue(),
131
174
  });
132
175
  readStream.pipe(zlib_1.default.createGunzip()).pipe(writeStream);
133
176
  return new Promise((resolve, reject) => {
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AbsolutePath = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ class AbsolutePath {
9
+ static fromSegments(...segments) {
10
+ return new AbsolutePath(node_path_1.default.join(...segments));
11
+ }
12
+ constructor(path) {
13
+ this.value = '';
14
+ this.value = node_path_1.default.resolve(path);
15
+ }
16
+ getValue() {
17
+ return this.value;
18
+ }
19
+ copyWithNewSegment(...relativePath) {
20
+ return new AbsolutePath(node_path_1.default.join(this.getValue(), ...relativePath));
21
+ }
22
+ getExtension() {
23
+ const maybeExtWithDot = node_path_1.default.extname(this.value);
24
+ if (maybeExtWithDot) {
25
+ return maybeExtWithDot.substring(1);
26
+ }
27
+ return null;
28
+ }
29
+ relativeTo(absolutePath) {
30
+ return new RelativePath(node_path_1.default.relative(absolutePath.getValue(), this.value));
31
+ }
32
+ }
33
+ exports.AbsolutePath = AbsolutePath;
34
+ class RelativePath {
35
+ constructor(value) {
36
+ this.value = value;
37
+ }
38
+ getValue() {
39
+ return this.value;
40
+ }
41
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CodegenConfig = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const io_1 = require("../io");
9
+ const DescriptiveError_1 = require("./DescriptiveError");
10
+ class CodegenConfig {
11
+ static fromRawCodegenConfig(rawCodegenConfig, packageRootPath, projectRootPath, packageName) {
12
+ var _a;
13
+ const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
14
+ const specPaths = ((_a = rawCodegenConfig.specPaths) !== null && _a !== void 0 ? _a : []).map((rawSpecPath) => {
15
+ if (rawSpecPath.startsWith('~')) {
16
+ return projectRootPath.copyWithNewSegment(rawSpecPath.replace('~', ''));
17
+ }
18
+ else {
19
+ return packageRootPath.copyWithNewSegment(rawSpecPath);
20
+ }
21
+ });
22
+ const specFilePaths = specPaths.flatMap((specPath) => {
23
+ if (!node_fs_1.default.existsSync(specPath.getValue())) {
24
+ throw new DescriptiveError_1.DescriptiveError({
25
+ whatHappened: `No such file or directory: ${specPath.getValue()}`,
26
+ whatCanUserDo: {
27
+ default: [
28
+ `Please verify in "${packageName}/package.json::harmony::codegenConfig". If you are not the maintainer of this package, please report this problem to the package maintainer.`,
29
+ ],
30
+ },
31
+ });
32
+ }
33
+ if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
34
+ return (0, io_1.findFilePathsWithExtensions)(specPath, SUPPORTED_SPEC_EXTENSIONS);
35
+ }
36
+ else {
37
+ const ext = specPath.getExtension();
38
+ if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
39
+ return [specPath];
40
+ }
41
+ return [];
42
+ }
43
+ });
44
+ return new CodegenConfig(specFilePaths);
45
+ }
46
+ constructor(specFilePaths) {
47
+ this.specFilePaths = specFilePaths;
48
+ }
49
+ getSpecFilePaths() {
50
+ return this.specFilePaths;
51
+ }
52
+ }
53
+ exports.CodegenConfig = CodegenConfig;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DescriptiveError = void 0;
4
+ class DescriptiveError extends Error {
5
+ constructor(data) {
6
+ super(data.whatHappened);
7
+ this.data = data;
8
+ }
9
+ isUnexpected() {
10
+ return 'unexpected' in this.data;
11
+ }
12
+ getMessage() {
13
+ return this.data.whatHappened;
14
+ }
15
+ getSuggestionsByRole() {
16
+ if ('whatCanUserDo' in this.data) {
17
+ return this.data.whatCanUserDo;
18
+ }
19
+ else {
20
+ return null;
21
+ }
22
+ }
23
+ getDetails() {
24
+ var _a;
25
+ if (!this.data.extraData) {
26
+ return '';
27
+ }
28
+ if (typeof this.data.extraData === 'string') {
29
+ return this.data.extraData.trim();
30
+ }
31
+ if (this.data.extraData instanceof Error) {
32
+ let lines = [
33
+ `${this.data.extraData.name}: ${this.data.extraData.message}`,
34
+ ];
35
+ for (let stackEntry of ((_a = this.data.extraData.stack) !== null && _a !== void 0 ? _a : '').split('\n')) {
36
+ lines.push('');
37
+ lines.push(stackEntry);
38
+ }
39
+ return lines.join('\n');
40
+ }
41
+ try {
42
+ return JSON.stringify(this.data.extraData, null, 2);
43
+ }
44
+ catch (err) {
45
+ return '';
46
+ }
47
+ }
48
+ }
49
+ exports.DescriptiveError = DescriptiveError;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PackageJSON = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const CodegenConfig_1 = require("./CodegenConfig");
9
+ const DescriptiveError_1 = require("./DescriptiveError");
10
+ class PackageJSON {
11
+ static fromProjectRootPath(packageRootPath, projectRootPath) {
12
+ const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
13
+ if (!fs_1.default.existsSync(packageJSONPath.getValue())) {
14
+ throw new DescriptiveError_1.DescriptiveError({
15
+ whatHappened: "Couldn't find 'package.json'",
16
+ whatCanUserDo: {
17
+ default: [
18
+ 'Check if the path to project root is correct',
19
+ 'Try changing working directory to project root',
20
+ ],
21
+ },
22
+ extraData: packageJSONPath.getValue(),
23
+ });
24
+ }
25
+ return new PackageJSON(JSON.parse(fs_1.default.readFileSync(packageJSONPath.getValue()).toString()), packageRootPath, projectRootPath);
26
+ }
27
+ constructor(rawPackageJSON, packageRootPath, projectRootPath) {
28
+ this.rawPackageJSON = rawPackageJSON;
29
+ this.packageRootPath = packageRootPath;
30
+ this.projectRootPath = projectRootPath;
31
+ }
32
+ get name() {
33
+ return this.rawPackageJSON.name;
34
+ }
35
+ get version() {
36
+ return this.rawPackageJSON.version;
37
+ }
38
+ maybeCreateCodegenConfig() {
39
+ var _a;
40
+ /**
41
+ * Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
42
+ * generate code for harmony-specific packages. The shape of this codegenConfig is different
43
+ * that the shape of the shared config, to allow specifying which specific turbo modules or
44
+ * fabric components should be code generated.
45
+ */
46
+ const rawCodegenConfig = (_a = this.rawPackageJSON.harmony) === null || _a === void 0 ? void 0 : _a.codegenConfig;
47
+ if (!rawCodegenConfig) {
48
+ return null;
49
+ }
50
+ return CodegenConfig_1.CodegenConfig.fromRawCodegenConfig(rawCodegenConfig, this.packageRootPath, this.projectRootPath, this.name);
51
+ }
52
+ }
53
+ exports.PackageJSON = PackageJSON;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ProjectDependenciesManager = exports.ProjectDependency = void 0;
16
+ const node_fs_1 = __importDefault(require("node:fs"));
17
+ const PackageJSON_1 = require("./PackageJSON");
18
+ class ProjectDependency {
19
+ constructor(packageRootPath, projectRootPath) {
20
+ this.packageRootPath = packageRootPath;
21
+ this.projectRootPath = projectRootPath;
22
+ }
23
+ getRootPath() {
24
+ return this.packageRootPath;
25
+ }
26
+ maybeCreateCodegenConfig() {
27
+ return this.readPackageJSON().maybeCreateCodegenConfig();
28
+ }
29
+ readPackageJSON() {
30
+ return PackageJSON_1.PackageJSON.fromProjectRootPath(this.packageRootPath, this.projectRootPath);
31
+ }
32
+ }
33
+ exports.ProjectDependency = ProjectDependency;
34
+ class ProjectDependenciesManager {
35
+ constructor(projectRootPath) {
36
+ this.projectRootPath = projectRootPath;
37
+ }
38
+ forEachAsync(cb) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ yield this.forEachDependencyInDirectory(cb, this.projectRootPath.copyWithNewSegment('node_modules'));
41
+ });
42
+ }
43
+ forEachDependencyInDirectory(cb, directoryPath) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ if (!node_fs_1.default.existsSync(directoryPath.getValue())) {
46
+ return;
47
+ }
48
+ for (let dirOrFileName of node_fs_1.default.readdirSync(directoryPath.getValue())) {
49
+ const potentialDependencyRootPath = directoryPath.copyWithNewSegment(dirOrFileName);
50
+ if (node_fs_1.default.lstatSync(potentialDependencyRootPath.getValue()).isDirectory()) {
51
+ if (dirOrFileName.startsWith('.')) {
52
+ continue;
53
+ }
54
+ else if (dirOrFileName.startsWith('@')) {
55
+ yield this.forEachDependencyInDirectory(cb, directoryPath.copyWithNewSegment(dirOrFileName));
56
+ }
57
+ else {
58
+ if (!node_fs_1.default.existsSync(potentialDependencyRootPath
59
+ .copyWithNewSegment('package.json')
60
+ .getValue())) {
61
+ continue;
62
+ }
63
+ yield cb(new ProjectDependency(potentialDependencyRootPath, this.projectRootPath));
64
+ }
65
+ }
66
+ }
67
+ });
68
+ }
69
+ }
70
+ exports.ProjectDependenciesManager = ProjectDependenciesManager;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.maybeRemoveFilesInDirectory = exports.maybeMakeDirectories = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const DescriptiveError_1 = require("./DescriptiveError");
9
+ function maybeMakeDirectories(path) {
10
+ if (!node_fs_1.default.existsSync(path.getValue())) {
11
+ node_fs_1.default.mkdirSync(path.getValue(), { recursive: true });
12
+ }
13
+ }
14
+ exports.maybeMakeDirectories = maybeMakeDirectories;
15
+ function maybeRemoveFilesInDirectory(path) {
16
+ if (!node_fs_1.default.existsSync(path.getValue())) {
17
+ return;
18
+ }
19
+ if (!node_fs_1.default.lstatSync(path.getValue()).isDirectory()) {
20
+ throw new DescriptiveError_1.DescriptiveError({
21
+ whatHappened: "Tried to remove all files from a path that doesn't point to a directory",
22
+ whatCanUserDo: { default: [`Verify path: ${path.getValue()}`] },
23
+ });
24
+ }
25
+ const fileOrDirNames = node_fs_1.default.readdirSync(path.getValue());
26
+ fileOrDirNames.forEach((fileOrDirName) => {
27
+ const maybeFilePath = path.copyWithNewSegment(fileOrDirName);
28
+ if (node_fs_1.default.statSync(maybeFilePath.getValue()).isDirectory()) {
29
+ return;
30
+ }
31
+ else {
32
+ node_fs_1.default.unlinkSync(maybeFilePath.getValue());
33
+ }
34
+ });
35
+ }
36
+ exports.maybeRemoveFilesInDirectory = maybeRemoveFilesInDirectory;
@@ -14,4 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AbsolutePath"), exports);
17
18
  __exportStar(require("./ValidationError"), exports);
19
+ __exportStar(require("./DescriptiveError"), exports);
20
+ __exportStar(require("./ValueObject"), exports);
21
+ __exportStar(require("./PackageJSON"), exports);
22
+ __exportStar(require("./ProjectDependenciesManager"), exports);
23
+ __exportStar(require("./CodegenConfig"), exports);
24
+ __exportStar(require("./fs"), exports);
package/dist/index.js CHANGED
@@ -3,5 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.config = void 0;
4
4
  const commands_1 = require("./commands");
5
5
  exports.config = {
6
- commands: [commands_1.commandBundleHarmony, commands_1.commandPackHarmony, commands_1.commandUnpackHarmony],
6
+ commands: [
7
+ commands_1.commandBundleHarmony,
8
+ commands_1.commandPackHarmony,
9
+ commands_1.commandUnpackHarmony,
10
+ commands_1.commandCreateMetroConstantsHarmony,
11
+ commands_1.commandCodegenHarmony,
12
+ ],
7
13
  };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Logger = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ class Logger {
9
+ info(prepareMsg, options) {
10
+ const prefix = (options === null || options === void 0 ? void 0 : options.prefix) ? `[${chalk_1.default.bold(chalk_1.default.cyan('INFO'))}]` : '';
11
+ if (prefix) {
12
+ console.info(prefix, prepareMsg(chalk_1.default));
13
+ }
14
+ else {
15
+ console.info(prepareMsg(chalk_1.default));
16
+ }
17
+ }
18
+ debug(prepareMsg) {
19
+ console.debug(prepareMsg(chalk_1.default));
20
+ }
21
+ descriptiveError(error) {
22
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
23
+ const lines = [];
24
+ if (error.isUnexpected() && error.stack) {
25
+ lines.push('');
26
+ lines.push(chalk_1.default.bold('Stack'));
27
+ error.stack.split('\n').forEach((line) => lines.push(chalk_1.default.gray(line)));
28
+ }
29
+ const details = error.getDetails();
30
+ if (details) {
31
+ lines.push('');
32
+ lines.push(chalk_1.default.bold('Details'));
33
+ details.split('\n').forEach((line) => lines.push(line));
34
+ }
35
+ lines.push('');
36
+ let prefix = '';
37
+ if (error.isUnexpected()) {
38
+ prefix = '[' + chalk_1.default.red(chalk_1.default.bold('UNEXPECTED_ERROR')) + ']';
39
+ }
40
+ else {
41
+ prefix = '[' + chalk_1.default.red(chalk_1.default.bold('ERROR')) + ']';
42
+ }
43
+ lines.push(`${prefix} ${error.getMessage()}`);
44
+ const suggestionsByRole = error.getSuggestionsByRole();
45
+ if (suggestionsByRole) {
46
+ if (((_b = (_a = suggestionsByRole.default) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
47
+ lines.push('');
48
+ lines.push(chalk_1.default.bold(`Suggestions`));
49
+ (_c = suggestionsByRole.default) === null || _c === void 0 ? void 0 : _c.forEach((suggestion) => {
50
+ lines.push(suggestion);
51
+ });
52
+ }
53
+ if (((_e = (_d = suggestionsByRole.rnAppDeveloper) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) > 0) {
54
+ lines.push('');
55
+ lines.push(chalk_1.default.bold(`Suggestions for RN App developers`));
56
+ (_f = suggestionsByRole.rnAppDeveloper) === null || _f === void 0 ? void 0 : _f.forEach((suggestion) => {
57
+ lines.push(suggestion);
58
+ });
59
+ }
60
+ if ((_h = (_g = suggestionsByRole.rnPackageDeveloper) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) {
61
+ lines.push('');
62
+ lines.push(chalk_1.default.bold(`Suggestions for RN package developers`));
63
+ (_j = suggestionsByRole.rnPackageDeveloper) === null || _j === void 0 ? void 0 : _j.forEach((suggestion) => {
64
+ lines.push(suggestion);
65
+ });
66
+ }
67
+ }
68
+ console.error(lines.join('\n'));
69
+ }
70
+ }
71
+ exports.Logger = Logger;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findFilePathsWithExtensions = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ function findFilePathsWithExtensions(dirPath, fileExtensions) {
10
+ let results = [];
11
+ const files = node_fs_1.default.readdirSync(dirPath.getValue(), { withFileTypes: true });
12
+ for (const file of files) {
13
+ const path = dirPath.copyWithNewSegment(file.name);
14
+ if (file.isDirectory()) {
15
+ results = results.concat(findFilePathsWithExtensions(path, fileExtensions));
16
+ }
17
+ else if (fileExtensions.includes(node_path_1.default.extname(file.name).substring(1))) {
18
+ results.push(path);
19
+ }
20
+ }
21
+ return results;
22
+ }
23
+ exports.findFilePathsWithExtensions = findFilePathsWithExtensions;