nitrogen 0.2.23 → 0.29.4
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/README.md +15 -109
- package/lib/Logger.d.ts +10 -0
- package/lib/Logger.js +56 -0
- package/lib/autolinking/Autolinking.d.ts +8 -0
- package/lib/autolinking/Autolinking.js +1 -0
- package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
- package/lib/autolinking/android/createCMakeExtension.js +106 -0
- package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
- package/lib/autolinking/android/createGradleExtension.js +36 -0
- package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
- package/lib/autolinking/android/createHybridObjectInitializer.js +159 -0
- package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
- package/lib/autolinking/createAndroidAutolinking.js +13 -0
- package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
- package/lib/autolinking/createIOSAutolinking.js +19 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.js +97 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.js +69 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.js +117 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.js +74 -0
- package/lib/config/NitroConfig.d.ts +52 -0
- package/lib/config/NitroConfig.js +112 -0
- package/lib/config/NitroUserConfig.d.ts +22 -0
- package/lib/config/NitroUserConfig.js +88 -0
- package/lib/config/getConfig.d.ts +2 -0
- package/lib/config/getConfig.js +84 -0
- package/lib/createGitAttributes.d.ts +1 -0
- package/lib/createGitAttributes.js +11 -0
- package/lib/createPlatformSpec.d.ts +4 -0
- package/lib/createPlatformSpec.js +127 -0
- package/lib/getFiles.d.ts +1 -0
- package/lib/getFiles.js +28 -0
- package/lib/getPlatformSpecs.d.ts +17 -0
- package/lib/getPlatformSpecs.js +153 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +113 -10
- package/lib/init.d.ts +1 -0
- package/lib/init.js +123 -0
- package/lib/nitrogen.d.ts +11 -0
- package/lib/nitrogen.js +165 -0
- package/lib/prettifyDirectory.d.ts +1 -0
- package/lib/prettifyDirectory.js +27 -0
- package/lib/syntax/BridgedType.d.ts +41 -0
- package/lib/syntax/BridgedType.js +1 -0
- package/lib/syntax/CodeNode.d.ts +23 -0
- package/lib/syntax/CodeNode.js +1 -0
- package/lib/syntax/HybridObjectSpec.d.ts +13 -0
- package/lib/syntax/HybridObjectSpec.js +1 -0
- package/lib/syntax/Method.d.ts +41 -0
- package/lib/syntax/Method.js +108 -0
- package/lib/syntax/Parameter.d.ts +15 -0
- package/lib/syntax/Parameter.js +65 -0
- package/lib/syntax/Property.d.ts +50 -0
- package/lib/syntax/Property.js +147 -0
- package/lib/syntax/SourceFile.d.ts +70 -0
- package/lib/syntax/SourceFile.js +7 -0
- package/lib/syntax/c++/CppEnum.d.ts +6 -0
- package/lib/syntax/c++/CppEnum.js +110 -0
- package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
- package/lib/syntax/c++/CppHybridObject.js +146 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.js +18 -0
- package/lib/syntax/c++/CppStruct.d.ts +3 -0
- package/lib/syntax/c++/CppStruct.js +108 -0
- package/lib/syntax/c++/CppUnion.d.ts +6 -0
- package/lib/syntax/c++/CppUnion.js +88 -0
- package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
- package/lib/syntax/c++/getForwardDeclaration.js +14 -0
- package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
- package/lib/syntax/c++/includeNitroHeader.js +34 -0
- package/lib/syntax/createType.d.ts +15 -0
- package/lib/syntax/createType.js +303 -0
- package/lib/syntax/getAllTypes.d.ts +3 -0
- package/lib/syntax/getAllTypes.js +11 -0
- package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
- package/lib/syntax/getCustomTypeConfig.js +53 -0
- package/lib/syntax/getHybridObjectName.d.ts +36 -0
- package/lib/syntax/getHybridObjectName.js +10 -0
- package/lib/syntax/getInterfaceProperties.d.ts +4 -0
- package/lib/syntax/getInterfaceProperties.js +9 -0
- package/lib/syntax/getReferencedTypes.d.ts +2 -0
- package/lib/syntax/getReferencedTypes.js +47 -0
- package/lib/syntax/helpers.d.ts +13 -0
- package/lib/syntax/helpers.js +53 -0
- package/lib/syntax/isCoreType.d.ts +9 -0
- package/lib/syntax/isCoreType.js +47 -0
- package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/FbjniHybridObject.js +261 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.js +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.js +17 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.js +893 -0
- package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinEnum.js +113 -0
- package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinFunction.js +256 -0
- package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObject.js +177 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.js +26 -0
- package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinStruct.js +172 -0
- package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinVariant.js +191 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.js +819 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +17 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.js +613 -0
- package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
- package/lib/syntax/swift/SwiftEnum.js +52 -0
- package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
- package/lib/syntax/swift/SwiftFunction.js +83 -0
- package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObject.js +103 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.js +451 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.js +42 -0
- package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
- package/lib/syntax/swift/SwiftStruct.js +75 -0
- package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
- package/lib/syntax/swift/SwiftVariant.js +58 -0
- package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
- package/lib/syntax/types/ArrayBufferType.js +37 -0
- package/lib/syntax/types/ArrayType.d.ts +12 -0
- package/lib/syntax/types/ArrayType.js +52 -0
- package/lib/syntax/types/BigIntType.d.ts +10 -0
- package/lib/syntax/types/BigIntType.js +27 -0
- package/lib/syntax/types/BooleanType.d.ts +10 -0
- package/lib/syntax/types/BooleanType.js +27 -0
- package/lib/syntax/types/CustomType.d.ts +14 -0
- package/lib/syntax/types/CustomType.js +36 -0
- package/lib/syntax/types/DateType.d.ts +10 -0
- package/lib/syntax/types/DateType.js +35 -0
- package/lib/syntax/types/EnumType.d.ts +23 -0
- package/lib/syntax/types/EnumType.js +101 -0
- package/lib/syntax/types/ErrorType.d.ts +11 -0
- package/lib/syntax/types/ErrorType.js +37 -0
- package/lib/syntax/types/FunctionType.d.ts +29 -0
- package/lib/syntax/types/FunctionType.js +147 -0
- package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
- package/lib/syntax/types/HybridObjectBaseType.js +38 -0
- package/lib/syntax/types/HybridObjectType.d.ts +23 -0
- package/lib/syntax/types/HybridObjectType.js +131 -0
- package/lib/syntax/types/MapType.d.ts +10 -0
- package/lib/syntax/types/MapType.js +37 -0
- package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
- package/lib/syntax/types/NamedWrappingType.js +27 -0
- package/lib/syntax/types/NullType.d.ts +10 -0
- package/lib/syntax/types/NullType.js +23 -0
- package/lib/syntax/types/NumberType.d.ts +10 -0
- package/lib/syntax/types/NumberType.js +27 -0
- package/lib/syntax/types/OptionalType.d.ts +13 -0
- package/lib/syntax/types/OptionalType.js +59 -0
- package/lib/syntax/types/PromiseType.d.ts +16 -0
- package/lib/syntax/types/PromiseType.js +62 -0
- package/lib/syntax/types/RecordType.d.ts +13 -0
- package/lib/syntax/types/RecordType.js +47 -0
- package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
- package/lib/syntax/types/ResultWrappingType.js +44 -0
- package/lib/syntax/types/StringType.d.ts +10 -0
- package/lib/syntax/types/StringType.js +35 -0
- package/lib/syntax/types/StructType.d.ts +14 -0
- package/lib/syntax/types/StructType.js +61 -0
- package/lib/syntax/types/TupleType.d.ts +12 -0
- package/lib/syntax/types/TupleType.js +39 -0
- package/lib/syntax/types/Type.d.ts +55 -0
- package/lib/syntax/types/Type.js +1 -0
- package/lib/syntax/types/VariantType.d.ts +19 -0
- package/lib/syntax/types/VariantType.js +75 -0
- package/lib/syntax/types/VoidType.d.ts +10 -0
- package/lib/syntax/types/VoidType.js +27 -0
- package/lib/syntax/types/getTypeAs.d.ts +2 -0
- package/lib/syntax/types/getTypeAs.js +12 -0
- package/lib/utils.d.ts +22 -0
- package/lib/utils.js +126 -0
- package/lib/views/CppHybridViewComponent.d.ts +14 -0
- package/lib/views/CppHybridViewComponent.js +254 -0
- package/lib/views/createHostComponentJs.d.ts +3 -0
- package/lib/views/createHostComponentJs.js +27 -0
- package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
- package/lib/views/kotlin/KotlinHybridViewManager.js +229 -0
- package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
- package/lib/views/swift/SwiftHybridViewManager.js +131 -0
- package/lib/writeFile.d.ts +5 -0
- package/lib/writeFile.js +19 -0
- package/package.json +58 -29
- package/src/Logger.ts +63 -0
- package/src/autolinking/Autolinking.ts +9 -0
- package/src/autolinking/android/createCMakeExtension.ts +123 -0
- package/src/autolinking/android/createGradleExtension.ts +43 -0
- package/src/autolinking/android/createHybridObjectInitializer.ts +174 -0
- package/src/autolinking/createAndroidAutolinking.ts +28 -0
- package/src/autolinking/createIOSAutolinking.ts +24 -0
- package/src/autolinking/ios/createHybridObjectInitializer.ts +112 -0
- package/src/autolinking/ios/createPodspecRubyExtension.ts +76 -0
- package/src/autolinking/ios/createSwiftCxxBridge.ts +137 -0
- package/src/autolinking/ios/createSwiftUmbrellaHeader.ts +90 -0
- package/src/config/NitroConfig.ts +139 -0
- package/src/config/NitroUserConfig.ts +105 -0
- package/src/config/getConfig.ts +91 -0
- package/src/createGitAttributes.ts +15 -0
- package/src/createPlatformSpec.ts +176 -0
- package/src/getFiles.ts +31 -0
- package/src/getPlatformSpecs.ts +202 -0
- package/src/index.ts +146 -0
- package/src/init.ts +186 -0
- package/src/nitrogen.ts +246 -0
- package/src/prettifyDirectory.ts +32 -0
- package/src/syntax/BridgedType.ts +59 -0
- package/src/syntax/CodeNode.ts +24 -0
- package/src/syntax/HybridObjectSpec.ts +14 -0
- package/src/syntax/Method.ts +154 -0
- package/src/syntax/Parameter.ts +81 -0
- package/src/syntax/Property.ts +203 -0
- package/src/syntax/SourceFile.ts +80 -0
- package/src/syntax/c++/CppEnum.ts +128 -0
- package/src/syntax/c++/CppHybridObject.ts +165 -0
- package/src/syntax/c++/CppHybridObjectRegistration.ts +39 -0
- package/src/syntax/c++/CppStruct.ts +129 -0
- package/src/syntax/c++/CppUnion.ts +105 -0
- package/src/syntax/c++/getForwardDeclaration.ts +19 -0
- package/src/syntax/c++/includeNitroHeader.ts +40 -0
- package/src/syntax/createType.ts +365 -0
- package/src/syntax/getAllTypes.ts +18 -0
- package/src/syntax/getCustomTypeConfig.ts +71 -0
- package/src/syntax/getHybridObjectName.ts +48 -0
- package/src/syntax/getInterfaceProperties.ts +21 -0
- package/src/syntax/getReferencedTypes.ts +57 -0
- package/src/syntax/helpers.ts +79 -0
- package/src/syntax/isCoreType.ts +60 -0
- package/src/syntax/kotlin/FbjniHybridObject.ts +313 -0
- package/src/syntax/kotlin/JNINativeRegistrations.ts +19 -0
- package/src/syntax/kotlin/KotlinBoxedPrimitive.ts +19 -0
- package/src/syntax/kotlin/KotlinCxxBridgedType.ts +942 -0
- package/src/syntax/kotlin/KotlinEnum.ts +130 -0
- package/src/syntax/kotlin/KotlinFunction.ts +277 -0
- package/src/syntax/kotlin/KotlinHybridObject.ts +205 -0
- package/src/syntax/kotlin/KotlinHybridObjectRegistration.ts +51 -0
- package/src/syntax/kotlin/KotlinStruct.ts +198 -0
- package/src/syntax/kotlin/KotlinVariant.ts +212 -0
- package/src/syntax/swift/SwiftCxxBridgedType.ts +874 -0
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +674 -0
- package/src/syntax/swift/SwiftEnum.ts +65 -0
- package/src/syntax/swift/SwiftFunction.ts +91 -0
- package/src/syntax/swift/SwiftHybridObject.ts +121 -0
- package/src/syntax/swift/SwiftHybridObjectBridge.ts +522 -0
- package/src/syntax/swift/SwiftHybridObjectRegistration.ts +75 -0
- package/src/syntax/swift/SwiftStruct.ts +85 -0
- package/src/syntax/swift/SwiftVariant.ts +67 -0
- package/src/syntax/types/ArrayBufferType.ts +49 -0
- package/src/syntax/types/ArrayType.ts +62 -0
- package/src/syntax/types/BigIntType.ts +35 -0
- package/src/syntax/types/BooleanType.ts +35 -0
- package/src/syntax/types/CustomType.ts +47 -0
- package/src/syntax/types/DateType.ts +43 -0
- package/src/syntax/types/EnumType.ts +130 -0
- package/src/syntax/types/ErrorType.ts +44 -0
- package/src/syntax/types/FunctionType.ts +167 -0
- package/src/syntax/types/HybridObjectBaseType.ts +54 -0
- package/src/syntax/types/HybridObjectType.ts +198 -0
- package/src/syntax/types/MapType.ts +49 -0
- package/src/syntax/types/NamedWrappingType.ts +33 -0
- package/src/syntax/types/NullType.ts +30 -0
- package/src/syntax/types/NumberType.ts +34 -0
- package/src/syntax/types/OptionalType.ts +66 -0
- package/src/syntax/types/PromiseType.ts +72 -0
- package/src/syntax/types/RecordType.ts +56 -0
- package/src/syntax/types/ResultWrappingType.ts +53 -0
- package/src/syntax/types/StringType.ts +44 -0
- package/src/syntax/types/StructType.ts +83 -0
- package/src/syntax/types/TupleType.ts +53 -0
- package/src/syntax/types/Type.ts +82 -0
- package/src/syntax/types/VariantType.ts +92 -0
- package/src/syntax/types/VoidType.ts +34 -0
- package/src/syntax/types/getTypeAs.ts +15 -0
- package/src/utils.ts +162 -0
- package/src/views/CppHybridViewComponent.ts +301 -0
- package/src/views/createHostComponentJs.ts +34 -0
- package/src/views/kotlin/KotlinHybridViewManager.ts +258 -0
- package/src/views/swift/SwiftHybridViewManager.ts +153 -0
- package/src/writeFile.ts +27 -0
- package/.jshintignore +0 -6
- package/.jshintrc +0 -3
- package/.npmignore +0 -3
- package/.travis.yml +0 -13
- package/LICENSE +0 -13
- package/browser/nitrogen-min.js +0 -3
- package/browser/nitrogen.js +0 -6369
- package/lib/apiKey.js +0 -67
- package/lib/blob.js +0 -57
- package/lib/commandManager.js +0 -350
- package/lib/device.js +0 -19
- package/lib/memoryStore.js +0 -24
- package/lib/message.js +0 -298
- package/lib/permission.js +0 -121
- package/lib/principal.js +0 -330
- package/lib/service.js +0 -349
- package/lib/session.js +0 -494
- package/lib/user.js +0 -20
- package/publish +0 -2
- package/scripts/build-documentation +0 -4
- package/scripts/build-module +0 -27
- package/scripts/module.js +0 -12
- package/scripts/postamble.js +0 -1
- package/scripts/preamble.js +0 -2
- package/scripts/run-test-server +0 -9
- package/test/config.js +0 -12
- package/test/fixtures/images/image.jpg +0 -0
- package/test/fixtures/images/motion0.jpg +0 -0
- package/test/fixtures/images/motion1.jpg +0 -0
- package/test/fixtures/images/motion2.jpg +0 -0
- package/test/fixtures/index.js +0 -76
- package/test/main.js +0 -5
- package/test/memoryStore.js +0 -22
- package/test/mocha.opts +0 -3
- package/test/units/apiKey.js +0 -46
- package/test/units/blob.js +0 -35
- package/test/units/commandManager.js +0 -67
- package/test/units/device.js +0 -26
- package/test/units/heartbeat.js +0 -28
- package/test/units/message.js +0 -79
- package/test/units/permissions.js +0 -43
- package/test/units/principal.js +0 -116
- package/test/units/service.js +0 -92
- package/test/units/session.js +0 -97
- package/test/units/user.js +0 -48
- package/yuidoc.json +0 -8
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { SourceFile } from '../SourceFile.js'
|
|
2
|
+
import { createFileMetadataString, isNotDuplicate } from '../helpers.js'
|
|
3
|
+
import { indent } from '../../utils.js'
|
|
4
|
+
import type { HybridObjectSpec } from '../HybridObjectSpec.js'
|
|
5
|
+
import { includeHeader, includeNitroHeader } from './includeNitroHeader.js'
|
|
6
|
+
import { getHybridObjectName } from '../getHybridObjectName.js'
|
|
7
|
+
import { HybridObjectType } from '../types/HybridObjectType.js'
|
|
8
|
+
|
|
9
|
+
export function createCppHybridObject(spec: HybridObjectSpec): SourceFile[] {
|
|
10
|
+
// Extra includes
|
|
11
|
+
const extraFiles = [
|
|
12
|
+
...spec.properties.flatMap((p) => p.getExtraFiles()),
|
|
13
|
+
...spec.methods.flatMap((m) => m.getExtraFiles()),
|
|
14
|
+
]
|
|
15
|
+
const extraIncludes = [
|
|
16
|
+
...spec.properties.flatMap((p) => p.getRequiredImports('c++')),
|
|
17
|
+
...spec.methods.flatMap((m) => m.getRequiredImports('c++')),
|
|
18
|
+
...spec.baseTypes.flatMap((b) =>
|
|
19
|
+
new HybridObjectType(b).getRequiredImports('c++')
|
|
20
|
+
),
|
|
21
|
+
]
|
|
22
|
+
const cppForwardDeclarations = extraIncludes
|
|
23
|
+
.map((i) => i.forwardDeclaration)
|
|
24
|
+
.filter((v) => v != null)
|
|
25
|
+
.filter(isNotDuplicate)
|
|
26
|
+
const cppExtraIncludes = extraIncludes
|
|
27
|
+
.map((i) => includeHeader(i))
|
|
28
|
+
.filter(isNotDuplicate)
|
|
29
|
+
const cxxNamespace = spec.config.getCxxNamespace('c++')
|
|
30
|
+
const name = getHybridObjectName(spec.name)
|
|
31
|
+
|
|
32
|
+
const bases = ['public virtual HybridObject']
|
|
33
|
+
for (const base of spec.baseTypes) {
|
|
34
|
+
const baseName = getHybridObjectName(base.name).HybridTSpec
|
|
35
|
+
const fullName = base.config.isExternalConfig
|
|
36
|
+
? base.config.getCxxNamespace('c++', baseName)
|
|
37
|
+
: baseName
|
|
38
|
+
bases.push(`public virtual ${fullName}`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Generate the full header / code
|
|
42
|
+
const cppHeaderCode = `
|
|
43
|
+
${createFileMetadataString(`${name.HybridTSpec}.hpp`)}
|
|
44
|
+
|
|
45
|
+
#pragma once
|
|
46
|
+
|
|
47
|
+
${includeNitroHeader('HybridObject.hpp')}
|
|
48
|
+
|
|
49
|
+
${cppForwardDeclarations.join('\n')}
|
|
50
|
+
|
|
51
|
+
${cppExtraIncludes.join('\n')}
|
|
52
|
+
|
|
53
|
+
namespace ${cxxNamespace} {
|
|
54
|
+
|
|
55
|
+
using namespace margelo::nitro;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* An abstract base class for \`${spec.name}\`
|
|
59
|
+
* Inherit this class to create instances of \`${name.HybridTSpec}\` in C++.
|
|
60
|
+
* You must explicitly call \`HybridObject\`'s constructor yourself, because it is virtual.
|
|
61
|
+
* @example
|
|
62
|
+
* \`\`\`cpp
|
|
63
|
+
* class ${name.HybridT}: public ${name.HybridTSpec} {
|
|
64
|
+
* public:
|
|
65
|
+
* ${name.HybridT}(...): HybridObject(TAG) { ... }
|
|
66
|
+
* // ...
|
|
67
|
+
* };
|
|
68
|
+
* \`\`\`
|
|
69
|
+
*/
|
|
70
|
+
class ${name.HybridTSpec}: ${bases.join(', ')} {
|
|
71
|
+
public:
|
|
72
|
+
// Constructor
|
|
73
|
+
explicit ${name.HybridTSpec}(): HybridObject(TAG) { }
|
|
74
|
+
|
|
75
|
+
// Destructor
|
|
76
|
+
~${name.HybridTSpec}() override = default;
|
|
77
|
+
|
|
78
|
+
public:
|
|
79
|
+
// Properties
|
|
80
|
+
${indent(spec.properties.map((p) => p.getCode('c++', { virtual: true })).join('\n'), ' ')}
|
|
81
|
+
|
|
82
|
+
public:
|
|
83
|
+
// Methods
|
|
84
|
+
${indent(spec.methods.map((m) => m.getCode('c++', { virtual: true })).join('\n'), ' ')}
|
|
85
|
+
|
|
86
|
+
protected:
|
|
87
|
+
// Hybrid Setup
|
|
88
|
+
void loadHybridMethods() override;
|
|
89
|
+
|
|
90
|
+
protected:
|
|
91
|
+
// Tag for logging
|
|
92
|
+
static constexpr auto TAG = "${spec.name}";
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} // namespace ${cxxNamespace}
|
|
96
|
+
`
|
|
97
|
+
|
|
98
|
+
// Each C++ method needs to be registered in the HybridObject - that's getters, setters and normal methods.
|
|
99
|
+
const registrations: string[] = []
|
|
100
|
+
for (const property of spec.properties) {
|
|
101
|
+
const getterMethod = property.getGetterName('other')
|
|
102
|
+
const setterMethod = property.getSetterName('other')
|
|
103
|
+
// getter
|
|
104
|
+
registrations.push(
|
|
105
|
+
`prototype.registerHybridGetter("${property.name}", &${name.HybridTSpec}::${getterMethod});`
|
|
106
|
+
)
|
|
107
|
+
if (!property.isReadonly) {
|
|
108
|
+
// setter
|
|
109
|
+
registrations.push(
|
|
110
|
+
`prototype.registerHybridSetter("${property.name}", &${name.HybridTSpec}::${setterMethod});`
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (const method of spec.methods) {
|
|
115
|
+
// method
|
|
116
|
+
registrations.push(
|
|
117
|
+
`prototype.registerHybridMethod("${method.name}", &${name.HybridTSpec}::${method.name});`
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const basePrototypeRegistrations = ['HybridObject::loadHybridMethods();']
|
|
122
|
+
for (const base of spec.baseTypes) {
|
|
123
|
+
const hybridObjectName = getHybridObjectName(base.name)
|
|
124
|
+
basePrototypeRegistrations.push(
|
|
125
|
+
`${hybridObjectName.HybridTSpec}::loadHybridMethods();`
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const cppBodyCode = `
|
|
130
|
+
${createFileMetadataString(`${name.HybridTSpec}.cpp`)}
|
|
131
|
+
|
|
132
|
+
#include "${name.HybridTSpec}.hpp"
|
|
133
|
+
|
|
134
|
+
namespace ${cxxNamespace} {
|
|
135
|
+
|
|
136
|
+
void ${name.HybridTSpec}::loadHybridMethods() {
|
|
137
|
+
// load base methods/properties
|
|
138
|
+
${indent(basePrototypeRegistrations.join('\n'), ' ')}
|
|
139
|
+
// load custom methods/properties
|
|
140
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
141
|
+
${indent(registrations.join('\n'), ' ')}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
} // namespace ${cxxNamespace}
|
|
146
|
+
`
|
|
147
|
+
|
|
148
|
+
const files: SourceFile[] = []
|
|
149
|
+
files.push({
|
|
150
|
+
content: cppHeaderCode,
|
|
151
|
+
name: `${name.HybridTSpec}.hpp`,
|
|
152
|
+
subdirectory: [],
|
|
153
|
+
language: 'c++',
|
|
154
|
+
platform: 'shared',
|
|
155
|
+
})
|
|
156
|
+
files.push({
|
|
157
|
+
content: cppBodyCode,
|
|
158
|
+
name: `${name.HybridTSpec}.cpp`,
|
|
159
|
+
subdirectory: [],
|
|
160
|
+
language: 'c++',
|
|
161
|
+
platform: 'shared',
|
|
162
|
+
})
|
|
163
|
+
files.push(...extraFiles)
|
|
164
|
+
return files
|
|
165
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SourceImport } from '../SourceFile.js'
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the Hybrid Object under which it should be registered and exposed to JS to.
|
|
6
|
+
*/
|
|
7
|
+
hybridObjectName: string
|
|
8
|
+
/**
|
|
9
|
+
* The name of the C++ class that will be default-constructed
|
|
10
|
+
*/
|
|
11
|
+
cppClassName: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface CppHybridObjectRegistration {
|
|
15
|
+
cppCode: string
|
|
16
|
+
requiredImports: SourceImport[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createCppHybridObjectRegistration({
|
|
20
|
+
hybridObjectName,
|
|
21
|
+
cppClassName,
|
|
22
|
+
}: Props): CppHybridObjectRegistration {
|
|
23
|
+
return {
|
|
24
|
+
requiredImports: [
|
|
25
|
+
{ name: `${cppClassName}.hpp`, language: 'c++', space: 'user' },
|
|
26
|
+
],
|
|
27
|
+
cppCode: `
|
|
28
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
29
|
+
"${hybridObjectName}",
|
|
30
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
31
|
+
static_assert(std::is_default_constructible_v<${cppClassName}>,
|
|
32
|
+
"The HybridObject \\"${cppClassName}\\" is not default-constructible! "
|
|
33
|
+
"Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
|
|
34
|
+
return std::make_shared<${cppClassName}>();
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
`.trim(),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { FileWithReferencedTypes } from '../SourceFile.js'
|
|
2
|
+
import { indent } from '../../utils.js'
|
|
3
|
+
import { createFileMetadataString, isNotDuplicate } from '../helpers.js'
|
|
4
|
+
import type { NamedType } from '../types/Type.js'
|
|
5
|
+
import { includeHeader, includeNitroHeader } from './includeNitroHeader.js'
|
|
6
|
+
import { NitroConfig } from '../../config/NitroConfig.js'
|
|
7
|
+
import type { GetFunctionCodeOptions } from '../types/FunctionType.js'
|
|
8
|
+
|
|
9
|
+
export function createCppStruct(
|
|
10
|
+
typename: string,
|
|
11
|
+
properties: NamedType[]
|
|
12
|
+
): FileWithReferencedTypes {
|
|
13
|
+
// Namespace typename
|
|
14
|
+
const fullyQualifiedTypename = NitroConfig.current.getCxxNamespace(
|
|
15
|
+
'c++',
|
|
16
|
+
typename
|
|
17
|
+
)
|
|
18
|
+
// Get C++ code for all struct members
|
|
19
|
+
const cppStructProps = properties
|
|
20
|
+
.map((p) => `${p.getCode('c++')} ${p.escapedName} SWIFT_PRIVATE;`)
|
|
21
|
+
.join('\n')
|
|
22
|
+
const cppConstructorParams = properties
|
|
23
|
+
.map((p) => `${p.getCode('c++')} ${p.escapedName}`)
|
|
24
|
+
.join(', ')
|
|
25
|
+
const cppInitializerParams = properties
|
|
26
|
+
.map((p) => `${p.escapedName}(${p.escapedName})`)
|
|
27
|
+
.join(', ')
|
|
28
|
+
// Get C++ code for converting each member from a jsi::Value
|
|
29
|
+
const codeOptions: GetFunctionCodeOptions = {
|
|
30
|
+
fullyQualified: true,
|
|
31
|
+
includeNameInfo: false,
|
|
32
|
+
}
|
|
33
|
+
const cppFromJsiParams = properties
|
|
34
|
+
.map(
|
|
35
|
+
(p) =>
|
|
36
|
+
`JSIConverter<${p.getCode('c++', codeOptions)}>::fromJSI(runtime, obj.getProperty(runtime, "${p.name}"))`
|
|
37
|
+
)
|
|
38
|
+
.join(',\n')
|
|
39
|
+
// Get C++ code for converting each member to a jsi::Value
|
|
40
|
+
const cppToJsiCalls = properties
|
|
41
|
+
.map(
|
|
42
|
+
(p) =>
|
|
43
|
+
`obj.setProperty(runtime, "${p.name}", JSIConverter<${p.getCode('c++', codeOptions)}>::toJSI(runtime, arg.${p.escapedName}));`
|
|
44
|
+
)
|
|
45
|
+
.join('\n')
|
|
46
|
+
// Get C++ code for verifying if jsi::Value can be converted to type
|
|
47
|
+
const cppCanConvertCalls = properties
|
|
48
|
+
.map(
|
|
49
|
+
(p) =>
|
|
50
|
+
`if (!JSIConverter<${p.getCode('c++', codeOptions)}>::canConvert(runtime, obj.getProperty(runtime, "${p.name}"))) return false;`
|
|
51
|
+
)
|
|
52
|
+
.join('\n')
|
|
53
|
+
|
|
54
|
+
// Get C++ includes for each extra-file we need to include
|
|
55
|
+
const includedTypes = properties.flatMap((r) => r.getRequiredImports('c++'))
|
|
56
|
+
const cppForwardDeclarations = includedTypes
|
|
57
|
+
.map((i) => i.forwardDeclaration)
|
|
58
|
+
.filter((v) => v != null)
|
|
59
|
+
.filter(isNotDuplicate)
|
|
60
|
+
const cppExtraIncludes = includedTypes
|
|
61
|
+
.map((i) => includeHeader(i))
|
|
62
|
+
.filter(isNotDuplicate)
|
|
63
|
+
const cxxNamespace = NitroConfig.current.getCxxNamespace('c++')
|
|
64
|
+
|
|
65
|
+
const cppCode = `
|
|
66
|
+
${createFileMetadataString(`${typename}.hpp`)}
|
|
67
|
+
|
|
68
|
+
#pragma once
|
|
69
|
+
|
|
70
|
+
${includeNitroHeader('JSIConverter.hpp')}
|
|
71
|
+
${includeNitroHeader('NitroDefines.hpp')}
|
|
72
|
+
|
|
73
|
+
${cppForwardDeclarations.join('\n')}
|
|
74
|
+
|
|
75
|
+
${cppExtraIncludes.join('\n')}
|
|
76
|
+
|
|
77
|
+
namespace ${cxxNamespace} {
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A struct which can be represented as a JavaScript object (${typename}).
|
|
81
|
+
*/
|
|
82
|
+
struct ${typename} {
|
|
83
|
+
public:
|
|
84
|
+
${indent(cppStructProps, ' ')}
|
|
85
|
+
|
|
86
|
+
public:
|
|
87
|
+
${typename}() = default;
|
|
88
|
+
explicit ${typename}(${cppConstructorParams}): ${cppInitializerParams} {}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
} // namespace ${cxxNamespace}
|
|
92
|
+
|
|
93
|
+
namespace margelo::nitro {
|
|
94
|
+
|
|
95
|
+
// C++ ${typename} <> JS ${typename} (object)
|
|
96
|
+
template <>
|
|
97
|
+
struct JSIConverter<${fullyQualifiedTypename}> final {
|
|
98
|
+
static inline ${fullyQualifiedTypename} fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
99
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
100
|
+
return ${fullyQualifiedTypename}(
|
|
101
|
+
${indent(cppFromJsiParams, ' ')}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const ${fullyQualifiedTypename}& arg) {
|
|
105
|
+
jsi::Object obj(runtime);
|
|
106
|
+
${indent(cppToJsiCalls, ' ')}
|
|
107
|
+
return obj;
|
|
108
|
+
}
|
|
109
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
110
|
+
if (!value.isObject()) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
jsi::Object obj = value.getObject(runtime);
|
|
114
|
+
${indent(cppCanConvertCalls, ' ')}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
} // namespace margelo::nitro
|
|
120
|
+
`
|
|
121
|
+
return {
|
|
122
|
+
content: cppCode,
|
|
123
|
+
name: `${typename}.hpp`,
|
|
124
|
+
subdirectory: [],
|
|
125
|
+
language: 'c++',
|
|
126
|
+
referencedTypes: properties,
|
|
127
|
+
platform: 'shared',
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { SourceFile } from '../SourceFile.js'
|
|
2
|
+
import { createFileMetadataString } from './../helpers.js'
|
|
3
|
+
import { indent, toLowerCamelCase } from '../../utils.js'
|
|
4
|
+
import type { EnumMember } from '../types/EnumType.js'
|
|
5
|
+
import { includeNitroHeader } from './includeNitroHeader.js'
|
|
6
|
+
import { NitroConfig } from '../../config/NitroConfig.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a C++ enum that converts to a TypeScript union (aka just strings).
|
|
10
|
+
*/
|
|
11
|
+
export function createCppUnion(
|
|
12
|
+
typename: string,
|
|
13
|
+
enumMembers: EnumMember[]
|
|
14
|
+
): SourceFile {
|
|
15
|
+
// Namespace typename
|
|
16
|
+
const fullyQualifiedTypename = NitroConfig.current.getCxxNamespace(
|
|
17
|
+
'c++',
|
|
18
|
+
typename
|
|
19
|
+
)
|
|
20
|
+
const cppEnumMembers = enumMembers
|
|
21
|
+
.map(
|
|
22
|
+
(m, i) => `${m.name} SWIFT_NAME(${toLowerCamelCase(m.name)}) = ${i},`
|
|
23
|
+
)
|
|
24
|
+
.join('\n')
|
|
25
|
+
const cppFromJsiHashCases = enumMembers
|
|
26
|
+
.map((v) =>
|
|
27
|
+
`case hashString("${v.stringValue}"): return ${fullyQualifiedTypename}::${v.name};`.trim()
|
|
28
|
+
)
|
|
29
|
+
.join('\n')
|
|
30
|
+
const cppToJsiCases = enumMembers
|
|
31
|
+
.map(
|
|
32
|
+
(v) =>
|
|
33
|
+
`case ${fullyQualifiedTypename}::${v.name}: return JSIConverter<std::string>::toJSI(runtime, "${v.stringValue}");`
|
|
34
|
+
)
|
|
35
|
+
.join('\n')
|
|
36
|
+
const cppCanConvertCases = enumMembers
|
|
37
|
+
.map((m) => `case hashString("${m.stringValue}"):`)
|
|
38
|
+
.join('\n')
|
|
39
|
+
const cxxNamespace = NitroConfig.current.getCxxNamespace('c++')
|
|
40
|
+
|
|
41
|
+
const cppCode = `
|
|
42
|
+
${createFileMetadataString(`${typename}.hpp`)}
|
|
43
|
+
|
|
44
|
+
#pragma once
|
|
45
|
+
|
|
46
|
+
${includeNitroHeader('NitroHash.hpp')}
|
|
47
|
+
${includeNitroHeader('JSIConverter.hpp')}
|
|
48
|
+
${includeNitroHeader('NitroDefines.hpp')}
|
|
49
|
+
|
|
50
|
+
namespace ${cxxNamespace} {
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* An enum which can be represented as a JavaScript union (${typename}).
|
|
54
|
+
*/
|
|
55
|
+
enum class ${typename} {
|
|
56
|
+
${indent(cppEnumMembers, ' ')}
|
|
57
|
+
} CLOSED_ENUM;
|
|
58
|
+
|
|
59
|
+
} // namespace ${cxxNamespace}
|
|
60
|
+
|
|
61
|
+
namespace margelo::nitro {
|
|
62
|
+
|
|
63
|
+
// C++ ${typename} <> JS ${typename} (union)
|
|
64
|
+
template <>
|
|
65
|
+
struct JSIConverter<${fullyQualifiedTypename}> final {
|
|
66
|
+
static inline ${fullyQualifiedTypename} fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
67
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
68
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
69
|
+
${indent(cppFromJsiHashCases, ' ')}
|
|
70
|
+
default: [[unlikely]]
|
|
71
|
+
throw std::invalid_argument("Cannot convert \\"" + unionValue + "\\" to enum ${typename} - invalid value!");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, ${fullyQualifiedTypename} arg) {
|
|
75
|
+
switch (arg) {
|
|
76
|
+
${indent(cppToJsiCases, ' ')}
|
|
77
|
+
default: [[unlikely]]
|
|
78
|
+
throw std::invalid_argument("Cannot convert ${typename} to JS - invalid value: "
|
|
79
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
83
|
+
if (!value.isString()) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
87
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
88
|
+
${indent(cppCanConvertCases, ' ')}
|
|
89
|
+
return true;
|
|
90
|
+
default:
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
} // namespace margelo::nitro
|
|
97
|
+
`
|
|
98
|
+
return {
|
|
99
|
+
content: cppCode,
|
|
100
|
+
name: `${typename}.hpp`,
|
|
101
|
+
subdirectory: [],
|
|
102
|
+
language: 'c++',
|
|
103
|
+
platform: 'shared',
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type DeclarationKind = 'class' | 'struct' | 'enum class'
|
|
2
|
+
|
|
3
|
+
export function getForwardDeclaration(
|
|
4
|
+
kind: DeclarationKind,
|
|
5
|
+
className: string,
|
|
6
|
+
namespace?: string
|
|
7
|
+
): string {
|
|
8
|
+
if (namespace != null) {
|
|
9
|
+
return `
|
|
10
|
+
// Forward declaration of \`${className}\` to properly resolve imports.
|
|
11
|
+
namespace ${namespace} { ${kind} ${className}; }
|
|
12
|
+
`.trim()
|
|
13
|
+
} else {
|
|
14
|
+
return `
|
|
15
|
+
// Forward declaration of \`${className}\` to properly resolve imports.
|
|
16
|
+
${kind} ${className};
|
|
17
|
+
`.trim()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SourceImport } from '../SourceFile.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates C++ code for including a `NitroModules` header.
|
|
5
|
+
* @example `Hash.hpp` -> `#include <NitroModules/Hash.hpp>`
|
|
6
|
+
*/
|
|
7
|
+
export function includeNitroHeader(headerName: string): string {
|
|
8
|
+
return `
|
|
9
|
+
#if __has_include(<NitroModules/${headerName}>)
|
|
10
|
+
#include <NitroModules/${headerName}>
|
|
11
|
+
#else
|
|
12
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
13
|
+
#endif
|
|
14
|
+
`.trim()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function includeHeader(
|
|
18
|
+
sourceImport: SourceImport,
|
|
19
|
+
force = true
|
|
20
|
+
): string {
|
|
21
|
+
const header = getHeader(sourceImport.name, sourceImport.space)
|
|
22
|
+
if (force) {
|
|
23
|
+
return `#include ${header}`
|
|
24
|
+
} else {
|
|
25
|
+
return `
|
|
26
|
+
#if __has_include(${header})
|
|
27
|
+
#include ${header}
|
|
28
|
+
#endif
|
|
29
|
+
`.trim()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getHeader(name: string, space: 'user' | 'system'): string {
|
|
34
|
+
switch (space) {
|
|
35
|
+
case 'user':
|
|
36
|
+
return `"${name}"`
|
|
37
|
+
case 'system':
|
|
38
|
+
return `<${name}>`
|
|
39
|
+
}
|
|
40
|
+
}
|