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
package/README.md
CHANGED
|
@@ -1,118 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
<a href="https://margelo.com">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="../../docs/static/img/banner-nitrogen-dark.png" />
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="../../docs/static/img/banner-nitrogen-light.png" />
|
|
5
|
+
<img alt="Nitrogen" src="../../docs/static/img/banner-nitrogen-light.png" />
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
<br />
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
**Nitrogen** is a code-generator that takes TypeScript interfaces and generates C++, Swift and Kotlin code and native bindings built on top of the [**react-native-nitro-modules**](../react-native-nitro-modules/) core APIs.
|
|
6
12
|
|
|
7
|
-
##
|
|
13
|
+
## Installation
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
``` javascript
|
|
14
|
-
var thermometer = new nitrogen.Device({
|
|
15
|
-
tags: ['sends:temperature'],
|
|
16
|
-
nickname: 'thermometer'
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
var service = new nitrogen.Service(config);
|
|
20
|
-
service.connect(thermometer, function(err, session, thermometer) {
|
|
21
|
-
|
|
22
|
-
// take temperature every 15 minutes.
|
|
23
|
-
|
|
24
|
-
setInterval(function() {
|
|
25
|
-
var message = new Nitrogen.Message({
|
|
26
|
-
type: 'temperature',
|
|
27
|
-
body: {
|
|
28
|
-
temperature: getTemp()
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
message.save(session);
|
|
33
|
-
}, 15 * 60 * 1000);
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
You can find a complete example for a device application of Nitrogen in the [camera](https://github.com/nitrogenjs/camera) project.
|
|
39
|
-
|
|
40
|
-
## Listening to a device's message stream
|
|
41
|
-
|
|
42
|
-
An application that displays these temperatures in real time as they are received would look like this. In this case,
|
|
43
|
-
we're using a user principal, and a filter with onMessage to only notify us of temperature updates.
|
|
44
|
-
|
|
45
|
-
``` javascript
|
|
46
|
-
var user = new nitrogen.User({...});
|
|
47
|
-
|
|
48
|
-
var service = new nitrogen.Service(config);
|
|
49
|
-
service.connect(user, function(err, session, user) {
|
|
50
|
-
session.onMessage({ type: 'temperature' }, function(message) {
|
|
51
|
-
console.log("The temperature is now: " + message.body.temperature);
|
|
52
|
-
|
|
53
|
-
// update the UI
|
|
54
|
-
});
|
|
55
|
-
});
|
|
15
|
+
Install [nitrogen](https://npmjs.org/nitrogen) as a `devDependency` in your react-native library:
|
|
16
|
+
```sh
|
|
17
|
+
npm i nitrogen -D
|
|
56
18
|
```
|
|
57
19
|
|
|
58
|
-
## Getting Started
|
|
59
|
-
|
|
60
|
-
To get started with a Nitrogen client:
|
|
61
|
-
|
|
62
|
-
### Node.js application
|
|
63
|
-
|
|
64
|
-
1. `npm install nitrogen`
|
|
65
|
-
|
|
66
|
-
### Browser application
|
|
67
|
-
|
|
68
|
-
1. Add `<script src="https://api.nitrogen.io/client/nitrogen-min.js" />` to your application.
|
|
69
|
-
|
|
70
|
-
### Documentation
|
|
71
|
-
|
|
72
|
-
Documentation for the Nitrogen client library can be found online at the [Nitrogen project](http://nitrogen.io).
|
|
73
|
-
|
|
74
|
-
### Contributing to the project.
|
|
75
|
-
|
|
76
|
-
1. Clone or fork this repo: `https://github.com/nitrogenjs/client`
|
|
77
|
-
2. If you are building on Windows, make sure to fetch all of the node-gyp dependencies as explained here: https://github.com/TooTallNate/node-gyp#installation
|
|
78
|
-
2. Fetch and install its node.js dependencies: `npm install`
|
|
79
|
-
3. Run a [Nitrogen server](https://github.com/nitrogenjs/service) locally that the tests can run against in test mode (NODE_ENV=test).
|
|
80
|
-
4. Run the tests to make sure everything is setup correctly: `npm test`
|
|
81
|
-
5. Make your change as a clean commit for a pull request.
|
|
82
|
-
6. Make sure there is a test to cover new functionality so nobody can break it in the future without us knowing.
|
|
83
|
-
7. Submit it as a pull request to the project.
|
|
84
|
-
|
|
85
|
-
## How to contribute
|
|
86
|
-
|
|
87
|
-
1. Feedback: We'd love feedback on what problems you are using Nitrogen to solve. Obviously, we'd also like to hear about where you ran into sharp edges and dead ends. Drop me a message at timfpark@gmail.com or file an issue with us above.
|
|
88
|
-
2. Pull requests: If you'd like to tackle an issue, fork the repo, create a clean commit for the fix or enhancement with tests if necessary, and send us a pull request. This is also the path to becoming a core committer for the project for folks that are interested in contributing in more depth.
|
|
89
|
-
3. Documentation: Better technical documentation is key to broadening the use of the platform. We'd love to have more help and this is one of the most valuable contributions you can make.
|
|
90
|
-
|
|
91
|
-
## Running on Windows
|
|
92
|
-
|
|
93
|
-
On Windows, you'll need to install some dependencies first:
|
|
94
|
-
- [node-gyp](https://github.com/TooTallNate/node-gyp/) (`npm install -g node-gyp`)
|
|
95
|
-
- [Python 2.7](http://www.python.org/download/releases/2.7.3#download) (not 3.3)
|
|
96
|
-
- Visual Studio 2010 or higher (including Express editions)
|
|
97
|
-
- Windows XP/Vista/7:
|
|
98
|
-
- Microsoft Visual Studio C++ 2010 ([Express](http://go.microsoft.com/?linkid=9709949) version works well)
|
|
99
|
-
- Also install [Microsoft Visual Studio 2010 Service Pack 1](http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=23691)
|
|
100
|
-
- For 64-bit builds of node and native modules you will _**also**_ need the [Windows 7 64-bit SDK](http://www.microsoft.com/en-us/download/details.aspx?id=8279)
|
|
101
|
-
- If you get errors that the 64-bit compilers are not installed you may also need the [compiler update for the Windows SDK 7.1](http://www.microsoft.com/en-us/download/details.aspx?id=4422)
|
|
102
|
-
- Windows 8:
|
|
103
|
-
- Microsoft Visual Studio C++ 2012 for Windows Desktop ([Express](http://go.microsoft.com/?linkid=9816758) version works well)
|
|
104
|
-
- [OpenSSL](http://slproweb.com/products/Win32OpenSSL.html) (normal, not light)
|
|
105
|
-
in the same bitness as your Node.js installation.
|
|
106
|
-
- The build script looks for OpenSSL in the default install directory (`C:\OpenSSL-Win32` or `C:\OpenSSL-Win64`)
|
|
107
|
-
- If you get `Error: The specified module could not be found.`, copy `libeay32.dll` from the OpenSSL bin directory to this module's bin directory, or to Windows\System3.
|
|
108
20
|
|
|
109
|
-
## Nitrogen Project
|
|
110
21
|
|
|
111
|
-
|
|
22
|
+
## Usage
|
|
112
23
|
|
|
113
|
-
|
|
114
|
-
2. [client](https://github.com/nitrogenjs/client): JavaScript client library for building Nitrogen devices and applications.
|
|
115
|
-
3. [admin](https://github.com/nitrogenjs/admin): Administrative tool for managing the Nitrogen service.
|
|
116
|
-
4. [device](https://github.com/nitrogenjs/devices): Adaptors for common pieces of hardware.
|
|
117
|
-
5. [commands](https://github.com/nitrogenjs/commands): CommandManagers and schemas for well known command types.
|
|
118
|
-
6. [cli](https://github.com/nitrogenjs/cli): Command line interface for working with a Nitrogen service.
|
|
24
|
+
See the [Nitrogen documentation](https://nitro.margelo.com/docs/nitrogen) for more information.
|
package/lib/Logger.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
2
|
+
export declare function isValidLogLevel(level: unknown): level is LogLevel;
|
|
3
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
4
|
+
export declare const Logger: {
|
|
5
|
+
withIndented(callback: () => void): void;
|
|
6
|
+
debug(message: string, ...extra: unknown[]): void;
|
|
7
|
+
info(message: string, ...extra: unknown[]): void;
|
|
8
|
+
warn(message: string, ...extra: unknown[]): void;
|
|
9
|
+
error(message: string, ...extra: unknown[]): void;
|
|
10
|
+
};
|
package/lib/Logger.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const levelMap = {
|
|
2
|
+
debug: 0,
|
|
3
|
+
info: 1,
|
|
4
|
+
warning: 2,
|
|
5
|
+
error: 3,
|
|
6
|
+
};
|
|
7
|
+
let currentLogLevel = 'info';
|
|
8
|
+
export function isValidLogLevel(level) {
|
|
9
|
+
// @ts-expect-error
|
|
10
|
+
return typeof levelMap[level] === 'number';
|
|
11
|
+
}
|
|
12
|
+
export function setLogLevel(level) {
|
|
13
|
+
currentLogLevel = level;
|
|
14
|
+
}
|
|
15
|
+
function isAtLeast(level) {
|
|
16
|
+
return levelMap[level] >= levelMap[currentLogLevel];
|
|
17
|
+
}
|
|
18
|
+
let indentation = 0;
|
|
19
|
+
function getIndentation() {
|
|
20
|
+
let string = '';
|
|
21
|
+
for (let i = 0; i < indentation; i++) {
|
|
22
|
+
string += ' ';
|
|
23
|
+
}
|
|
24
|
+
return string;
|
|
25
|
+
}
|
|
26
|
+
export const Logger = {
|
|
27
|
+
withIndented(callback) {
|
|
28
|
+
try {
|
|
29
|
+
indentation++;
|
|
30
|
+
callback();
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
indentation--;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
debug(message, ...extra) {
|
|
37
|
+
if (isAtLeast('debug')) {
|
|
38
|
+
console.debug(getIndentation() + message, ...extra);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
info(message, ...extra) {
|
|
42
|
+
if (isAtLeast('info')) {
|
|
43
|
+
console.info(getIndentation() + message, ...extra);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
warn(message, ...extra) {
|
|
47
|
+
if (isAtLeast('warning')) {
|
|
48
|
+
console.warn(getIndentation() + message, ...extra);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
error(message, ...extra) {
|
|
52
|
+
if (isAtLeast('error')) {
|
|
53
|
+
console.error(getIndentation() + message, ...extra);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Platform } from '../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile } from '../syntax/SourceFile.js';
|
|
3
|
+
type AutolinkingFile = Omit<SourceFile, 'language'>;
|
|
4
|
+
export interface Autolinking {
|
|
5
|
+
platform: Platform;
|
|
6
|
+
sourceFiles: AutolinkingFile[];
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceFile } from '../../syntax/SourceFile.js';
|
|
2
|
+
export interface CMakeFile extends Omit<SourceFile, 'language'> {
|
|
3
|
+
language: 'cmake';
|
|
4
|
+
}
|
|
5
|
+
export declare function getBuildingWithGeneratedCmakeDefinition(): string;
|
|
6
|
+
export declare function createCMakeExtension(files: SourceFile[]): CMakeFile;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { indent, toLowerCamelCase, toUnixPath } from '../../utils.js';
|
|
3
|
+
import { createFileMetadataString, getRelativeDirectory, getRelativeDirectoryGenerated, isCppFile, isNotDuplicate, } from '../../syntax/helpers.js';
|
|
4
|
+
export function getBuildingWithGeneratedCmakeDefinition() {
|
|
5
|
+
const moduleName = NitroConfig.current.getAndroidCxxLibName();
|
|
6
|
+
const upper = toLowerCamelCase(moduleName).toUpperCase();
|
|
7
|
+
return `BUILDING_${upper}_WITH_GENERATED_CMAKE_PROJECT`;
|
|
8
|
+
}
|
|
9
|
+
export function createCMakeExtension(files) {
|
|
10
|
+
const name = NitroConfig.current.getAndroidCxxLibName();
|
|
11
|
+
const sharedFiles = files
|
|
12
|
+
.filter((f) => f.platform === 'shared' && isCppFile(f))
|
|
13
|
+
.map((f) => getRelativeDirectory(f))
|
|
14
|
+
.map((p) => toUnixPath(p))
|
|
15
|
+
.filter(isNotDuplicate);
|
|
16
|
+
const androidFiles = files
|
|
17
|
+
.filter((f) => f.platform === 'android' && isCppFile(f))
|
|
18
|
+
.map((f) => getRelativeDirectory(f))
|
|
19
|
+
.map((p) => toUnixPath(p))
|
|
20
|
+
.filter(isNotDuplicate);
|
|
21
|
+
const autolinkingFilePath = getRelativeDirectoryGenerated('android', `${name}OnLoad.cpp`);
|
|
22
|
+
const autolinkingFile = toUnixPath(autolinkingFilePath);
|
|
23
|
+
const buildingWithDefinition = getBuildingWithGeneratedCmakeDefinition();
|
|
24
|
+
const code = `
|
|
25
|
+
${createFileMetadataString(`${name}+autolinking.cmake`, '#')}
|
|
26
|
+
|
|
27
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
28
|
+
# to the current CMake project.
|
|
29
|
+
#
|
|
30
|
+
# To use it, add this to your CMakeLists.txt:
|
|
31
|
+
# \`\`\`cmake
|
|
32
|
+
# include(\${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/${name}+autolinking.cmake)
|
|
33
|
+
# \`\`\`
|
|
34
|
+
|
|
35
|
+
# Add all headers that were generated by Nitrogen
|
|
36
|
+
include_directories(
|
|
37
|
+
"../nitrogen/generated/shared/c++"
|
|
38
|
+
"../nitrogen/generated/android/c++"
|
|
39
|
+
"../nitrogen/generated/android/"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
43
|
+
target_sources(
|
|
44
|
+
# CMake project name (Android C++ library name)
|
|
45
|
+
${name} PRIVATE
|
|
46
|
+
# Autolinking Setup
|
|
47
|
+
${autolinkingFile}
|
|
48
|
+
# Shared Nitrogen C++ sources
|
|
49
|
+
${indent(sharedFiles.join('\n'), ' ')}
|
|
50
|
+
# Android-specific Nitrogen C++ sources
|
|
51
|
+
${indent(androidFiles.join('\n'), ' ')}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Define a flag to check if we are building properly
|
|
55
|
+
add_definitions(-D${buildingWithDefinition})
|
|
56
|
+
|
|
57
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
58
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
59
|
+
target_compile_definitions(
|
|
60
|
+
${name} PRIVATE
|
|
61
|
+
-DFOLLY_NO_CONFIG=1
|
|
62
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
63
|
+
-DFOLLY_USE_LIBCPP=1
|
|
64
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
65
|
+
-DFOLLY_MOBILE=1
|
|
66
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
67
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
68
|
+
# Once we target android-23 above, we can comment
|
|
69
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
70
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Add all libraries required by the generated specs
|
|
74
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
75
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
76
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
77
|
+
|
|
78
|
+
# Link all libraries together
|
|
79
|
+
target_link_libraries(
|
|
80
|
+
${name}
|
|
81
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
82
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
83
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
87
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
88
|
+
target_link_libraries(
|
|
89
|
+
${name}
|
|
90
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
91
|
+
)
|
|
92
|
+
else()
|
|
93
|
+
target_link_libraries(
|
|
94
|
+
${name}
|
|
95
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
96
|
+
)
|
|
97
|
+
endif()
|
|
98
|
+
`.trim();
|
|
99
|
+
return {
|
|
100
|
+
content: code,
|
|
101
|
+
language: 'cmake',
|
|
102
|
+
name: `${name}+autolinking.cmake`,
|
|
103
|
+
platform: 'android',
|
|
104
|
+
subdirectory: [],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { createFileMetadataString } from '../../syntax/helpers.js';
|
|
3
|
+
export function createGradleExtension() {
|
|
4
|
+
const name = NitroConfig.current.getAndroidCxxLibName();
|
|
5
|
+
const code = `
|
|
6
|
+
${createFileMetadataString(`${name}+autolinking.gradle`)}
|
|
7
|
+
|
|
8
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// \`\`\`gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/${name}+autolinking.gradle'
|
|
14
|
+
/// \`\`\`
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 ${name} is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"\${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`.trim();
|
|
29
|
+
return {
|
|
30
|
+
content: code,
|
|
31
|
+
language: 'gradle',
|
|
32
|
+
name: `${name}+autolinking.gradle`,
|
|
33
|
+
platform: 'android',
|
|
34
|
+
subdirectory: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { createCppHybridObjectRegistration } from '../../syntax/c++/CppHybridObjectRegistration.js';
|
|
3
|
+
import { includeHeader } from '../../syntax/c++/includeNitroHeader.js';
|
|
4
|
+
import { createFileMetadataString, isNotDuplicate, } from '../../syntax/helpers.js';
|
|
5
|
+
import { getJNINativeRegistrations } from '../../syntax/kotlin/JNINativeRegistrations.js';
|
|
6
|
+
import { createJNIHybridObjectRegistration } from '../../syntax/kotlin/KotlinHybridObjectRegistration.js';
|
|
7
|
+
import { indent } from '../../utils.js';
|
|
8
|
+
import { getBuildingWithGeneratedCmakeDefinition } from './createCMakeExtension.js';
|
|
9
|
+
export function createHybridObjectIntializer() {
|
|
10
|
+
const cxxNamespace = NitroConfig.current.getCxxNamespace('c++');
|
|
11
|
+
const cppLibName = NitroConfig.current.getAndroidCxxLibName();
|
|
12
|
+
const javaNamespace = NitroConfig.current.getAndroidPackage('java/kotlin');
|
|
13
|
+
const autolinkingClassName = `${NitroConfig.current.getAndroidCxxLibName()}OnLoad`;
|
|
14
|
+
const jniRegistrations = getJNINativeRegistrations()
|
|
15
|
+
.map((r) => `${r.namespace}::${r.className}::registerNatives();`)
|
|
16
|
+
.filter(isNotDuplicate);
|
|
17
|
+
const autolinkedHybridObjects = NitroConfig.current.getAutolinkedHybridObjects();
|
|
18
|
+
const cppHybridObjectImports = [];
|
|
19
|
+
const cppRegistrations = [];
|
|
20
|
+
for (const hybridObjectName of Object.keys(autolinkedHybridObjects)) {
|
|
21
|
+
const config = autolinkedHybridObjects[hybridObjectName];
|
|
22
|
+
if (config?.cpp != null) {
|
|
23
|
+
// Autolink a C++ HybridObject!
|
|
24
|
+
const { cppCode, requiredImports } = createCppHybridObjectRegistration({
|
|
25
|
+
hybridObjectName: hybridObjectName,
|
|
26
|
+
cppClassName: config.cpp,
|
|
27
|
+
});
|
|
28
|
+
cppHybridObjectImports.push(...requiredImports);
|
|
29
|
+
cppRegistrations.push(cppCode);
|
|
30
|
+
}
|
|
31
|
+
if (config?.kotlin != null) {
|
|
32
|
+
// Autolink a Kotlin HybridObject through JNI/C++!
|
|
33
|
+
const { cppCode, requiredImports } = createJNIHybridObjectRegistration({
|
|
34
|
+
hybridObjectName: hybridObjectName,
|
|
35
|
+
jniClassName: config.kotlin,
|
|
36
|
+
});
|
|
37
|
+
cppHybridObjectImports.push(...requiredImports);
|
|
38
|
+
cppRegistrations.push(cppCode);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const buildingWithDefinition = getBuildingWithGeneratedCmakeDefinition();
|
|
42
|
+
const includes = [
|
|
43
|
+
...getJNINativeRegistrations().map((r) => includeHeader(r.import)),
|
|
44
|
+
...cppHybridObjectImports.map((i) => includeHeader(i)),
|
|
45
|
+
]
|
|
46
|
+
.filter(isNotDuplicate)
|
|
47
|
+
.join('\n');
|
|
48
|
+
const hppCode = `
|
|
49
|
+
${createFileMetadataString(`${autolinkingClassName}.hpp`)}
|
|
50
|
+
|
|
51
|
+
#include <jni.h>
|
|
52
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
53
|
+
|
|
54
|
+
namespace ${cxxNamespace} {
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Initializes the native (C++) part of ${cppLibName}, and autolinks all Hybrid Objects.
|
|
58
|
+
* Call this in your \`JNI_OnLoad\` function (probably inside \`cpp-adapter.cpp\`).
|
|
59
|
+
* Example:
|
|
60
|
+
* \`\`\`cpp (cpp-adapter.cpp)
|
|
61
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
62
|
+
* return ${cxxNamespace}::initialize(vm);
|
|
63
|
+
* }
|
|
64
|
+
* \`\`\`
|
|
65
|
+
*/
|
|
66
|
+
int initialize(JavaVM* vm);
|
|
67
|
+
|
|
68
|
+
} // namespace ${cxxNamespace}
|
|
69
|
+
|
|
70
|
+
`;
|
|
71
|
+
const cppCode = `
|
|
72
|
+
${createFileMetadataString(`${autolinkingClassName}.cpp`)}
|
|
73
|
+
|
|
74
|
+
#ifndef ${buildingWithDefinition}
|
|
75
|
+
#error ${autolinkingClassName}.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
76
|
+
#endif
|
|
77
|
+
|
|
78
|
+
#include "${autolinkingClassName}.hpp"
|
|
79
|
+
|
|
80
|
+
#include <jni.h>
|
|
81
|
+
#include <fbjni/fbjni.h>
|
|
82
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
83
|
+
|
|
84
|
+
${includes}
|
|
85
|
+
|
|
86
|
+
namespace ${cxxNamespace} {
|
|
87
|
+
|
|
88
|
+
int initialize(JavaVM* vm) {
|
|
89
|
+
using namespace margelo::nitro;
|
|
90
|
+
using namespace ${cxxNamespace};
|
|
91
|
+
using namespace facebook;
|
|
92
|
+
|
|
93
|
+
return facebook::jni::initialize(vm, [] {
|
|
94
|
+
// Register native JNI methods
|
|
95
|
+
${indent(jniRegistrations.join('\n'), ' ')}
|
|
96
|
+
|
|
97
|
+
// Register Nitro Hybrid Objects
|
|
98
|
+
${indent(cppRegistrations.join('\n'), ' ')}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
} // namespace ${cxxNamespace}
|
|
103
|
+
`.trim();
|
|
104
|
+
const kotlinCode = `
|
|
105
|
+
${createFileMetadataString(`${autolinkingClassName}.kt`)}
|
|
106
|
+
|
|
107
|
+
package ${javaNamespace}
|
|
108
|
+
|
|
109
|
+
import android.util.Log
|
|
110
|
+
|
|
111
|
+
internal class ${autolinkingClassName} {
|
|
112
|
+
companion object {
|
|
113
|
+
private const val TAG = "${autolinkingClassName}"
|
|
114
|
+
private var didLoad = false
|
|
115
|
+
/**
|
|
116
|
+
* Initializes the native part of "${cppLibName}".
|
|
117
|
+
* This method is idempotent and can be called more than once.
|
|
118
|
+
*/
|
|
119
|
+
@JvmStatic
|
|
120
|
+
fun initializeNative() {
|
|
121
|
+
if (didLoad) return
|
|
122
|
+
try {
|
|
123
|
+
Log.i(TAG, "Loading ${cppLibName} C++ library...")
|
|
124
|
+
System.loadLibrary("${cppLibName}")
|
|
125
|
+
Log.i(TAG, "Successfully loaded ${cppLibName} C++ library!")
|
|
126
|
+
didLoad = true
|
|
127
|
+
} catch (e: Error) {
|
|
128
|
+
Log.e(TAG, "Failed to load ${cppLibName} C++ library! Is it properly installed and linked? " +
|
|
129
|
+
"Is the name correct? (see \`CMakeLists.txt\`, at \`add_library(...)\`)", e)
|
|
130
|
+
throw e
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
`.trim();
|
|
136
|
+
return [
|
|
137
|
+
{
|
|
138
|
+
content: hppCode,
|
|
139
|
+
language: 'c++',
|
|
140
|
+
name: `${autolinkingClassName}.hpp`,
|
|
141
|
+
platform: 'android',
|
|
142
|
+
subdirectory: [],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
content: cppCode,
|
|
146
|
+
language: 'c++',
|
|
147
|
+
name: `${autolinkingClassName}.cpp`,
|
|
148
|
+
platform: 'android',
|
|
149
|
+
subdirectory: [],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
content: kotlinCode,
|
|
153
|
+
language: 'kotlin',
|
|
154
|
+
name: `${autolinkingClassName}.kt`,
|
|
155
|
+
platform: 'android',
|
|
156
|
+
subdirectory: ['kotlin', ...javaNamespace.split('.')],
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SourceFile, SourceImport } from '../syntax/SourceFile.js';
|
|
2
|
+
import type { Autolinking } from './Autolinking.js';
|
|
3
|
+
interface JNIHybridRegistration {
|
|
4
|
+
sourceImport: SourceImport;
|
|
5
|
+
registrationCode: string;
|
|
6
|
+
}
|
|
7
|
+
interface AndroidAutolinking extends Autolinking {
|
|
8
|
+
jniHybridRegistrations: JNIHybridRegistration[];
|
|
9
|
+
}
|
|
10
|
+
export declare function createAndroidAutolinking(allFiles: SourceFile[]): AndroidAutolinking;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createCMakeExtension } from './android/createCMakeExtension.js';
|
|
2
|
+
import { createGradleExtension } from './android/createGradleExtension.js';
|
|
3
|
+
import { createHybridObjectIntializer } from './android/createHybridObjectInitializer.js';
|
|
4
|
+
export function createAndroidAutolinking(allFiles) {
|
|
5
|
+
const cmakeExtension = createCMakeExtension(allFiles);
|
|
6
|
+
const gradleExtension = createGradleExtension();
|
|
7
|
+
const hybridObjectInitializer = createHybridObjectIntializer();
|
|
8
|
+
return {
|
|
9
|
+
platform: 'android',
|
|
10
|
+
jniHybridRegistrations: [],
|
|
11
|
+
sourceFiles: [cmakeExtension, gradleExtension, ...hybridObjectInitializer],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createHybridObjectIntializer } from './ios/createHybridObjectInitializer.js';
|
|
2
|
+
import { createPodspecRubyExtension } from './ios/createPodspecRubyExtension.js';
|
|
3
|
+
import { createSwiftCxxBridge } from './ios/createSwiftCxxBridge.js';
|
|
4
|
+
import { createSwiftUmbrellaHeader } from './ios/createSwiftUmbrellaHeader.js';
|
|
5
|
+
export function createIOSAutolinking() {
|
|
6
|
+
const podspecExtension = createPodspecRubyExtension();
|
|
7
|
+
const swiftCxxBridge = createSwiftCxxBridge();
|
|
8
|
+
const swiftUmbrellaHeader = createSwiftUmbrellaHeader();
|
|
9
|
+
const hybridObjectInitializer = createHybridObjectIntializer();
|
|
10
|
+
return {
|
|
11
|
+
platform: 'ios',
|
|
12
|
+
sourceFiles: [
|
|
13
|
+
podspecExtension,
|
|
14
|
+
...swiftCxxBridge,
|
|
15
|
+
swiftUmbrellaHeader,
|
|
16
|
+
...hybridObjectInitializer,
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SourceFile } from '../../syntax/SourceFile.js';
|
|
2
|
+
type ObjcFile = Omit<SourceFile, 'language'> & {
|
|
3
|
+
language: 'objective-c++';
|
|
4
|
+
};
|
|
5
|
+
type SwiftFile = Omit<SourceFile, 'language'> & {
|
|
6
|
+
language: 'swift';
|
|
7
|
+
};
|
|
8
|
+
export declare function createHybridObjectIntializer(): [ObjcFile, SwiftFile] | [];
|
|
9
|
+
export {};
|