@react-native-oh/react-native-harmony-cli 0.0.25 → 0.0.26-1

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 (94) hide show
  1. package/.prettierrc +6 -6
  2. package/dist/assetResolver.js +1 -23
  3. package/dist/codegen/core/CodeGenerator.js +2 -0
  4. package/dist/codegen/core/UberSchema.js +35 -9
  5. package/dist/codegen/core/index.js +1 -1
  6. package/dist/codegen/generators/{ComponentCodeGenerator.js → ComponentCodeGeneratorArkTS.js} +12 -4
  7. package/dist/codegen/generators/ComponentCodeGeneratorCAPI.js +79 -0
  8. package/dist/codegen/generators/GlueCodeGenerator.js +60 -0
  9. package/dist/codegen/generators/NativeModuleCodeGenerator.js +14 -6
  10. package/dist/codegen/generators/UberGeneratorV1.js +49 -0
  11. package/dist/codegen/generators/UberGeneratorV2.js +60 -0
  12. package/dist/codegen/generators/index.js +5 -2
  13. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +103 -0
  14. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +42 -36
  15. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +45 -36
  16. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +135 -127
  17. package/dist/codegen/templates/GeneratedPackageHTemplate.js +101 -0
  18. package/dist/codegen/templates/IndexTSTemplate.js +23 -5
  19. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +88 -82
  20. package/dist/codegen/templates/TurboModuleCppTemplate.js +26 -18
  21. package/dist/codegen/templates/TurboModuleHTemplate.js +27 -17
  22. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +37 -27
  23. package/dist/codegen/templates/index.js +1 -0
  24. package/dist/commands/codegen-harmony.js +99 -14
  25. package/dist/core/AbsolutePath.js +6 -0
  26. package/dist/core/CodegenConfig.js +8 -4
  27. package/dist/core/PackageJSON.js +8 -3
  28. package/dist/core/ProjectDependenciesManager.js +2 -2
  29. package/jest.config.js +5 -5
  30. package/package.json +57 -56
  31. package/react-native.config.js +10 -10
  32. package/src/assetResolver.ts +21 -44
  33. package/src/codegen/core/CodeGenerator.ts +9 -0
  34. package/src/codegen/core/CodegenError.ts +3 -3
  35. package/src/codegen/core/EventUtils.ts +18 -18
  36. package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
  37. package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
  38. package/src/codegen/core/UberSchema.ts +142 -99
  39. package/src/codegen/core/index.ts +5 -5
  40. package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
  41. package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
  42. package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
  43. package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
  44. package/src/codegen/generators/UberGeneratorV1.ts +64 -0
  45. package/src/codegen/generators/UberGeneratorV2.ts +91 -0
  46. package/src/codegen/generators/index.ts +6 -3
  47. package/src/codegen/index.ts +2 -2
  48. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
  49. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
  50. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
  51. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
  52. package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
  53. package/src/codegen/templates/IndexTSTemplate.ts +53 -33
  54. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
  55. package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
  56. package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
  57. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
  58. package/src/codegen/templates/index.ts +9 -8
  59. package/src/commands/bundle-harmony.ts +203 -203
  60. package/src/commands/codegen-harmony.ts +272 -143
  61. package/src/commands/create-metro-host-constants.ts +48 -48
  62. package/src/commands/index.ts +6 -6
  63. package/src/commands/pack-harmony.ts +121 -121
  64. package/src/commands/unpack-harmony.ts +231 -231
  65. package/src/commands/verify-package-harmony.ts +106 -106
  66. package/src/core/AbsolutePath.ts +50 -43
  67. package/src/core/CodegenConfig.ts +62 -54
  68. package/src/core/DescriptiveError.ts +61 -61
  69. package/src/core/OHPackageJSON5.ts +23 -23
  70. package/src/core/PackageJSON.ts +75 -63
  71. package/src/core/ProjectDependenciesManager.ts +77 -77
  72. package/src/core/ValidationError.ts +1 -1
  73. package/src/core/ValueObject.ts +2 -2
  74. package/src/core/fs.ts +31 -31
  75. package/src/core/index.ts +9 -9
  76. package/src/index.ts +20 -20
  77. package/src/io/Logger.ts +68 -68
  78. package/src/io/TarGz.ts +26 -26
  79. package/src/io/fsUtils.ts +24 -24
  80. package/src/io/index.ts +3 -3
  81. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -28
  82. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -24
  83. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -18
  84. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -47
  85. package/src/package-verifier/checks/index.ts +4 -4
  86. package/src/package-verifier/index.ts +2 -2
  87. package/src/package-verifier/types.ts +12 -12
  88. package/src/package-verifier/verify-package.ts +117 -117
  89. package/tsconfig.build.json +6 -6
  90. package/tsconfig.json +2 -2
  91. package/dist/codegen/core/Codegen.js +0 -35
  92. package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
  93. package/src/codegen/core/Codegen.ts +0 -44
  94. package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
