@react-native-oh/react-native-harmony-cli 0.0.24 → 0.0.26
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.
- package/.prettierrc +6 -6
- package/jest.config.js +5 -5
- package/package.json +57 -52
- package/react-native.config.js +10 -10
- package/src/assetResolver.ts +21 -44
- package/src/codegen/core/CodeGenerator.ts +9 -0
- package/src/codegen/core/CodegenError.ts +3 -3
- package/src/codegen/core/EventUtils.ts +18 -18
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
- package/src/codegen/core/UberSchema.ts +142 -99
- package/src/codegen/core/index.ts +5 -5
- package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
- package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
- package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
- package/src/codegen/generators/UberGeneratorV1.ts +64 -0
- package/src/codegen/generators/UberGeneratorV2.ts +91 -0
- package/src/codegen/generators/index.ts +6 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
- package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
- package/src/codegen/templates/IndexTSTemplate.ts +53 -33
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
- package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
- package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
- package/src/codegen/templates/index.ts +9 -8
- package/src/commands/bundle-harmony.ts +203 -202
- package/src/commands/codegen-harmony.ts +272 -143
- package/src/commands/create-metro-host-constants.ts +48 -48
- package/src/commands/index.ts +6 -5
- package/src/commands/pack-harmony.ts +121 -121
- package/src/commands/unpack-harmony.ts +231 -231
- package/src/commands/verify-package-harmony.ts +106 -0
- package/src/core/AbsolutePath.ts +50 -43
- package/src/core/CodegenConfig.ts +62 -54
- package/src/core/DescriptiveError.ts +61 -61
- package/src/core/OHPackageJSON5.ts +23 -0
- package/src/core/PackageJSON.ts +75 -63
- package/src/core/ProjectDependenciesManager.ts +77 -77
- package/src/core/ValidationError.ts +1 -1
- package/src/core/ValueObject.ts +2 -2
- package/src/core/fs.ts +31 -31
- package/src/core/index.ts +9 -8
- package/src/index.ts +20 -18
- package/src/io/Logger.ts +68 -68
- package/src/io/TarGz.ts +26 -0
- package/src/io/fsUtils.ts +24 -24
- package/src/io/index.ts +3 -2
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -0
- package/src/package-verifier/checks/index.ts +4 -0
- package/src/package-verifier/index.ts +2 -0
- package/src/package-verifier/types.ts +12 -0
- package/src/package-verifier/verify-package.ts +117 -0
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/dist/assetResolver.js +0 -41
- package/dist/codegen/core/Codegen.js +0 -35
- package/dist/codegen/core/CodegenError.js +0 -7
- package/dist/codegen/core/EventUtils.js +0 -19
- package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
- package/dist/codegen/core/UberSchema.js +0 -74
- package/dist/codegen/core/index.js +0 -21
- package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/dist/codegen/generators/index.js +0 -19
- package/dist/codegen/index.js +0 -18
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
- package/dist/codegen/templates/IndexTSTemplate.js +0 -31
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
- package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
- package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
- package/dist/codegen/templates/index.js +0 -24
- package/dist/commands/bundle-harmony.js +0 -179
- package/dist/commands/codegen-harmony.js +0 -110
- package/dist/commands/create-metro-host-constants.js +0 -61
- package/dist/commands/index.js +0 -21
- package/dist/commands/pack-harmony.js +0 -100
- package/dist/commands/unpack-harmony.js +0 -184
- package/dist/core/AbsolutePath.js +0 -41
- package/dist/core/CodegenConfig.js +0 -53
- package/dist/core/DescriptiveError.js +0 -49
- package/dist/core/PackageJSON.js +0 -53
- package/dist/core/ProjectDependenciesManager.js +0 -70
- package/dist/core/ValidationError.js +0 -6
- package/dist/core/ValueObject.js +0 -2
- package/dist/core/fs.js +0 -36
- package/dist/core/index.js +0 -24
- package/dist/index.js +0 -13
- package/dist/io/Logger.js +0 -71
- package/dist/io/fsUtils.js +0 -23
- package/dist/io/index.js +0 -18
- package/src/codegen/core/Codegen.ts +0 -44
- package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
package/.prettierrc
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"trailingComma": "es5",
|
|
3
|
-
"tabWidth": 2,
|
|
4
|
-
"semi": true,
|
|
5
|
-
"singleQuote": true
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"trailingComma": "es5",
|
|
3
|
+
"tabWidth": 2,
|
|
4
|
+
"semi": true,
|
|
5
|
+
"singleQuote": true
|
|
6
|
+
}
|
package/jest.config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
};
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
};
|
package/package.json
CHANGED
|
@@ -1,52 +1,57 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@react-native-oh/react-native-harmony-cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"registry": "https://registry.npmjs.org/",
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "tsc --outDir dist -p tsconfig.build.json",
|
|
11
|
-
"prepack": "npm run build",
|
|
12
|
-
"verify": "tsc --noEmit && npm run test",
|
|
13
|
-
"test": "npm run build && jest",
|
|
14
|
-
"test:codegen": "jest ./src/codegen/.* && npm run build && jest tests/codegen.*",
|
|
15
|
-
"rn": "npm run build && react-native",
|
|
16
|
-
"prepublishOnly": "npm run verify"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [],
|
|
19
|
-
"author": "",
|
|
20
|
-
"license": "ISC",
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"metro": "*"
|
|
23
|
-
},
|
|
24
|
-
"main": "dist/index.js",
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"@react-native-community/cli-types": "^11.3.0",
|
|
27
|
-
"@types/
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/
|
|
30
|
-
"@types/
|
|
31
|
-
"@types/
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"ts-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-oh/react-native-harmony-cli",
|
|
3
|
+
"version": "0.0.26",
|
|
4
|
+
"description": "",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org/",
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc --outDir dist -p tsconfig.build.json",
|
|
11
|
+
"prepack": "npm run build",
|
|
12
|
+
"verify": "tsc --noEmit && npm run test",
|
|
13
|
+
"test": "npm run build && jest",
|
|
14
|
+
"test:codegen": "jest ./src/codegen/.* && npm run build && jest tests/codegen.*",
|
|
15
|
+
"rn": "npm run build && react-native",
|
|
16
|
+
"prepublishOnly": "npm run verify"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"metro": "*"
|
|
23
|
+
},
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@react-native-community/cli-types": "^11.3.0",
|
|
27
|
+
"@types/adm-zip": "^0.5.5",
|
|
28
|
+
"@types/fs-extra": "^11.0.1",
|
|
29
|
+
"@types/jest": "^29.5.1",
|
|
30
|
+
"@types/jszip": "^3.4.1",
|
|
31
|
+
"@types/mustache": "^4.2.5",
|
|
32
|
+
"@types/tar": "^6.1.5",
|
|
33
|
+
"@types/tmp": "^0.2.3",
|
|
34
|
+
"directory-tree": "^3.5.1",
|
|
35
|
+
"execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",
|
|
36
|
+
"jest": "^29.5.0",
|
|
37
|
+
"react-native": "^0.72.0",
|
|
38
|
+
"ts-jest": "^29.1.0",
|
|
39
|
+
"ts-node": "^10.9.1",
|
|
40
|
+
"typescript": "^5.0.4"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@react-native-community/cli-tools": "^13.6.5",
|
|
44
|
+
"@react-native/codegen": "0.74.0",
|
|
45
|
+
"@tsconfig/recommended": "^1.0.2",
|
|
46
|
+
"adm-zip": "^0.5.12",
|
|
47
|
+
"case": "^1.6.3",
|
|
48
|
+
"chalk": "^4",
|
|
49
|
+
"fs-extra": "^11.1.1",
|
|
50
|
+
"glob": "^10.2.6",
|
|
51
|
+
"ignore": "^5.2.4",
|
|
52
|
+
"json5": "^2.2.3",
|
|
53
|
+
"mustache": "^4.2.0",
|
|
54
|
+
"tar": "^6.1.15",
|
|
55
|
+
"tmp": "^0.2.1"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/react-native.config.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const { config: harmonyConfig } = require('./dist');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @type {import("@react-native-community/cli-types").Config}
|
|
5
|
-
*/
|
|
6
|
-
const config = {
|
|
7
|
-
commands: harmonyConfig.commands,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
module.exports = config;
|
|
1
|
+
const { config: harmonyConfig } = require('./dist');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import("@react-native-community/cli-types").Config}
|
|
5
|
+
*/
|
|
6
|
+
const config = {
|
|
7
|
+
commands: harmonyConfig.commands,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = config;
|
package/src/assetResolver.ts
CHANGED
|
@@ -1,44 +1,21 @@
|
|
|
1
|
-
import type { AssetData } from 'metro';
|
|
2
|
-
|
|
3
|
-
export type Asset = AssetData;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export function getAssetDestRelativePath(asset: Asset): string {
|
|
27
|
-
const fileName = getResourceIdentifier(asset);
|
|
28
|
-
return `${fileName}.${asset.type}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getResourceIdentifier(asset: Asset): string {
|
|
32
|
-
const folderPath = getBasePath(asset);
|
|
33
|
-
const fullAssetPath = `${folderPath}/${asset.name}.${asset.type}`.toLowerCase();
|
|
34
|
-
const assetPathHash = cyrb53(fullAssetPath);
|
|
35
|
-
return assetPathHash.toString(16);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getBasePath(asset: Asset): string {
|
|
39
|
-
let basePath = asset.httpServerLocation;
|
|
40
|
-
if (basePath[0] === '/') {
|
|
41
|
-
basePath = basePath.substr(1);
|
|
42
|
-
}
|
|
43
|
-
return basePath;
|
|
44
|
-
}
|
|
1
|
+
import type { AssetData } from 'metro';
|
|
2
|
+
|
|
3
|
+
export type Asset = AssetData;
|
|
4
|
+
|
|
5
|
+
export function getAssetDestRelativePath(asset: Asset): string {
|
|
6
|
+
const fileName = getResourceIdentifier(asset);
|
|
7
|
+
return `${fileName}.${asset.type}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getResourceIdentifier(asset: Asset): string {
|
|
11
|
+
const folderPath = getBasePath(asset);
|
|
12
|
+
return `${folderPath}/${asset.name}`.slice('assets/'.length);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getBasePath(asset: Asset): string {
|
|
16
|
+
let basePath = asset.httpServerLocation;
|
|
17
|
+
if (basePath[0] === '/') {
|
|
18
|
+
basePath = basePath.substr(1);
|
|
19
|
+
}
|
|
20
|
+
return basePath;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbsolutePath } from '../../core';
|
|
2
|
+
import { SpecSchema } from './UberSchema';
|
|
3
|
+
|
|
4
|
+
type FileContent = string;
|
|
5
|
+
export interface CodeGenerator<T> {
|
|
6
|
+
generate(data: T): Map<AbsolutePath, FileContent>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SpecCodeGenerator extends CodeGenerator<SpecSchema> {}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DescriptiveError } from '../../core';
|
|
2
|
-
|
|
3
|
-
export class CodegenError extends DescriptiveError {}
|
|
1
|
+
import { DescriptiveError } from '../../core';
|
|
2
|
+
|
|
3
|
+
export class CodegenError extends DescriptiveError {}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { CodegenError } from './CodegenError';
|
|
2
|
-
|
|
3
|
-
export function createEventNameFromEventHandlerName(
|
|
4
|
-
eventHandlerName: string
|
|
5
|
-
): string {
|
|
6
|
-
const eventName = eventHandlerName.replace('on', '');
|
|
7
|
-
if (eventName.length === 0) {
|
|
8
|
-
throw new CodegenError({
|
|
9
|
-
whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
|
|
10
|
-
whatCanUserDo: {
|
|
11
|
-
default: [
|
|
12
|
-
'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return eventName.charAt(0).toLowerCase() + eventName.slice(1);
|
|
18
|
-
}
|
|
1
|
+
import { CodegenError } from './CodegenError';
|
|
2
|
+
|
|
3
|
+
export function createEventNameFromEventHandlerName(
|
|
4
|
+
eventHandlerName: string
|
|
5
|
+
): string {
|
|
6
|
+
const eventName = eventHandlerName.replace('on', '');
|
|
7
|
+
if (eventName.length === 0) {
|
|
8
|
+
throw new CodegenError({
|
|
9
|
+
whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
|
|
10
|
+
whatCanUserDo: {
|
|
11
|
+
default: [
|
|
12
|
+
'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return eventName.charAt(0).toLowerCase() + eventName.slice(1);
|
|
18
|
+
}
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
|
|
2
|
-
|
|
3
|
-
function convert(typeAnnotation: TypeAnnotation) {
|
|
4
|
-
return new TypeAnnotationToTS().convert(typeAnnotation);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
it('should convert boolean prop correctly', () => {
|
|
8
|
-
const result = convert({
|
|
9
|
-
type: 'BooleanTypeAnnotation',
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
expect(result).toBe('boolean');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should convert string prop correctly', () => {
|
|
16
|
-
const result = convert({
|
|
17
|
-
type: 'StringTypeAnnotation',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
expect(result).toBe('string');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should convert double prop correctly', () => {
|
|
24
|
-
const result = convert({
|
|
25
|
-
type: 'DoubleTypeAnnotation',
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(result).toBe('number');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should convert float prop correctly', () => {
|
|
32
|
-
const result = convert({
|
|
33
|
-
type: 'FloatTypeAnnotation',
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
expect(result).toBe('number');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should convert object prop correctly', () => {
|
|
40
|
-
const result = convert({
|
|
41
|
-
type: 'ObjectTypeAnnotation',
|
|
42
|
-
properties: [
|
|
43
|
-
{
|
|
44
|
-
typeAnnotation: { type: 'BooleanTypeAnnotation' },
|
|
45
|
-
name: 'booleanTest',
|
|
46
|
-
optional: false,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [] },
|
|
50
|
-
name: 'objectTest',
|
|
51
|
-
optional: true,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
expect(result).toBe('{booleanTest: boolean, objectTest?: {}}');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should convert array correctly', () => {
|
|
60
|
-
const result = convert({
|
|
61
|
-
type: 'ObjectTypeAnnotation',
|
|
62
|
-
properties: [
|
|
63
|
-
{
|
|
64
|
-
typeAnnotation: {
|
|
65
|
-
type: 'ArrayTypeAnnotation',
|
|
66
|
-
elementType: { type: 'StringTypeAnnotation' },
|
|
67
|
-
},
|
|
68
|
-
name: 'arrayTest',
|
|
69
|
-
optional: false,
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
expect(result).toBe('{arrayTest: string[]}');
|
|
75
|
-
});
|
|
1
|
+
import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
|
|
2
|
+
|
|
3
|
+
function convert(typeAnnotation: TypeAnnotation) {
|
|
4
|
+
return new TypeAnnotationToTS().convert(typeAnnotation);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
it('should convert boolean prop correctly', () => {
|
|
8
|
+
const result = convert({
|
|
9
|
+
type: 'BooleanTypeAnnotation',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
expect(result).toBe('boolean');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should convert string prop correctly', () => {
|
|
16
|
+
const result = convert({
|
|
17
|
+
type: 'StringTypeAnnotation',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
expect(result).toBe('string');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should convert double prop correctly', () => {
|
|
24
|
+
const result = convert({
|
|
25
|
+
type: 'DoubleTypeAnnotation',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(result).toBe('number');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should convert float prop correctly', () => {
|
|
32
|
+
const result = convert({
|
|
33
|
+
type: 'FloatTypeAnnotation',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(result).toBe('number');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should convert object prop correctly', () => {
|
|
40
|
+
const result = convert({
|
|
41
|
+
type: 'ObjectTypeAnnotation',
|
|
42
|
+
properties: [
|
|
43
|
+
{
|
|
44
|
+
typeAnnotation: { type: 'BooleanTypeAnnotation' },
|
|
45
|
+
name: 'booleanTest',
|
|
46
|
+
optional: false,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [] },
|
|
50
|
+
name: 'objectTest',
|
|
51
|
+
optional: true,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(result).toBe('{booleanTest: boolean, objectTest?: {}}');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should convert array correctly', () => {
|
|
60
|
+
const result = convert({
|
|
61
|
+
type: 'ObjectTypeAnnotation',
|
|
62
|
+
properties: [
|
|
63
|
+
{
|
|
64
|
+
typeAnnotation: {
|
|
65
|
+
type: 'ArrayTypeAnnotation',
|
|
66
|
+
elementType: { type: 'StringTypeAnnotation' },
|
|
67
|
+
},
|
|
68
|
+
name: 'arrayTest',
|
|
69
|
+
optional: false,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(result).toBe('{arrayTest: string[]}');
|
|
75
|
+
});
|