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

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 +1 @@
1
- export class ValidationError extends Error {}
1
+ export class ValidationError extends Error {}
@@ -1,2 +1,2 @@
1
- /** https://en.wikipedia.org/wiki/Value_object */
2
- export interface ValueObject {}
1
+ /** https://en.wikipedia.org/wiki/Value_object */
2
+ export interface ValueObject {}
package/src/core/fs.ts CHANGED
@@ -1,31 +1,31 @@
1
- import fs from 'node:fs';
2
- import { AbsolutePath } from './AbsolutePath';
3
- import { DescriptiveError } from './DescriptiveError';
4
-
5
- export function maybeMakeDirectories(path: AbsolutePath): void {
6
- if (!fs.existsSync(path.getValue())) {
7
- fs.mkdirSync(path.getValue(), { recursive: true });
8
- }
9
- }
10
-
11
- export function maybeRemoveFilesInDirectory(path: AbsolutePath): void {
12
- if (!fs.existsSync(path.getValue())) {
13
- return;
14
- }
15
- if (!fs.lstatSync(path.getValue()).isDirectory()) {
16
- throw new DescriptiveError({
17
- whatHappened:
18
- "Tried to remove all files from a path that doesn't point to a directory",
19
- whatCanUserDo: { default: [`Verify path: ${path.getValue()}`] },
20
- });
21
- }
22
- const fileOrDirNames = fs.readdirSync(path.getValue());
23
- fileOrDirNames.forEach((fileOrDirName) => {
24
- const maybeFilePath = path.copyWithNewSegment(fileOrDirName);
25
- if (fs.statSync(maybeFilePath.getValue()).isDirectory()) {
26
- return;
27
- } else {
28
- fs.unlinkSync(maybeFilePath.getValue());
29
- }
30
- });
31
- }
1
+ import fs from 'node:fs';
2
+ import { AbsolutePath } from './AbsolutePath';
3
+ import { DescriptiveError } from './DescriptiveError';
4
+
5
+ export function maybeMakeDirectories(path: AbsolutePath): void {
6
+ if (!fs.existsSync(path.getValue())) {
7
+ fs.mkdirSync(path.getValue(), { recursive: true });
8
+ }
9
+ }
10
+
11
+ export function maybeRemoveFilesInDirectory(path: AbsolutePath): void {
12
+ if (!fs.existsSync(path.getValue())) {
13
+ return;
14
+ }
15
+ if (!fs.lstatSync(path.getValue()).isDirectory()) {
16
+ throw new DescriptiveError({
17
+ whatHappened:
18
+ "Tried to remove all files from a path that doesn't point to a directory",
19
+ whatCanUserDo: { default: [`Verify path: ${path.getValue()}`] },
20
+ });
21
+ }
22
+ const fileOrDirNames = fs.readdirSync(path.getValue());
23
+ fileOrDirNames.forEach((fileOrDirName) => {
24
+ const maybeFilePath = path.copyWithNewSegment(fileOrDirName);
25
+ if (fs.statSync(maybeFilePath.getValue()).isDirectory()) {
26
+ return;
27
+ } else {
28
+ fs.unlinkSync(maybeFilePath.getValue());
29
+ }
30
+ });
31
+ }
package/src/core/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- export * from './AbsolutePath';
2
- export * from './ValidationError';
3
- export * from './DescriptiveError';
4
- export * from './ValueObject';
5
- export * from './PackageJSON';
6
- export * from './ProjectDependenciesManager';
7
- export * from './CodegenConfig';
8
- export * from './fs';
9
- export * from './OHPackageJSON5';
1
+ export * from './AbsolutePath';
2
+ export * from './ValidationError';
3
+ export * from './DescriptiveError';
4
+ export * from './ValueObject';
5
+ export * from './PackageJSON';
6
+ export * from './ProjectDependenciesManager';
7
+ export * from './CodegenConfig';
8
+ export * from './fs';
9
+ export * from './OHPackageJSON5';
package/src/index.ts CHANGED
@@ -1,20 +1,20 @@
1
- import { Config } from '@react-native-community/cli-types';
2
- import {
3
- commandBundleHarmony,
4
- commandPackHarmony,
5
- commandUnpackHarmony,
6
- commandCreateMetroConstantsHarmony,
7
- commandCodegenHarmony,
8
- commandVerifyPackageHarmony,
9
- } from './commands';
10
-
11
- export const config = {
12
- commands: [
13
- commandBundleHarmony,
14
- commandPackHarmony,
15
- commandUnpackHarmony,
16
- commandCreateMetroConstantsHarmony,
17
- commandCodegenHarmony,
18
- commandVerifyPackageHarmony,
19
- ],
20
- } satisfies Partial<Config>;
1
+ import { Config } from '@react-native-community/cli-types';
2
+ import {
3
+ commandBundleHarmony,
4
+ commandPackHarmony,
5
+ commandUnpackHarmony,
6
+ commandCreateMetroConstantsHarmony,
7
+ commandCodegenHarmony,
8
+ commandVerifyPackageHarmony,
9
+ } from './commands';
10
+
11
+ export const config = {
12
+ commands: [
13
+ commandBundleHarmony,
14
+ commandPackHarmony,
15
+ commandUnpackHarmony,
16
+ commandCreateMetroConstantsHarmony,
17
+ commandCodegenHarmony,
18
+ commandVerifyPackageHarmony,
19
+ ],
20
+ } satisfies Partial<Config>;
package/src/io/Logger.ts CHANGED
@@ -1,68 +1,68 @@
1
- import chalk from 'chalk';
2
- import { DescriptiveError } from '../core';
3
-
4
- export class Logger {
5
- info(
6
- prepareMsg: (styles: typeof chalk) => string,
7
- options?: { prefix?: boolean }
8
- ) {
9
- const prefix = options?.prefix ? `[${chalk.bold(chalk.cyan('INFO'))}]` : '';
10
- if (prefix) {
11
- console.info(prefix, prepareMsg(chalk));
12
- } else {
13
- console.info(prepareMsg(chalk));
14
- }
15
- }
16
-
17
- debug(prepareMsg: (styles: typeof chalk) => string) {
18
- console.debug(prepareMsg(chalk));
19
- }
20
-
21
- descriptiveError(error: DescriptiveError) {
22
- const lines: string[] = [];
23
- if (error.isUnexpected() && error.stack) {
24
- lines.push('');
25
- lines.push(chalk.bold('Stack'));
26
- error.stack.split('\n').forEach((line) => lines.push(chalk.gray(line)));
27
- }
28
- const details = error.getDetails();
29
- if (details) {
30
- lines.push('');
31
- lines.push(chalk.bold('Details'));
32
- details.split('\n').forEach((line) => lines.push(line));
33
- }
34
- lines.push('');
35
- let prefix = '';
36
- if (error.isUnexpected()) {
37
- prefix = '[' + chalk.red(chalk.bold('UNEXPECTED_ERROR')) + ']';
38
- } else {
39
- prefix = '[' + chalk.red(chalk.bold('ERROR')) + ']';
40
- }
41
- lines.push(`${prefix} ${error.getMessage()}`);
42
- const suggestionsByRole = error.getSuggestionsByRole();
43
- if (suggestionsByRole) {
44
- if ((suggestionsByRole.default?.length ?? 0) > 0) {
45
- lines.push('');
46
- lines.push(chalk.bold(`Suggestions`));
47
- suggestionsByRole.default?.forEach((suggestion) => {
48
- lines.push(suggestion);
49
- });
50
- }
51
- if ((suggestionsByRole.rnAppDeveloper?.length ?? 0) > 0) {
52
- lines.push('');
53
- lines.push(chalk.bold(`Suggestions for RN App developers`));
54
- suggestionsByRole.rnAppDeveloper?.forEach((suggestion) => {
55
- lines.push(suggestion);
56
- });
57
- }
58
- if (suggestionsByRole.rnPackageDeveloper?.length ?? 0) {
59
- lines.push('');
60
- lines.push(chalk.bold(`Suggestions for RN package developers`));
61
- suggestionsByRole.rnPackageDeveloper?.forEach((suggestion) => {
62
- lines.push(suggestion);
63
- });
64
- }
65
- }
66
- console.error(lines.join('\n'));
67
- }
68
- }
1
+ import chalk from 'chalk';
2
+ import { DescriptiveError } from '../core';
3
+
4
+ export class Logger {
5
+ info(
6
+ prepareMsg: (styles: typeof chalk) => string,
7
+ options?: { prefix?: boolean }
8
+ ) {
9
+ const prefix = options?.prefix ? `[${chalk.bold(chalk.cyan('INFO'))}]` : '';
10
+ if (prefix) {
11
+ console.info(prefix, prepareMsg(chalk));
12
+ } else {
13
+ console.info(prepareMsg(chalk));
14
+ }
15
+ }
16
+
17
+ debug(prepareMsg: (styles: typeof chalk) => string) {
18
+ console.debug(prepareMsg(chalk));
19
+ }
20
+
21
+ descriptiveError(error: DescriptiveError) {
22
+ const lines: string[] = [];
23
+ if (error.isUnexpected() && error.stack) {
24
+ lines.push('');
25
+ lines.push(chalk.bold('Stack'));
26
+ error.stack.split('\n').forEach((line) => lines.push(chalk.gray(line)));
27
+ }
28
+ const details = error.getDetails();
29
+ if (details) {
30
+ lines.push('');
31
+ lines.push(chalk.bold('Details'));
32
+ details.split('\n').forEach((line) => lines.push(line));
33
+ }
34
+ lines.push('');
35
+ let prefix = '';
36
+ if (error.isUnexpected()) {
37
+ prefix = '[' + chalk.red(chalk.bold('UNEXPECTED_ERROR')) + ']';
38
+ } else {
39
+ prefix = '[' + chalk.red(chalk.bold('ERROR')) + ']';
40
+ }
41
+ lines.push(`${prefix} ${error.getMessage()}`);
42
+ const suggestionsByRole = error.getSuggestionsByRole();
43
+ if (suggestionsByRole) {
44
+ if ((suggestionsByRole.default?.length ?? 0) > 0) {
45
+ lines.push('');
46
+ lines.push(chalk.bold(`Suggestions`));
47
+ suggestionsByRole.default?.forEach((suggestion) => {
48
+ lines.push(suggestion);
49
+ });
50
+ }
51
+ if ((suggestionsByRole.rnAppDeveloper?.length ?? 0) > 0) {
52
+ lines.push('');
53
+ lines.push(chalk.bold(`Suggestions for RN App developers`));
54
+ suggestionsByRole.rnAppDeveloper?.forEach((suggestion) => {
55
+ lines.push(suggestion);
56
+ });
57
+ }
58
+ if (suggestionsByRole.rnPackageDeveloper?.length ?? 0) {
59
+ lines.push('');
60
+ lines.push(chalk.bold(`Suggestions for RN package developers`));
61
+ suggestionsByRole.rnPackageDeveloper?.forEach((suggestion) => {
62
+ lines.push(suggestion);
63
+ });
64
+ }
65
+ }
66
+ console.error(lines.join('\n'));
67
+ }
68
+ }
package/src/io/TarGz.ts CHANGED
@@ -1,26 +1,26 @@
1
- import fs from 'node:fs';
2
- import zlib from 'zlib';
3
- import tar from 'tar';
4
- import { AbsolutePath } from '../core';
5
-
6
- export function unpackTarGz(
7
- archivePath: AbsolutePath,
8
- outputDirPath: AbsolutePath
9
- ) {
10
- if (!fs.existsSync(outputDirPath.getValue())) {
11
- fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
12
- }
13
- const readStream = fs.createReadStream(archivePath.getValue());
14
- const writeStream = tar.extract({
15
- cwd: outputDirPath.getValue(),
16
- });
17
- readStream.pipe(zlib.createGunzip()).pipe(writeStream);
18
- return new Promise((resolve, reject) => {
19
- writeStream.on('finish', () => {
20
- resolve(undefined);
21
- });
22
- writeStream.on('error', (err) => {
23
- reject(err);
24
- });
25
- });
26
- }
1
+ import fs from 'node:fs';
2
+ import zlib from 'zlib';
3
+ import tar from 'tar';
4
+ import { AbsolutePath } from '../core';
5
+
6
+ export function unpackTarGz(
7
+ archivePath: AbsolutePath,
8
+ outputDirPath: AbsolutePath
9
+ ) {
10
+ if (!fs.existsSync(outputDirPath.getValue())) {
11
+ fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
12
+ }
13
+ const readStream = fs.createReadStream(archivePath.getValue());
14
+ const writeStream = tar.extract({
15
+ cwd: outputDirPath.getValue(),
16
+ });
17
+ readStream.pipe(zlib.createGunzip()).pipe(writeStream);
18
+ return new Promise((resolve, reject) => {
19
+ writeStream.on('finish', () => {
20
+ resolve(undefined);
21
+ });
22
+ writeStream.on('error', (err) => {
23
+ reject(err);
24
+ });
25
+ });
26
+ }
package/src/io/fsUtils.ts CHANGED
@@ -1,24 +1,24 @@
1
- import pathUtils from 'node:path';
2
- import fs from 'node:fs';
3
- import { AbsolutePath } from '../core';
4
-
5
- export function findFilePathsWithExtensions(
6
- dirPath: AbsolutePath,
7
- fileExtensions: readonly string[]
8
- ): AbsolutePath[] {
9
- let results: AbsolutePath[] = [];
10
- const files = fs.readdirSync(dirPath.getValue(), { withFileTypes: true });
11
- for (const file of files) {
12
- const path = dirPath.copyWithNewSegment(file.name);
13
- if (file.isDirectory()) {
14
- results = results.concat(
15
- findFilePathsWithExtensions(path, fileExtensions)
16
- );
17
- } else if (
18
- fileExtensions.includes(pathUtils.extname(file.name).substring(1))
19
- ) {
20
- results.push(path);
21
- }
22
- }
23
- return results;
24
- }
1
+ import pathUtils from 'node:path';
2
+ import fs from 'node:fs';
3
+ import { AbsolutePath } from '../core';
4
+
5
+ export function findFilePathsWithExtensions(
6
+ dirPath: AbsolutePath,
7
+ fileExtensions: readonly string[]
8
+ ): AbsolutePath[] {
9
+ let results: AbsolutePath[] = [];
10
+ const files = fs.readdirSync(dirPath.getValue(), { withFileTypes: true });
11
+ for (const file of files) {
12
+ const path = dirPath.copyWithNewSegment(file.name);
13
+ if (file.isDirectory()) {
14
+ results = results.concat(
15
+ findFilePathsWithExtensions(path, fileExtensions)
16
+ );
17
+ } else if (
18
+ fileExtensions.includes(pathUtils.extname(file.name).substring(1))
19
+ ) {
20
+ results.push(path);
21
+ }
22
+ }
23
+ return results;
24
+ }
package/src/io/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './Logger';
2
- export * from './fsUtils';
3
- export * from './TarGz';
1
+ export * from './Logger';
2
+ export * from './fsUtils';
3
+ export * from './TarGz';
@@ -1,28 +1,28 @@
1
- import fs from 'node:fs';
2
- import { AbsolutePath } from '../../core';
3
- import { Check } from '../types';
4
-
5
- export function createHarmonyDirContainsOnlyHarsCheck(
6
- npmPackagePath: AbsolutePath,
7
- hasNpmPackageNativeCode: boolean
8
- ): Check {
9
- return {
10
- checkIf: 'harmony_directory_contains_only_one_har_file',
11
- run: async () => {
12
- if (!hasNpmPackageNativeCode) {
13
- return 'skip';
14
- }
15
- const harmonyPath = npmPackagePath
16
- .copyWithNewSegment('harmony')
17
- .getValue();
18
- const fileOrDirNames = fs.readdirSync(harmonyPath);
19
- if (fileOrDirNames.length !== 1) {
20
- return { status: 'fail', message: JSON.stringify(fileOrDirNames) };
21
- }
22
- if (!fileOrDirNames[0].endsWith('.har')) {
23
- return 'fail';
24
- }
25
- return 'pass';
26
- },
27
- };
28
- }
1
+ import fs from 'node:fs';
2
+ import { AbsolutePath } from '../../core';
3
+ import { Check } from '../types';
4
+
5
+ export function createHarmonyDirContainsOnlyHarsCheck(
6
+ npmPackagePath: AbsolutePath,
7
+ hasNpmPackageNativeCode: boolean
8
+ ): Check {
9
+ return {
10
+ checkIf: 'harmony_directory_contains_only_one_har_file',
11
+ run: async () => {
12
+ if (!hasNpmPackageNativeCode) {
13
+ return 'skip';
14
+ }
15
+ const harmonyPath = npmPackagePath
16
+ .copyWithNewSegment('harmony')
17
+ .getValue();
18
+ const fileOrDirNames = fs.readdirSync(harmonyPath);
19
+ if (fileOrDirNames.length !== 1) {
20
+ return { status: 'fail', message: JSON.stringify(fileOrDirNames) };
21
+ }
22
+ if (!fileOrDirNames[0].endsWith('.har')) {
23
+ return 'fail';
24
+ }
25
+ return 'pass';
26
+ },
27
+ };
28
+ }
@@ -1,24 +1,24 @@
1
- import fs from 'node:fs';
2
- import { AbsolutePath } from '../../core';
3
- import { Check } from '../types';
4
-
5
- export function createHarmonyDirExistsCheck(
6
- packagePath: AbsolutePath,
7
- hasNativeCode: boolean
8
- ): Check {
9
- return {
10
- checkIf: 'package_has_harmony_dir',
11
- run: async () => {
12
- const harmonyDirExist = fs.existsSync(
13
- packagePath.copyWithNewSegment('harmony').getValue()
14
- );
15
- if (!hasNativeCode) {
16
- return 'skip';
17
- }
18
- if (!harmonyDirExist) {
19
- return 'fail';
20
- }
21
- return 'pass';
22
- },
23
- };
24
- }
1
+ import fs from 'node:fs';
2
+ import { AbsolutePath } from '../../core';
3
+ import { Check } from '../types';
4
+
5
+ export function createHarmonyDirExistsCheck(
6
+ packagePath: AbsolutePath,
7
+ hasNativeCode: boolean
8
+ ): Check {
9
+ return {
10
+ checkIf: 'package_has_harmony_dir',
11
+ run: async () => {
12
+ const harmonyDirExist = fs.existsSync(
13
+ packagePath.copyWithNewSegment('harmony').getValue()
14
+ );
15
+ if (!hasNativeCode) {
16
+ return 'skip';
17
+ }
18
+ if (!harmonyDirExist) {
19
+ return 'fail';
20
+ }
21
+ return 'pass';
22
+ },
23
+ };
24
+ }
@@ -1,18 +1,18 @@
1
- import { Check } from '../types';
2
-
3
- export function createNpmAndOhPackageVersionsAreEqualCheck(
4
- npmPackageVersion: string,
5
- ohPackageVersion: string
6
- ): Check {
7
- return {
8
- checkIf: 'npm_and_oh_package_versions_are_equal',
9
- run: async () => {
10
- return npmPackageVersion === ohPackageVersion
11
- ? 'pass'
12
- : {
13
- status: 'fail',
14
- message: `expected OH package version (${ohPackageVersion}) to match NPM version (${npmPackageVersion})`,
15
- };
16
- },
17
- };
18
- }
1
+ import { Check } from '../types';
2
+
3
+ export function createNpmAndOhPackageVersionsAreEqualCheck(
4
+ npmPackageVersion: string,
5
+ ohPackageVersion: string
6
+ ): Check {
7
+ return {
8
+ checkIf: 'npm_and_oh_package_versions_are_equal',
9
+ run: async () => {
10
+ return npmPackageVersion === ohPackageVersion
11
+ ? 'pass'
12
+ : {
13
+ status: 'fail',
14
+ message: `expected OH package version (${ohPackageVersion}) to match NPM version (${npmPackageVersion})`,
15
+ };
16
+ },
17
+ };
18
+ }
@@ -1,47 +1,47 @@
1
- import { Check } from '../types';
2
-
3
- export function createOhPackageNameFollowsNamingConventionCheck(
4
- npmPackageName: string,
5
- ohPackageName: string
6
- ): Check {
7
- const npmPackageNameInfo = getPackageNameInfo(npmPackageName);
8
- return {
9
- checkIf: 'oh_package_name_is_derived_from_npm_package_name',
10
- run: async () => {
11
- if (npmPackageNameInfo.organizationName) {
12
- const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.organizationName}--${npmPackageNameInfo.unscopedName}`;
13
- return expectedOHPackageName === ohPackageName
14
- ? 'pass'
15
- : {
16
- status: 'fail',
17
- message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
18
- };
19
- } else {
20
- const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.unscopedName}`;
21
- return expectedOHPackageName === ohPackageName
22
- ? 'pass'
23
- : {
24
- status: 'fail',
25
- message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
26
- };
27
- }
28
- },
29
- };
30
- }
31
-
32
- type PackageNameInfo = {
33
- organizationName: string | null;
34
- unscopedName: string;
35
- };
36
-
37
- function getPackageNameInfo(packageName: string): PackageNameInfo {
38
- if (packageName.startsWith('@') && packageName.includes('/')) {
39
- const [part1, part2] = packageName.split('/');
40
- return {
41
- organizationName: part1.replace('@', ''),
42
- unscopedName: part2,
43
- };
44
- } else {
45
- return { organizationName: null, unscopedName: packageName };
46
- }
47
- }
1
+ import { Check } from '../types';
2
+
3
+ export function createOhPackageNameFollowsNamingConventionCheck(
4
+ npmPackageName: string,
5
+ ohPackageName: string
6
+ ): Check {
7
+ const npmPackageNameInfo = getPackageNameInfo(npmPackageName);
8
+ return {
9
+ checkIf: 'oh_package_name_is_derived_from_npm_package_name',
10
+ run: async () => {
11
+ if (npmPackageNameInfo.organizationName) {
12
+ const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.organizationName}--${npmPackageNameInfo.unscopedName}`;
13
+ return expectedOHPackageName === ohPackageName
14
+ ? 'pass'
15
+ : {
16
+ status: 'fail',
17
+ message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
18
+ };
19
+ } else {
20
+ const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.unscopedName}`;
21
+ return expectedOHPackageName === ohPackageName
22
+ ? 'pass'
23
+ : {
24
+ status: 'fail',
25
+ message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
26
+ };
27
+ }
28
+ },
29
+ };
30
+ }
31
+
32
+ type PackageNameInfo = {
33
+ organizationName: string | null;
34
+ unscopedName: string;
35
+ };
36
+
37
+ function getPackageNameInfo(packageName: string): PackageNameInfo {
38
+ if (packageName.startsWith('@') && packageName.includes('/')) {
39
+ const [part1, part2] = packageName.split('/');
40
+ return {
41
+ organizationName: part1.replace('@', ''),
42
+ unscopedName: part2,
43
+ };
44
+ } else {
45
+ return { organizationName: null, unscopedName: packageName };
46
+ }
47
+ }
@@ -1,4 +1,4 @@
1
- export * from './HarmonyDirExistsCheck';
2
- export * from './HarmonyDirContainsOnlyHarsCheck';
3
- export * from './NpmAnAndOhPackageVersionsAreEqual';
4
- export * from './OhPackageNameFollowsNamingConventionCheck';
1
+ export * from './HarmonyDirExistsCheck';
2
+ export * from './HarmonyDirContainsOnlyHarsCheck';
3
+ export * from './NpmAnAndOhPackageVersionsAreEqual';
4
+ export * from './OhPackageNameFollowsNamingConventionCheck';
@@ -1,2 +1,2 @@
1
- export * from './types';
2
- export * from './verify-package';
1
+ export * from './types';
2
+ export * from './verify-package';
@@ -1,12 +1,12 @@
1
- export type CheckStatus = 'pass' | 'fail' | 'skip';
2
-
3
- export type Check = {
4
- checkIf: string;
5
- run: () => Promise<CheckStatus | { status: CheckStatus; message: string }>;
6
- };
7
-
8
- export type CheckResult = {
9
- name: string;
10
- status: CheckStatus;
11
- message: string;
12
- };
1
+ export type CheckStatus = 'pass' | 'fail' | 'skip';
2
+
3
+ export type Check = {
4
+ checkIf: string;
5
+ run: () => Promise<CheckStatus | { status: CheckStatus; message: string }>;
6
+ };
7
+
8
+ export type CheckResult = {
9
+ name: string;
10
+ status: CheckStatus;
11
+ message: string;
12
+ };