@react-native-oh/react-native-harmony-cli 0.0.37 → 0.0.40-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 (84) hide show
  1. package/dist/autolinking/Autolinking.js +14 -11
  2. package/dist/codegen/generators/UberGeneratorV1.js +9 -2
  3. package/dist/codegen/generators/UberGeneratorV2.js +8 -1
  4. package/dist/commands/codegen-harmony.js +16 -5
  5. package/dist/commands/run-harmony.js +0 -2
  6. package/dist/core/ProjectDependenciesManager.js +5 -7
  7. package/dist/simulator/LaunchSimulator.js +9 -2
  8. package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
  9. package/package.json +10 -2
  10. package/.prettierrc +0 -6
  11. package/src/assetResolver.ts +0 -134
  12. package/src/autolinking/Autolinking.test.ts +0 -483
  13. package/src/autolinking/Autolinking.ts +0 -382
  14. package/src/autolinking/index.ts +0 -8
  15. package/src/codegen/core/CodeGenerator.ts +0 -16
  16. package/src/codegen/core/CodegenError.ts +0 -10
  17. package/src/codegen/core/EventUtils.ts +0 -23
  18. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  19. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  20. package/src/codegen/core/UberSchema.ts +0 -152
  21. package/src/codegen/core/index.ts +0 -12
  22. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -124
  23. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  24. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  25. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  26. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  27. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  28. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  29. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  30. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  31. package/src/codegen/generators/index.ts +0 -15
  32. package/src/codegen/index.ts +0 -9
  33. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  34. package/src/codegen/templates/BasePackageHTemplate.ts +0 -159
  35. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  36. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  37. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  38. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  39. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -150
  40. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  41. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  42. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  43. package/src/codegen/templates/index.ts +0 -16
  44. package/src/commands/bundle-harmony.ts +0 -134
  45. package/src/commands/codegen-harmony.ts +0 -297
  46. package/src/commands/codegen-lib-harmony.ts +0 -389
  47. package/src/commands/create-metro-host-constants.ts +0 -55
  48. package/src/commands/index.ts +0 -16
  49. package/src/commands/init.ts +0 -755
  50. package/src/commands/link-harmony.ts +0 -102
  51. package/src/commands/pack-harmony.ts +0 -128
  52. package/src/commands/run-harmony.ts +0 -506
  53. package/src/commands/types.ts +0 -21
  54. package/src/commands/unpack-harmony.ts +0 -238
  55. package/src/commands/verify-package-harmony.ts +0 -113
  56. package/src/core/AbsolutePath.ts +0 -66
  57. package/src/core/CodegenConfig.ts +0 -67
  58. package/src/core/DescriptiveError.ts +0 -68
  59. package/src/core/FileSystem.ts +0 -57
  60. package/src/core/OHPackageJSON5.ts +0 -30
  61. package/src/core/PackageJSON.ts +0 -104
  62. package/src/core/ProjectDependenciesManager.ts +0 -103
  63. package/src/core/ValidationError.ts +0 -8
  64. package/src/core/ValueObject.ts +0 -9
  65. package/src/core/fs.ts +0 -38
  66. package/src/core/index.ts +0 -17
  67. package/src/index.ts +0 -33
  68. package/src/io/CliExecutor.ts +0 -69
  69. package/src/io/Logger.ts +0 -112
  70. package/src/io/RealFS.ts +0 -62
  71. package/src/io/TarGz.ts +0 -33
  72. package/src/io/__fixtures__.ts +0 -139
  73. package/src/io/fsUtils.ts +0 -44
  74. package/src/io/index.ts +0 -11
  75. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  76. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  77. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  78. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  79. package/src/package-verifier/checks/index.ts +0 -11
  80. package/src/package-verifier/index.ts +0 -9
  81. package/src/package-verifier/types.ts +0 -19
  82. package/src/package-verifier/verify-package.ts +0 -123
  83. package/src/simulator/LaunchSimulator.ts +0 -352
  84. package/src/simulator/index.ts +0 -8