@@ -1,231 +1,231 @@
1
- import { Command } from '@react-native-community/cli-types';
2
- import { Logger } from '../io';
3
-
4
- import pathUtils from 'path';
5
- import fs from 'fs';
6
- import zlib from 'zlib';
7
- import tar from 'tar';
8
- import JSON5 from 'json5';
9
- import {
10
- ValidationError,
11
- AbsolutePath,
12
- ProjectDependenciesManager,
13
- } from '../core';
14
-
15
- export const commandUnpackHarmony: Command = {
16
- name: 'unpack-harmony',
17
- description: 'Unpacks native code.',
18
- options: [
19
- {
20
- name: '--project-root-path <path>',
21
- description: 'Relative path to package root',
22
- default: '.',
23
- },
24
- {
25
- name: '--output-dir <string>',
26
- description: 'Output directory to which OH modules should be unpacked to',
27
- default: './harmony/rnoh_modules',
28
- },
29
- ],
30
- func: async (argv, config, args: any) => {
31
- try {
32
- await unpack(
33
- new AbsolutePath(args.projectRootPath),
34
- new AbsolutePath(args.outputDir)
35
- );
36
- } catch (err) {
37
- if (err instanceof ValidationError) {
38
- console.error('[ERROR]', err.message);
39
- process.exit(1);
40
- } else {
41
- throw err;
42
- }
43
- }
44
- },
45
- };
46
-
47
- async function unpack(
48
- projectRootPath: AbsolutePath,
49
- outputDirPath: AbsolutePath
50
- ) {
51
- const logger = new Logger();
52
- const projectDependenciesManager = new ProjectDependenciesManager(
53
- projectRootPath
54
- );
55
- logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
56
- prefix: true,
57
- });
58
- let unpackedArchivesCount = 0;
59
- let skippedArchivesCount = 0;
60
- await projectDependenciesManager.forEachAsync(async (dependency) => {
61
- const packageJSON = dependency.readPackageJSON();
62
- const harmonyArchivePath = dependency
63
- .getRootPath()
64
- .copyWithNewSegment('harmony.tar.gz');
65
- const pkgHarmonyDirPath = dependency
66
- .getRootPath()
67
- .copyWithNewSegment('harmony');
68
- const harmonyTarGzPathStr = dependency
69
- .getRootPath()
70
- .copyWithNewSegment('harmony.tar.gz')
71
- .relativeTo(projectRootPath)
72
- .getValue();
73
- if (
74
- packageJSON.version &&
75
- shouldUnpack(
76
- harmonyArchivePath,
77
- pkgHarmonyDirPath,
78
- outputDirPath,
79
- packageJSON.version
80
- )
81
- ) {
82
- if (!fs.existsSync(pkgHarmonyDirPath.getValue())) {
83
- /**
84
- * After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
85
- */
86
- logger.info(
87
- (styles) =>
88
- `[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`
89
- );
90
- await unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
91
- unpackedArchivesCount++;
92
- } else {
93
- skippedArchivesCount++;
94
- logger.info(
95
- (styles) =>
96
- `[${styles.yellow('skipped')}] ${styles.gray(
97
- harmonyTarGzPathStr
98
- )}`
99
- );
100
- }
101
- const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
102
- for (const ohModuleInfo of ohModulesInfo) {
103
- const moduleArchivePathStr = dependency
104
- .getRootPath()
105
- .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
106
- .relativeTo(projectRootPath)
107
- .getValue();
108
- logger.info(
109
- (styles) =>
110
- `[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`
111
- );
112
- unpackedArchivesCount++;
113
- await unpackTarGz(
114
- ohModuleInfo.archivePath,
115
- ohModuleInfo.computedModulePath
116
- );
117
- }
118
- } else {
119
- if (fs.existsSync(harmonyArchivePath.getValue())) {
120
- skippedArchivesCount++;
121
- logger.info(
122
- (styles) =>
123
- `[${styles.yellow('skipped')}] ${styles.gray(
124
- harmonyTarGzPathStr
125
- )}`
126
- );
127
- }
128
- const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
129
- for (const ohModuleInfo of ohModulesInfo) {
130
- const moduleArchivePathStr = dependency
131
- .getRootPath()
132
- .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
133
- .relativeTo(projectRootPath)
134
- .getValue();
135
- skippedArchivesCount++;
136
- logger.info(
137
- (styles) =>
138
- `[${styles.yellow('skipped')}] ${styles.gray(
139
- moduleArchivePathStr
140
- )}`
141
- );
142
- }
143
- }
144
- });
145
- logger.info(
146
- (styles) =>
147
- `\nUnpacked: ${styles.cyan(
148
- unpackedArchivesCount
149
- )}, Skipped: ${styles.yellow(skippedArchivesCount)}`
150
- );
151
- }
152
-
153
- function shouldUnpack(
154
- harmonyArchivePath: AbsolutePath,
155
- pkgHarmonyDirPath: AbsolutePath,
156
- outputDirPath: AbsolutePath,
157
- nodePackageVersion: string
158
- ) {
159
- if (!fs.existsSync(harmonyArchivePath.getValue())) return false;
160
- if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return true;
161
- const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
162
- for (const ohModuleInfo of ohModulesInfo) {
163
- if (
164
- !fs.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
165
- getOhPackageVersion(ohModuleInfo.computedModulePath) !==
166
- nodePackageVersion
167
- ) {
168
- return true;
169
- }
170
- }
171
- return false;
172
- }
173
-
174
- function getOhPackageVersion(modulePath: AbsolutePath) {
175
- const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
176
- if (!fs.existsSync(ohPackagePath.getValue())) return null;
177
- const content = fs.readFileSync(ohPackagePath.getValue(), {
178
- encoding: 'utf-8',
179
- });
180
- return JSON5.parse(content)['version'];
181
- }
182
-
183
- function getOhModulesInfo(
184
- pkgHarmonyDirPath: AbsolutePath,
185
- outputDirPath: AbsolutePath
186
- ) {
187
- const results: {
188
- archivePath: AbsolutePath;
189
- archiveFileName: string;
190
- computedModulePath: AbsolutePath;
191
- computedModuleName: string;
192
- }[] = [];
193
- if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return [];
194
- const names = fs.readdirSync(pkgHarmonyDirPath.getValue());
195
- for (const name of names) {
196
- if (name.endsWith('.tar.gz')) {
197
- const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
198
- const computedModuleName = pathUtils
199
- .parse(archivePath.getValue())
200
- .name.split('.')[0];
201
- const computedModulePath =
202
- outputDirPath.copyWithNewSegment(computedModuleName);
203
- results.push({
204
- archivePath,
205
- archiveFileName: name,
206
- computedModulePath,
207
- computedModuleName,
208
- });
209
- }
210
- }
211
- return results;
212
- }
213
-
214
- function unpackTarGz(archivePath: AbsolutePath, outputDirPath: AbsolutePath) {
215
- if (!fs.existsSync(outputDirPath.getValue())) {
216
- fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
217
- }
218
- const readStream = fs.createReadStream(archivePath.getValue());
219
- const writeStream = tar.extract({
220
- cwd: outputDirPath.getValue(),
221
- });
222
- readStream.pipe(zlib.createGunzip()).pipe(writeStream);
223
- return new Promise((resolve, reject) => {
224
- writeStream.on('finish', () => {
225
- resolve(undefined);
226
- });
227
- writeStream.on('error', (err) => {
228
- reject(err);
229
- });
230
- });
231
- }
1
+ import { Command } from '@react-native-community/cli-types';
2
+ import { Logger } from '../io';
3
+
4
+ import pathUtils from 'path';
5
+ import fs from 'fs';
6
+ import zlib from 'zlib';
7
+ import tar from 'tar';
8
+ import JSON5 from 'json5';
9
+ import {
10
+ ValidationError,
11
+ AbsolutePath,
12
+ ProjectDependenciesManager,
13
+ } from '../core';
14
+
15
+ export const commandUnpackHarmony: Command = {
16
+ name: 'unpack-harmony',
17
+ description: 'Unpacks native code.',
18
+ options: [
19
+ {
20
+ name: '--project-root-path <path>',
21
+ description: 'Relative path to package root',
22
+ default: '.',
23
+ },
24
+ {
25
+ name: '--output-dir <string>',
26
+ description: 'Output directory to which OH modules should be unpacked to',
27
+ default: './harmony/rnoh_modules',
28
+ },
29
+ ],
30
+ func: async (argv, config, args: any) => {
31
+ try {
32
+ await unpack(
33
+ new AbsolutePath(args.projectRootPath),
34
+ new AbsolutePath(args.outputDir)
35
+ );
36
+ } catch (err) {
37
+ if (err instanceof ValidationError) {
38
+ console.error('[ERROR]', err.message);
39
+ process.exit(1);
40
+ } else {
41
+ throw err;
42
+ }
43
+ }
44
+ },
45
+ };
46
+
47
+ async function unpack(
48
+ projectRootPath: AbsolutePath,
49
+ outputDirPath: AbsolutePath
50
+ ) {
51
+ const logger = new Logger();
52
+ const projectDependenciesManager = new ProjectDependenciesManager(
53
+ projectRootPath
54
+ );
55
+ logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
56
+ prefix: true,
57
+ });
58
+ let unpackedArchivesCount = 0;
59
+ let skippedArchivesCount = 0;
60
+ await projectDependenciesManager.forEachAsync(async (dependency) => {
61
+ const packageJSON = dependency.readPackageJSON();
62
+ const harmonyArchivePath = dependency
63
+ .getRootPath()
64
+ .copyWithNewSegment('harmony.tar.gz');
65
+ const pkgHarmonyDirPath = dependency
66
+ .getRootPath()
67
+ .copyWithNewSegment('harmony');
68
+ const harmonyTarGzPathStr = dependency
69
+ .getRootPath()
70
+ .copyWithNewSegment('harmony.tar.gz')
71
+ .relativeTo(projectRootPath)
72
+ .getValue();
73
+ if (
74
+ packageJSON.version &&
75
+ shouldUnpack(
76
+ harmonyArchivePath,
77
+ pkgHarmonyDirPath,
78
+ outputDirPath,
79
+ packageJSON.version
80
+ )
81
+ ) {
82
+ if (!fs.existsSync(pkgHarmonyDirPath.getValue())) {
83
+ /**
84
+ * After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
85
+ */
86
+ logger.info(
87
+ (styles) =>
88
+ `[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`
89
+ );
90
+ await unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
91
+ unpackedArchivesCount++;
92
+ } else {
93
+ skippedArchivesCount++;
94
+ logger.info(
95
+ (styles) =>
96
+ `[${styles.yellow('skipped')}] ${styles.gray(
97
+ harmonyTarGzPathStr
98
+ )}`
99
+ );
100
+ }
101
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
102
+ for (const ohModuleInfo of ohModulesInfo) {
103
+ const moduleArchivePathStr = dependency
104
+ .getRootPath()
105
+ .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
106
+ .relativeTo(projectRootPath)
107
+ .getValue();
108
+ logger.info(
109
+ (styles) =>
110
+ `[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`
111
+ );
112
+ unpackedArchivesCount++;
113
+ await unpackTarGz(
114
+ ohModuleInfo.archivePath,
115
+ ohModuleInfo.computedModulePath
116
+ );
117
+ }
118
+ } else {
119
+ if (fs.existsSync(harmonyArchivePath.getValue())) {
120
+ skippedArchivesCount++;
121
+ logger.info(
122
+ (styles) =>
123
+ `[${styles.yellow('skipped')}] ${styles.gray(
124
+ harmonyTarGzPathStr
125
+ )}`
126
+ );
127
+ }
128
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
129
+ for (const ohModuleInfo of ohModulesInfo) {
130
+ const moduleArchivePathStr = dependency
131
+ .getRootPath()
132
+ .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
133
+ .relativeTo(projectRootPath)
134
+ .getValue();
135
+ skippedArchivesCount++;
136
+ logger.info(
137
+ (styles) =>
138
+ `[${styles.yellow('skipped')}] ${styles.gray(
139
+ moduleArchivePathStr
140
+ )}`
141
+ );
142
+ }
143
+ }
144
+ });
145
+ logger.info(
146
+ (styles) =>
147
+ `\nUnpacked: ${styles.cyan(
148
+ unpackedArchivesCount
149
+ )}, Skipped: ${styles.yellow(skippedArchivesCount)}`
150
+ );
151
+ }
152
+
153
+ function shouldUnpack(
154
+ harmonyArchivePath: AbsolutePath,
155
+ pkgHarmonyDirPath: AbsolutePath,
156
+ outputDirPath: AbsolutePath,
157
+ nodePackageVersion: string
158
+ ) {
159
+ if (!fs.existsSync(harmonyArchivePath.getValue())) return false;
160
+ if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return true;
161
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
162
+ for (const ohModuleInfo of ohModulesInfo) {
163
+ if (
164
+ !fs.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
165
+ getOhPackageVersion(ohModuleInfo.computedModulePath) !==
166
+ nodePackageVersion
167
+ ) {
168
+ return true;
169
+ }
170
+ }
171
+ return false;
172
+ }
173
+
174
+ function getOhPackageVersion(modulePath: AbsolutePath) {
175
+ const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
176
+ if (!fs.existsSync(ohPackagePath.getValue())) return null;
177
+ const content = fs.readFileSync(ohPackagePath.getValue(), {
178
+ encoding: 'utf-8',
179
+ });
180
+ return JSON5.parse(content)['version'];
181
+ }
182
+
183
+ function getOhModulesInfo(
184
+ pkgHarmonyDirPath: AbsolutePath,
185
+ outputDirPath: AbsolutePath
186
+ ) {
187
+ const results: {
188
+ archivePath: AbsolutePath;
189
+ archiveFileName: string;
190
+ computedModulePath: AbsolutePath;
191
+ computedModuleName: string;
192
+ }[] = [];
193
+ if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return [];
194
+ const names = fs.readdirSync(pkgHarmonyDirPath.getValue());
195
+ for (const name of names) {
196
+ if (name.endsWith('.tar.gz')) {
197
+ const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
198
+ const computedModuleName = pathUtils
199
+ .parse(archivePath.getValue())
200
+ .name.split('.')[0];
201
+ const computedModulePath =
202
+ outputDirPath.copyWithNewSegment(computedModuleName);
203
+ results.push({
204
+ archivePath,
205
+ archiveFileName: name,
206
+ computedModulePath,
207
+ computedModuleName,
208
+ });
209
+ }
210
+ }
211
+ return results;
212
+ }
213
+
214
+ function unpackTarGz(archivePath: AbsolutePath, outputDirPath: AbsolutePath) {
215
+ if (!fs.existsSync(outputDirPath.getValue())) {
216
+ fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
217
+ }
218
+ const readStream = fs.createReadStream(archivePath.getValue());
219
+ const writeStream = tar.extract({
220
+ cwd: outputDirPath.getValue(),
221
+ });
222
+ readStream.pipe(zlib.createGunzip()).pipe(writeStream);
223
+ return new Promise((resolve, reject) => {
224
+ writeStream.on('finish', () => {
225
+ resolve(undefined);
226
+ });
227
+ writeStream.on('error', (err) => {
228
+ reject(err);
229
+ });
230
+ });
231
+ }
@@ -1,106 +1,106 @@
1
- import { Command } from '@react-native-community/cli-types';
2
- import { getLoader, Loader } from '@react-native-community/cli-tools';
3
- import chalk from 'chalk';
4
- import { DescriptiveError, AbsolutePath } from '../core';
5
- import { Logger } from '../io';
6
- import { CheckResult, verifyRNOHPackage } from '../package-verifier';
7
-
8
- export const commandVerifyPackageHarmony: Command = {
9
- name: 'verify-package-harmony',
10
- description: 'Validates that a package is compliant with guidelines',
11
- options: [
12
- {
13
- name: '--package-path <path>',
14
- description: 'Path to the npm package',
15
- },
16
- {
17
- name: '--no-harmony-code [boolean]',
18
- description: 'Disable har verification',
19
- },
20
- {
21
- name: '--skip-checks <string>',
22
- description: 'Disable certain checks by their names separated by ";"',
23
- },
24
- ],
25
- func: async (argv, config, rawArgs: any) => {
26
- const loader = getLoader();
27
- try {
28
- const args = validateArgs(rawArgs);
29
- loader.info(`Verifying RNOH package: ${args.packagePath.getValue()}`);
30
- const checkResults: CheckResult[] = [];
31
- for await (const checkResult of verifyRNOHPackage({
32
- npmPackagePath: args.packagePath,
33
- hasHarmonyCode: args.hasHarmonyCode,
34
- checkNamesToSkip: args.checkNamesToSkip,
35
- })) {
36
- if (checkResult.type === 'START_PROCESS') {
37
- loader.start(chalk.gray(checkResult.name));
38
- } else if (checkResult.type === 'FINISHED_CHECKING') {
39
- checkResults.push(checkResult);
40
- logCheckResult(loader, checkResult);
41
- }
42
- }
43
- if (
44
- checkResults.every(
45
- (checkResult) =>
46
- checkResult.status === 'pass' || checkResult.status === 'skip'
47
- )
48
- ) {
49
- loader.info(chalk.bold('OK'));
50
- } else {
51
- loader.info(
52
- chalk.red(
53
- 'Package verification failed. Please fix those checks before publishing your package.'
54
- )
55
- );
56
- process.exit(1);
57
- }
58
- } catch (err) {
59
- if (err instanceof DescriptiveError) {
60
- new Logger().descriptiveError(err);
61
- process.exit(1);
62
- }
63
- throw err;
64
- }
65
- },
66
- };
67
-
68
- type Args = {
69
- packagePath: AbsolutePath;
70
- hasHarmonyCode: boolean;
71
- checkNamesToSkip: string[];
72
- };
73
-
74
- function validateArgs(args: any): Args {
75
- if (!args.packagePath) {
76
- throw new DescriptiveError({
77
- whatHappened: 'package-path is undefined',
78
- whatCanUserDo: { default: ['Please provide --package-path'] },
79
- });
80
- }
81
- return {
82
- packagePath: new AbsolutePath(args.packagePath),
83
- hasHarmonyCode: args.harmonyCode,
84
- checkNamesToSkip: ((args.skipChecks ?? '') as string).split(';'),
85
- };
86
- }
87
-
88
- function logCheckResult(loader: Loader, checkResult: CheckResult) {
89
- const prefix = (() => {
90
- switch (checkResult.status) {
91
- case 'pass':
92
- return `${chalk.green('PASS')}`;
93
- case 'fail':
94
- return `${chalk.red('FAIL')}`;
95
- case 'skip':
96
- return `${chalk.yellow('SKIP')}`;
97
- }
98
- })();
99
- loader.info(
100
- checkResult.message
101
- ? `[${chalk.bold(prefix)}] ${chalk.bold(checkResult.name)}\n${
102
- checkResult.message
103
- }`
104
- : `[${chalk.bold(prefix)}] ${chalk.bold(checkResult.name)}`
105
- );
106
- }
1
+ import { Command } from '@react-native-community/cli-types';
2
+ import { getLoader, Loader } from '@react-native-community/cli-tools';
3
+ import chalk from 'chalk';
4
+ import { DescriptiveError, AbsolutePath } from '../core';
5
+ import { Logger } from '../io';
6
+ import { CheckResult, verifyRNOHPackage } from '../package-verifier';
7
+
8
+ export const commandVerifyPackageHarmony: Command = {
9
+ name: 'verify-package-harmony',
10
+ description: 'Validates that a package is compliant with guidelines',
11
+ options: [
12
+ {
13
+ name: '--package-path <path>',
14
+ description: 'Path to the npm package',
15
+ },
16
+ {
17
+ name: '--no-harmony-code [boolean]',
18
+ description: 'Disable har verification',
19
+ },
20
+ {
21
+ name: '--skip-checks <string>',
22
+ description: 'Disable certain checks by their names separated by ";"',
23
+ },
24
+ ],
25
+ func: async (argv, config, rawArgs: any) => {
26
+ const loader = getLoader();
27
+ try {
28
+ const args = validateArgs(rawArgs);
29
+ loader.info(`Verifying RNOH package: ${args.packagePath.getValue()}`);
30
+ const checkResults: CheckResult[] = [];
31
+ for await (const checkResult of verifyRNOHPackage({
32
+ npmPackagePath: args.packagePath,
33
+ hasHarmonyCode: args.hasHarmonyCode,
34
+ checkNamesToSkip: args.checkNamesToSkip,
35
+ })) {
36
+ if (checkResult.type === 'START_PROCESS') {
37
+ loader.start(chalk.gray(checkResult.name));
38
+ } else if (checkResult.type === 'FINISHED_CHECKING') {
39
+ checkResults.push(checkResult);
40
+ logCheckResult(loader, checkResult);
41
+ }
42
+ }
43
+ if (
44
+ checkResults.every(
45
+ (checkResult) =>
46
+ checkResult.status === 'pass' || checkResult.status === 'skip'
47
+ )
48
+ ) {
49
+ loader.info(chalk.bold('OK'));
50
+ } else {
51
+ loader.info(
52
+ chalk.red(
53
+ 'Package verification failed. Please fix those checks before publishing your package.'
54
+ )
55
+ );
56
+ process.exit(1);
57
+ }
58
+ } catch (err) {
59
+ if (err instanceof DescriptiveError) {
60
+ new Logger().descriptiveError(err);
61
+ process.exit(1);
62
+ }
63
+ throw err;
64
+ }
65
+ },
66
+ };
67
+
68
+ type Args = {
69
+ packagePath: AbsolutePath;
70
+ hasHarmonyCode: boolean;
71
+ checkNamesToSkip: string[];
72
+ };
73
+
74
+ function validateArgs(args: any): Args {
75
+ if (!args.packagePath) {
76
+ throw new DescriptiveError({
77
+ whatHappened: 'package-path is undefined',
78
+ whatCanUserDo: { default: ['Please provide --package-path'] },
79
+ });
80
+ }
81
+ return {
82
+ packagePath: new AbsolutePath(args.packagePath),
83
+ hasHarmonyCode: args.harmonyCode,
84
+ checkNamesToSkip: ((args.skipChecks ?? '') as string).split(';'),
85
+ };
86
+ }
87
+
88
+ function logCheckResult(loader: Loader, checkResult: CheckResult) {
89
+ const prefix = (() => {
90
+ switch (checkResult.status) {
91
+ case 'pass':
92
+ return `${chalk.green('PASS')}`;
93
+ case 'fail':
94
+ return `${chalk.red('FAIL')}`;
95
+ case 'skip':
96
+ return `${chalk.yellow('SKIP')}`;
97
+ }
98
+ })();
99
+ loader.info(
100
+ checkResult.message
101
+ ? `[${chalk.bold(prefix)}] ${chalk.bold(checkResult.name)}\n${
102
+ checkResult.message
103
+ }`
104
+ : `[${chalk.bold(prefix)}] ${chalk.bold(checkResult.name)}`
105
+ );
106
+ }