@@ -1,382 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import JSON5 from 'json5';
9
- import {
10
- AbsolutePath,
11
- ProjectDependenciesManager,
12
- FS,
13
- DescriptiveError,
14
- } from '../core';
15
- import Mustache from 'mustache';
16
- import Case from 'case';
17
- import { Logger } from '../io';
18
-
19
- type Version = string;
20
- type DependencySpecifier = `file:${string}` | Version;
21
-
22
- export type AutolinkingConfig = {
23
- harmonyProjectPath: AbsolutePath;
24
- nodeModulesPath: AbsolutePath;
25
- ohPackagePathRelativeToHarmony: string;
26
- etsRNOHPackagesFactoryPathRelativeToHarmony: string;
27
- cppRNOHPackagesFactoryPathRelativeToHarmony: string;
28
- cmakeAutolinkPathRelativeToHarmony: string;
29
- excludedNpmPackageNames: Set<string>;
30
- includedNpmPackageNames: Set<string>;
31
- };
32
-
33
- type AutolinkableLibrary = {
34
- npmPackageName: string;
35
- harFilePathRelativeToHarmony: string;
36
- etsRNOHPackageClassName?: string;
37
- cppRNOHPackageClassName?: string;
38
- cmakeLibraryTargetName?: string;
39
- ohPackageName?: string;
40
- };
41
-
42
- type AutolinkingInput = {
43
- projectRootPath: AbsolutePath;
44
- etsRNOHPackagesFactoryPath: AbsolutePath;
45
- cppRNOHPackagesFactoryPath: AbsolutePath;
46
- cmakeAutolinkingPath: AbsolutePath;
47
- ohPackagePathAndContent: [AbsolutePath, string];
48
- autolinkableLibraries: AutolinkableLibrary[];
49
- nodeModuleHarFilePathsRelativeToHarmony: string[];
50
- skippedLibraryNpmPackageNames: string[];
51
- };
52
-
53
- type AutolinkingOutput = {
54
- linkedLibraryNpmPackageNames: string[];
55
- skippedLibraryNpmPackageNames: string[];
56
- projectRootPath: AbsolutePath;
57
- etsRNOHPackagesFactoryPathAndContent: [AbsolutePath, string];
58
- cppRNOHPackagesFactoryPathAndContent: [AbsolutePath, string];
59
- cmakeAutolinkingPathAndContent: [AbsolutePath, string];
60
- ohPackagePathAndContent: [AbsolutePath, string];
61
- };
62
-
63
- const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
64
- /*
65
- * This file was generated by RNOH autolinking.
66
- * DO NOT modify it manually, your changes WILL be overwritten.
67
- */
68
- import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
69
- {{#libraries}}
70
- import {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';
71
- {{/libraries}}
72
-
73
- export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
74
- return [
75
- {{#libraries}}
76
- new {{etsRNOHPackageClassName}}(ctx),
77
- {{/libraries}}
78
- ];
79
- }
80
- `.trimStart();
81
-
82
- const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
83
- /*
84
- * This file was generated by RNOH autolinking.
85
- * DO NOT modify it manually, your changes WILL be overwritten.
86
- */
87
- // clang-format off
88
- #pragma once
89
- #include "RNOH/Package.h"
90
- {{#libraries}}
91
- #include "{{etsRNOHPackageClassName}}.h"
92
- {{/libraries}}
93
-
94
- std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
95
- return {
96
- {{#libraries}}
97
- std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),
98
- {{/libraries}}
99
- };
100
- }
101
- `.trimStart();
102
-
103
- const CMAKE_AUTOLINKING_TEMPLATE = `
104
- # This file was generated by RNOH autolinking.
105
- # DO NOT modify it manually, your changes WILL be overwritten.
106
- cmake_minimum_required(VERSION 3.5)
107
-
108
- # @api
109
- function(autolink_libraries target)
110
- {{#libraries}}
111
- add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
112
- {{/libraries}}
113
-
114
- set(AUTOLINKED_LIBRARIES
115
- {{#libraries}}
116
- {{cmakeLibraryTargetName}}
117
- {{/libraries}}
118
- )
119
-
120
- foreach(lib \${AUTOLINKED_LIBRARIES})
121
- target_link_libraries(\${target} PUBLIC \${lib})
122
- endforeach()
123
- endfunction()
124
- `.trimStart();
125
-
126
- export class Autolinking {
127
- constructor(private fs: FS, private logger: Logger) {}
128
-
129
- async prepareInput(config: AutolinkingConfig): Promise<AutolinkingInput> {
130
- if (
131
- config.includedNpmPackageNames.size > 0 &&
132
- config.excludedNpmPackageNames.size > 0
133
- ) {
134
- throw new DescriptiveError({
135
- whatHappened: 'Tried to exclude and include npm packages.',
136
- whatCanUserDo: ['Include or exclude npm packages, but not both.'],
137
-
138
- extraData: {
139
- includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
140
- excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
141
- includedNpmPackageNames: config.includedNpmPackageNames,
142
- excludedNpmPackageNames: config.excludedNpmPackageNames,
143
- },
144
- });
145
- }
146
- const harmonyProjectPath =
147
- config.harmonyProjectPath ?? new AbsolutePath('./');
148
- const nodeModuleHarPaths: AbsolutePath[] = [];
149
- const autolinkableLibraries: AutolinkableLibrary[] = [];
150
- const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
151
- const skippedLibraryNpmPackageNames: string[] = [];
152
- await new ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync(
153
- (dependency) => {
154
- const harFilePath = dependency.getHarFilePath();
155
- if (!harFilePath) {
156
- return;
157
- }
158
- nodeModuleHarPaths.push(harFilePath);
159
- const packageJson = dependency.readPackageJSON();
160
- const providedAutolinkingConfig = packageJson.harmony?.autolinking;
161
-
162
- if (
163
- providedAutolinkingConfig === undefined ||
164
- providedAutolinkingConfig === null ||
165
- (config.excludedNpmPackageNames.has(packageJson.name) &&
166
- config.excludedNpmPackageNames.size > 0) ||
167
- (!config.includedNpmPackageNames.has(packageJson.name) &&
168
- config.includedNpmPackageNames.size > 0)
169
- ) {
170
- skippedLibraryNpmPackageNames.push(packageJson.name);
171
- return;
172
- }
173
- const autolinkingConfig =
174
- providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
175
- autolinkableLibraries.push({
176
- npmPackageName: packageJson.name,
177
- etsRNOHPackageClassName: autolinkingConfig?.etsPackageClassName,
178
- cppRNOHPackageClassName: autolinkingConfig?.cppPackageClassName,
179
- cmakeLibraryTargetName: autolinkingConfig?.cmakeLibraryTargetName,
180
- ohPackageName: autolinkingConfig?.ohPackageName,
181
- harFilePathRelativeToHarmony: harFilePath
182
- .relativeTo(harmonyProjectPath)
183
- .toString(),
184
- });
185
- }
186
- );
187
- const ohPackagePath = harmonyProjectPath.copyWithNewSegment(
188
- config.ohPackagePathRelativeToHarmony
189
- );
190
- const ohPackageContent = await this.fs.readText(ohPackagePath);
191
- const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(
192
- config.cppRNOHPackagesFactoryPathRelativeToHarmony
193
- );
194
- const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(
195
- config.cmakeAutolinkPathRelativeToHarmony
196
- );
197
- return {
198
- projectRootPath,
199
- skippedLibraryNpmPackageNames,
200
- etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(
201
- config.etsRNOHPackagesFactoryPathRelativeToHarmony
202
- ),
203
- cppRNOHPackagesFactoryPath,
204
- cmakeAutolinkingPath: cmakeAutolinkingPath,
205
- ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
206
- autolinkableLibraries,
207
- nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) =>
208
- p.relativeTo(harmonyProjectPath).toString()
209
- ),
210
- };
211
- }
212
-
213
- evaluate(input: AutolinkingInput): AutolinkingOutput {
214
- const autolinkableLibraries: Required<AutolinkableLibrary>[] =
215
- input.autolinkableLibraries.map((lib) => {
216
- return {
217
- ...lib,
218
- etsRNOHPackageClassName:
219
- lib.etsRNOHPackageClassName ??
220
- this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
221
- cppRNOHPackageClassName:
222
- lib.cppRNOHPackageClassName ??
223
- this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName),
224
- cmakeLibraryTargetName:
225
- lib.cmakeLibraryTargetName ??
226
- this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName),
227
- ohPackageName:
228
- lib.ohPackageName ??
229
- this.npmPackageNameToOHPackageName(lib.npmPackageName),
230
- };
231
- });
232
- autolinkableLibraries.sort((a, b) => {
233
- if (a.npmPackageName < b.npmPackageName) return -1;
234
- if (a.npmPackageName > b.npmPackageName) return 1;
235
- return 0;
236
- });
237
- const ohPackage = JSON5.parse(input.ohPackagePathAndContent[1]);
238
- const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map(
239
- (lib) => lib.harFilePathRelativeToHarmony
240
- );
241
- const unmanagedNativeDependencySpecifierByName: Record<
242
- string,
243
- DependencySpecifier
244
- > = {};
245
- Object.entries<DependencySpecifier>(ohPackage.dependencies).forEach(
246
- ([name, dependencySpecifier]) => {
247
- if (!dependencySpecifier.includes('file:')) {
248
- unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
249
- } else {
250
- const harFilePathRelativeToHarmony = dependencySpecifier.replace(
251
- 'file:',
252
- ''
253
- );
254
- if (
255
- !autolinkableHarFilePathsRelativeToHarmony.includes(
256
- harFilePathRelativeToHarmony
257
- ) &&
258
- input.nodeModuleHarFilePathsRelativeToHarmony.includes(
259
- harFilePathRelativeToHarmony
260
- )
261
- ) {
262
- unmanagedNativeDependencySpecifierByName[name] =
263
- dependencySpecifier;
264
- }
265
- }
266
- }
267
- );
268
- const managedNativeDependencySpecifierByName: Record<string, string> = {};
269
- for (const library of autolinkableLibraries) {
270
- managedNativeDependencySpecifierByName[library.ohPackageName] =
271
- 'file:' + library.harFilePathRelativeToHarmony;
272
- }
273
- return {
274
- skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
275
- linkedLibraryNpmPackageNames: autolinkableLibraries.map(
276
- (lib) => lib.npmPackageName
277
- ),
278
- projectRootPath: input.projectRootPath,
279
- cppRNOHPackagesFactoryPathAndContent: [
280
- input.cppRNOHPackagesFactoryPath,
281
- Mustache.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
282
- libraries: autolinkableLibraries,
283
- }),
284
- ],
285
- etsRNOHPackagesFactoryPathAndContent: [
286
- input.etsRNOHPackagesFactoryPath,
287
- Mustache.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
288
- libraries: autolinkableLibraries,
289
- }),
290
- ],
291
- cmakeAutolinkingPathAndContent: [
292
- input.cmakeAutolinkingPath,
293
- Mustache.render(CMAKE_AUTOLINKING_TEMPLATE, {
294
- libraries: autolinkableLibraries,
295
- }),
296
- ],
297
- ohPackagePathAndContent: [
298
- input.ohPackagePathAndContent[0],
299
- JSON5.stringify(
300
- {
301
- ...ohPackage,
302
- dependencies: {
303
- ...unmanagedNativeDependencySpecifierByName,
304
- ...managedNativeDependencySpecifierByName,
305
- },
306
- },
307
- { space: 2, quote: '"' }
308
- ) + '\n',
309
- ],
310
- };
311
- }
312
-
313
- private npmPackageNameToRNOHPackageClassName(fullNpmPackageName: string) {
314
- if (fullNpmPackageName.startsWith('@')) {
315
- const [scopeName, packageName] = fullNpmPackageName
316
- .replace('@', '')
317
- .split('/');
318
- return Case.pascal(scopeName) + Case.pascal(packageName) + 'Package';
319
- }
320
- return Case.pascal(fullNpmPackageName) + 'Package';
321
- }
322
-
323
- private npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName: string) {
324
- if (fullNpmPackageName.startsWith('@')) {
325
- const [scopeName, packageName] = fullNpmPackageName
326
- .replace('@', '')
327
- .split('/');
328
- return 'rnoh__' + Case.snake(scopeName) + '__' + Case.snake(packageName);
329
- }
330
- return 'rnoh__' + Case.snake(fullNpmPackageName);
331
- }
332
-
333
- private npmPackageNameToOHPackageName(fullNpmPackageName: string): string {
334
- if (fullNpmPackageName.startsWith('@')) {
335
- const [scopeName, packageName] = fullNpmPackageName
336
- .replace('@', '')
337
- .split('/');
338
- return '@rnoh/' + Case.kebab(scopeName) + '--' + Case.kebab(packageName);
339
- }
340
- return '@rnoh/' + Case.kebab(fullNpmPackageName);
341
- }
342
-
343
- saveAndLogOutput(output: AutolinkingOutput) {
344
- const pathAndContentPairs: [AbsolutePath, string][] = [];
345
- pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
346
- pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
347
- pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
348
- pathAndContentPairs.push(output.ohPackagePathAndContent);
349
- pathAndContentPairs.forEach(([path, content]) => {
350
- this.fs.writeTextSync(path, content);
351
- });
352
- output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
353
- this.logger.debug(
354
- (styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`
355
- );
356
- });
357
- output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
358
- this.logger.debug(
359
- (styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`
360
- );
361
- });
362
- this.logger.debug(() => '');
363
- const sortedPathsRelativeToRoot = pathAndContentPairs
364
- .map(([path]) => path.relativeTo(output.projectRootPath).toString())
365
- .sort();
366
- sortedPathsRelativeToRoot.forEach((pathStr) => {
367
- this.logger.debug((styles) => styles.gray(`• ${pathStr}`));
368
- });
369
- this.logger.debug(() => '');
370
- this.logger.info(
371
- (styles) =>
372
- `updated ${styles.green(
373
- styles.bold(sortedPathsRelativeToRoot.length)
374
- )} file(s), linked ${styles.green(
375
- styles.bold(output.linkedLibraryNpmPackageNames.length)
376
- )} libraries, skipped ${styles.yellow(
377
- styles.bold(output.skippedLibraryNpmPackageNames.length)
378
- )} libraries`
379
- );
380
- this.logger.debug(() => '');
381
- }
382
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- export * from './Autolinking';
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { AbsolutePath } from '../../core';
9
- import { SpecSchema } from './UberSchema';
10
-
11
- type FileContent = string;
12
- export interface CodeGenerator<T> {
13
- generate(data: T): Map<AbsolutePath, FileContent>;
14
- }
15
-
16
- export interface SpecCodeGenerator extends CodeGenerator<SpecSchema> {}
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { DescriptiveError } from '../../core';
9
-
10
- export class CodegenError extends DescriptiveError {}
@@ -1,23 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { CodegenError } from './CodegenError';
9
-
10
- export function createEventNameFromEventHandlerName(
11
- eventHandlerName: string
12
- ): string {
13
- const eventName = eventHandlerName.replace('on', '');
14
- if (eventName.length === 0) {
15
- throw new CodegenError({
16
- whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
17
- whatCanUserDo: [
18
- 'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
19
- ],
20
- });
21
- }
22
- return eventName.charAt(0).toLowerCase() + eventName.slice(1);
23
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
9
-
10
- function convert(typeAnnotation: TypeAnnotation) {
11
- return new TypeAnnotationToTS().convert(typeAnnotation);
12
- }
13
-
14
- it('should convert boolean prop correctly', () => {
15
- const result = convert({
16
- type: 'BooleanTypeAnnotation',
17
- });
18
-
19
- expect(result).toBe('boolean');
20
- });
21
-
22
- it('should convert string prop correctly', () => {
23
- const result = convert({
24
- type: 'StringTypeAnnotation',
25
- });
26
-
27
- expect(result).toBe('string');
28
- });
29
-
30
- it('should convert double prop correctly', () => {
31
- const result = convert({
32
- type: 'DoubleTypeAnnotation',
33
- });
34
-
35
- expect(result).toBe('number');
36
- });
37
-
38
- it('should convert float prop correctly', () => {
39
- const result = convert({
40
- type: 'FloatTypeAnnotation',
41
- });
42
-
43
- expect(result).toBe('number');
44
- });
45
-
46
- it('should convert object prop correctly', () => {
47
- const result = convert({
48
- type: 'ObjectTypeAnnotation',
49
- properties: [
50
- {
51
- typeAnnotation: { type: 'BooleanTypeAnnotation' },
52
- name: 'booleanTest',
53
- optional: false,
54
- },
55
- {
56
- typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [] },
57
- name: 'objectTest',
58
- optional: true,
59
- },
60
- ],
61
- });
62
-
63
- expect(result).toBe('{booleanTest: boolean, objectTest?: {}}');
64
- });
65
-
66
- it('should convert array correctly', () => {
67
- const result = convert({
68
- type: 'ObjectTypeAnnotation',
69
- properties: [
70
- {
71
- typeAnnotation: {
72
- type: 'ArrayTypeAnnotation',
73
- elementType: { type: 'StringTypeAnnotation' },
74
- },
75
- name: 'arrayTest',
76
- optional: false,
77
- },
78
- ],
79
- });
80
-
81
- expect(result).toBe('{arrayTest: string[]}');
82
- });