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,97 @@
|
|
|
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 } from '../../syntax/helpers.js';
|
|
5
|
+
import { createSwiftHybridObjectRegistration } from '../../syntax/swift/SwiftHybridObjectRegistration.js';
|
|
6
|
+
import { indent } from '../../utils.js';
|
|
7
|
+
import { getUmbrellaHeaderName } from './createSwiftUmbrellaHeader.js';
|
|
8
|
+
export function createHybridObjectIntializer() {
|
|
9
|
+
const autolinkingClassName = `${NitroConfig.current.getIosModuleName()}Autolinking`;
|
|
10
|
+
const umbrellaHeaderName = getUmbrellaHeaderName();
|
|
11
|
+
const bridgeNamespace = NitroConfig.current.getSwiftBridgeNamespace('swift');
|
|
12
|
+
const autolinkedHybridObjects = NitroConfig.current.getAutolinkedHybridObjects();
|
|
13
|
+
const swiftFunctions = [];
|
|
14
|
+
const cppRegistrations = [];
|
|
15
|
+
const cppImports = [];
|
|
16
|
+
let containsSwiftObjects = false;
|
|
17
|
+
for (const hybridObjectName of Object.keys(autolinkedHybridObjects)) {
|
|
18
|
+
const config = autolinkedHybridObjects[hybridObjectName];
|
|
19
|
+
if (config?.cpp != null) {
|
|
20
|
+
// Autolink a C++ HybridObject!
|
|
21
|
+
const { cppCode, requiredImports } = createCppHybridObjectRegistration({
|
|
22
|
+
hybridObjectName: hybridObjectName,
|
|
23
|
+
cppClassName: config.cpp,
|
|
24
|
+
});
|
|
25
|
+
cppImports.push(...requiredImports);
|
|
26
|
+
cppRegistrations.push(cppCode);
|
|
27
|
+
}
|
|
28
|
+
if (config?.swift != null) {
|
|
29
|
+
// Autolink a Swift HybridObject!
|
|
30
|
+
containsSwiftObjects = true;
|
|
31
|
+
const { cppCode, requiredImports, swiftFunction } = createSwiftHybridObjectRegistration({
|
|
32
|
+
hybridObjectName: hybridObjectName,
|
|
33
|
+
swiftClassName: config.swift,
|
|
34
|
+
});
|
|
35
|
+
cppImports.push(...requiredImports);
|
|
36
|
+
cppRegistrations.push(cppCode);
|
|
37
|
+
swiftFunctions.push(swiftFunction);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (cppRegistrations.length === 0) {
|
|
41
|
+
// Nothing to autolink!
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
const umbrellaImport = containsSwiftObjects
|
|
45
|
+
? `#import "${umbrellaHeaderName}"`
|
|
46
|
+
: '';
|
|
47
|
+
const imports = cppImports.map((i) => includeHeader(i, true)).join('\n');
|
|
48
|
+
const objcCode = `
|
|
49
|
+
${createFileMetadataString(`${autolinkingClassName}.mm`)}
|
|
50
|
+
|
|
51
|
+
#import <Foundation/Foundation.h>
|
|
52
|
+
#import <NitroModules/HybridObjectRegistry.hpp>
|
|
53
|
+
${umbrellaImport}
|
|
54
|
+
#import <type_traits>
|
|
55
|
+
|
|
56
|
+
${imports}
|
|
57
|
+
|
|
58
|
+
@interface ${autolinkingClassName} : NSObject
|
|
59
|
+
@end
|
|
60
|
+
|
|
61
|
+
@implementation ${autolinkingClassName}
|
|
62
|
+
|
|
63
|
+
+ (void) load {
|
|
64
|
+
using namespace margelo::nitro;
|
|
65
|
+
using namespace ${NitroConfig.current.getCxxNamespace('c++')};
|
|
66
|
+
|
|
67
|
+
${indent(cppRegistrations.join('\n'), ' ')}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@end
|
|
71
|
+
`.trim();
|
|
72
|
+
const swiftCode = `
|
|
73
|
+
${createFileMetadataString(`${autolinkingClassName}.swift`)}
|
|
74
|
+
|
|
75
|
+
public final class ${autolinkingClassName} {
|
|
76
|
+
public typealias bridge = ${bridgeNamespace}
|
|
77
|
+
|
|
78
|
+
${indent(swiftFunctions.join('\n\n'), ' ')}
|
|
79
|
+
}
|
|
80
|
+
`.trim();
|
|
81
|
+
return [
|
|
82
|
+
{
|
|
83
|
+
content: objcCode,
|
|
84
|
+
language: 'objective-c++',
|
|
85
|
+
name: `${autolinkingClassName}.mm`,
|
|
86
|
+
platform: 'ios',
|
|
87
|
+
subdirectory: [],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
content: swiftCode,
|
|
91
|
+
language: 'swift',
|
|
92
|
+
name: `${autolinkingClassName}.swift`,
|
|
93
|
+
platform: 'ios',
|
|
94
|
+
subdirectory: [],
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { createFileMetadataString } from '../../syntax/helpers.js';
|
|
3
|
+
export function createPodspecRubyExtension() {
|
|
4
|
+
const name = NitroConfig.current.getIosModuleName();
|
|
5
|
+
const code = `
|
|
6
|
+
${createFileMetadataString(`${name}+autolinking.rb`, '#')}
|
|
7
|
+
|
|
8
|
+
# This is a Ruby script that adds all files generated by Nitrogen
|
|
9
|
+
# to the given podspec.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your .podspec:
|
|
12
|
+
# \`\`\`ruby
|
|
13
|
+
# Pod::Spec.new do |spec|
|
|
14
|
+
# # ...
|
|
15
|
+
#
|
|
16
|
+
# # Add all files generated by Nitrogen
|
|
17
|
+
# load 'nitrogen/generated/ios/${name}+autolinking.rb'
|
|
18
|
+
# add_nitrogen_files(spec)
|
|
19
|
+
# end
|
|
20
|
+
# \`\`\`
|
|
21
|
+
|
|
22
|
+
def add_nitrogen_files(spec)
|
|
23
|
+
Pod::UI.puts "[NitroModules] 🔥 ${name} is boosted by nitro!"
|
|
24
|
+
|
|
25
|
+
spec.dependency "NitroModules"
|
|
26
|
+
|
|
27
|
+
current_source_files = Array(spec.attributes_hash['source_files'])
|
|
28
|
+
spec.source_files = current_source_files + [
|
|
29
|
+
# Generated cross-platform specs
|
|
30
|
+
"nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
|
|
31
|
+
# Generated bridges for the cross-platform specs
|
|
32
|
+
"nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
current_public_header_files = Array(spec.attributes_hash['public_header_files'])
|
|
36
|
+
spec.public_header_files = current_public_header_files + [
|
|
37
|
+
# Generated specs
|
|
38
|
+
"nitrogen/generated/shared/**/*.{h,hpp}",
|
|
39
|
+
# Swift to C++ bridging helpers
|
|
40
|
+
"nitrogen/generated/ios/${name}-Swift-Cxx-Bridge.hpp"
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
current_private_header_files = Array(spec.attributes_hash['private_header_files'])
|
|
44
|
+
spec.private_header_files = current_private_header_files + [
|
|
45
|
+
# iOS specific specs
|
|
46
|
+
"nitrogen/generated/ios/c++/**/*.{h,hpp}",
|
|
47
|
+
# Views are framework-specific and should be private
|
|
48
|
+
"nitrogen/generated/shared/**/views/**/*"
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
|
|
52
|
+
spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
|
|
53
|
+
# Use C++ 20
|
|
54
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
55
|
+
# Enables C++ <-> Swift interop (by default it's only C)
|
|
56
|
+
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
|
+
# Enables stricter modular headers
|
|
58
|
+
"DEFINES_MODULE" => "YES",
|
|
59
|
+
})
|
|
60
|
+
end
|
|
61
|
+
`.trim();
|
|
62
|
+
return {
|
|
63
|
+
content: code,
|
|
64
|
+
language: 'ruby',
|
|
65
|
+
name: `${name}+autolinking.rb`,
|
|
66
|
+
platform: 'ios',
|
|
67
|
+
subdirectory: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { includeHeader } from '../../syntax/c++/includeNitroHeader.js';
|
|
3
|
+
import { getAllKnownTypes } from '../../syntax/createType.js';
|
|
4
|
+
import { createFileMetadataString, isNotDuplicate, } from '../../syntax/helpers.js';
|
|
5
|
+
import { getReferencedTypes } from '../../syntax/getReferencedTypes.js';
|
|
6
|
+
import { SwiftCxxBridgedType } from '../../syntax/swift/SwiftCxxBridgedType.js';
|
|
7
|
+
import { filterDuplicateHelperBridges, indent } from '../../utils.js';
|
|
8
|
+
import { getTypeAs } from '../../syntax/types/getTypeAs.js';
|
|
9
|
+
import { HybridObjectType } from '../../syntax/types/HybridObjectType.js';
|
|
10
|
+
import { getForwardDeclaration } from '../../syntax/c++/getForwardDeclaration.js';
|
|
11
|
+
import { getHybridObjectName } from '../../syntax/getHybridObjectName.js';
|
|
12
|
+
export function createSwiftCxxBridge() {
|
|
13
|
+
const bridgeName = NitroConfig.current.getSwiftBridgeHeaderName();
|
|
14
|
+
const bridgeNamespace = NitroConfig.current.getSwiftBridgeNamespace('c++');
|
|
15
|
+
const types = getAllKnownTypes('swift').map((t) => new SwiftCxxBridgedType(t));
|
|
16
|
+
const bridges = types
|
|
17
|
+
.flatMap((t) => {
|
|
18
|
+
const referenced = getReferencedTypes(t.type);
|
|
19
|
+
return referenced.map((r) => {
|
|
20
|
+
const bridge = new SwiftCxxBridgedType(r);
|
|
21
|
+
return bridge.getRequiredBridge();
|
|
22
|
+
});
|
|
23
|
+
})
|
|
24
|
+
.filter((b) => b != null)
|
|
25
|
+
.flatMap((b) => [b, ...b?.dependencies])
|
|
26
|
+
.filter(filterDuplicateHelperBridges);
|
|
27
|
+
const headerHelperFunctions = bridges
|
|
28
|
+
.map((b) => `// pragma MARK: ${b.cxxType}\n${b.cxxHeader.code}`)
|
|
29
|
+
.filter(isNotDuplicate)
|
|
30
|
+
.join('\n\n');
|
|
31
|
+
const implementationHelperFunctions = bridges
|
|
32
|
+
.map((b) => {
|
|
33
|
+
if (b.cxxImplementation == null)
|
|
34
|
+
return undefined;
|
|
35
|
+
else
|
|
36
|
+
return `// pragma MARK: ${b.cxxType}\n${b.cxxImplementation.code}`;
|
|
37
|
+
})
|
|
38
|
+
.filter((c) => c != null)
|
|
39
|
+
.filter(isNotDuplicate)
|
|
40
|
+
.join('\n\n');
|
|
41
|
+
const requiredImportsHeader = bridges.flatMap((b) => b.cxxHeader.requiredIncludes);
|
|
42
|
+
const includesHeader = requiredImportsHeader
|
|
43
|
+
.map((i) => includeHeader(i, true))
|
|
44
|
+
.filter(isNotDuplicate);
|
|
45
|
+
const forwardDeclarationsHeader = requiredImportsHeader
|
|
46
|
+
.map((i) => i.forwardDeclaration)
|
|
47
|
+
.filter((f) => f != null)
|
|
48
|
+
.filter(isNotDuplicate);
|
|
49
|
+
const includesImplementation = bridges
|
|
50
|
+
.flatMap((b) => b.cxxImplementation?.requiredIncludes)
|
|
51
|
+
.filter((i) => i != null)
|
|
52
|
+
.map((i) => includeHeader(i, true))
|
|
53
|
+
.filter(isNotDuplicate);
|
|
54
|
+
const forwardDeclaredSwiftTypes = types
|
|
55
|
+
.filter((t) => t.type.kind === 'hybrid-object')
|
|
56
|
+
.map((t) => {
|
|
57
|
+
const hybridObject = getTypeAs(t.type, HybridObjectType);
|
|
58
|
+
const hybridObjectModuleName = hybridObject.sourceConfig.getIosModuleName();
|
|
59
|
+
const { HybridTSpecCxx } = getHybridObjectName(hybridObject.hybridObjectName);
|
|
60
|
+
return getForwardDeclaration('class', HybridTSpecCxx, hybridObjectModuleName);
|
|
61
|
+
})
|
|
62
|
+
.filter(isNotDuplicate);
|
|
63
|
+
const header = `
|
|
64
|
+
${createFileMetadataString(`${bridgeName}.hpp`)}
|
|
65
|
+
|
|
66
|
+
#pragma once
|
|
67
|
+
|
|
68
|
+
// Forward declarations of C++ defined types
|
|
69
|
+
${forwardDeclarationsHeader.sort().join('\n')}
|
|
70
|
+
|
|
71
|
+
// Forward declarations of Swift defined types
|
|
72
|
+
${forwardDeclaredSwiftTypes.sort().join('\n')}
|
|
73
|
+
|
|
74
|
+
// Include C++ defined types
|
|
75
|
+
${includesHeader.sort().join('\n')}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Contains specialized versions of C++ templated types so they can be accessed from Swift,
|
|
79
|
+
* as well as helper functions to interact with those C++ types from Swift.
|
|
80
|
+
*/
|
|
81
|
+
namespace ${bridgeNamespace} {
|
|
82
|
+
|
|
83
|
+
${indent(headerHelperFunctions, ' ')}
|
|
84
|
+
|
|
85
|
+
} // namespace ${bridgeNamespace}
|
|
86
|
+
`;
|
|
87
|
+
const source = `
|
|
88
|
+
${createFileMetadataString(`${bridgeName}.cpp`)}
|
|
89
|
+
|
|
90
|
+
#include "${bridgeName}.hpp"
|
|
91
|
+
|
|
92
|
+
// Include C++ implementation defined types
|
|
93
|
+
${includesImplementation.sort().join('\n')}
|
|
94
|
+
|
|
95
|
+
namespace ${bridgeNamespace} {
|
|
96
|
+
|
|
97
|
+
${indent(implementationHelperFunctions, ' ')}
|
|
98
|
+
|
|
99
|
+
} // namespace ${bridgeNamespace}
|
|
100
|
+
`;
|
|
101
|
+
const files = [];
|
|
102
|
+
files.push({
|
|
103
|
+
content: header,
|
|
104
|
+
language: 'c++',
|
|
105
|
+
name: `${bridgeName}.hpp`,
|
|
106
|
+
platform: 'ios',
|
|
107
|
+
subdirectory: [],
|
|
108
|
+
});
|
|
109
|
+
files.push({
|
|
110
|
+
content: source,
|
|
111
|
+
language: 'c++',
|
|
112
|
+
name: `${bridgeName}.cpp`,
|
|
113
|
+
platform: 'ios',
|
|
114
|
+
subdirectory: [],
|
|
115
|
+
});
|
|
116
|
+
return files;
|
|
117
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { getForwardDeclaration } from '../../syntax/c++/getForwardDeclaration.js';
|
|
3
|
+
import { includeHeader } from '../../syntax/c++/includeNitroHeader.js';
|
|
4
|
+
import { getAllKnownTypes } from '../../syntax/createType.js';
|
|
5
|
+
import { getHybridObjectName } from '../../syntax/getHybridObjectName.js';
|
|
6
|
+
import { createFileMetadataString, isNotDuplicate, } from '../../syntax/helpers.js';
|
|
7
|
+
import { getTypeAs } from '../../syntax/types/getTypeAs.js';
|
|
8
|
+
import { HybridObjectType } from '../../syntax/types/HybridObjectType.js';
|
|
9
|
+
export function getUmbrellaHeaderName() {
|
|
10
|
+
const moduleName = NitroConfig.current.getIosModuleName();
|
|
11
|
+
return `${moduleName}-Swift-Cxx-Umbrella.hpp`;
|
|
12
|
+
}
|
|
13
|
+
export function createSwiftUmbrellaHeader() {
|
|
14
|
+
const moduleName = NitroConfig.current.getIosModuleName();
|
|
15
|
+
const filename = getUmbrellaHeaderName();
|
|
16
|
+
const types = getAllKnownTypes('swift');
|
|
17
|
+
const swiftForwardDeclares = types
|
|
18
|
+
.filter((t) => t.kind === 'hybrid-object')
|
|
19
|
+
.map((t) => {
|
|
20
|
+
const hybridObjectType = getTypeAs(t, HybridObjectType);
|
|
21
|
+
const hybridObjectModuleName = hybridObjectType.sourceConfig.getIosModuleName();
|
|
22
|
+
const name = getHybridObjectName(hybridObjectType.hybridObjectName);
|
|
23
|
+
return getForwardDeclaration('class', name.HybridTSpecCxx, hybridObjectModuleName);
|
|
24
|
+
})
|
|
25
|
+
.filter(isNotDuplicate);
|
|
26
|
+
const imports = types.flatMap((t) => t.getRequiredImports('c++'));
|
|
27
|
+
const forwardDeclarations = imports
|
|
28
|
+
.map((i) => i.forwardDeclaration)
|
|
29
|
+
.filter((f) => f != null)
|
|
30
|
+
.filter(isNotDuplicate);
|
|
31
|
+
const includes = imports.map((i) => includeHeader(i)).filter(isNotDuplicate);
|
|
32
|
+
const code = `
|
|
33
|
+
${createFileMetadataString(filename, '///')}
|
|
34
|
+
|
|
35
|
+
#pragma once
|
|
36
|
+
|
|
37
|
+
// Forward declarations of C++ defined types
|
|
38
|
+
${forwardDeclarations.sort().join('\n')}
|
|
39
|
+
|
|
40
|
+
// Include C++ defined types
|
|
41
|
+
${includes.sort().join('\n')}
|
|
42
|
+
|
|
43
|
+
// C++ helpers for Swift
|
|
44
|
+
#include "${moduleName}-Swift-Cxx-Bridge.hpp"
|
|
45
|
+
|
|
46
|
+
// Common C++ types used in Swift
|
|
47
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
48
|
+
#include <NitroModules/AnyMapUtils.hpp>
|
|
49
|
+
#include <NitroModules/RuntimeError.hpp>
|
|
50
|
+
#include <NitroModules/DateToChronoDate.hpp>
|
|
51
|
+
|
|
52
|
+
// Forward declarations of Swift defined types
|
|
53
|
+
${swiftForwardDeclares.sort().join('\n')}
|
|
54
|
+
|
|
55
|
+
// Include Swift defined types
|
|
56
|
+
#if __has_include("${moduleName}-Swift.h")
|
|
57
|
+
// This header is generated by Xcode/Swift on every app build.
|
|
58
|
+
// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "${moduleName}".
|
|
59
|
+
#include "${moduleName}-Swift.h"
|
|
60
|
+
// Same as above, but used when building with frameworks (\`use_frameworks\`)
|
|
61
|
+
#elif __has_include(<${moduleName}/${moduleName}-Swift.h>)
|
|
62
|
+
#include <${moduleName}/${moduleName}-Swift.h>
|
|
63
|
+
#else
|
|
64
|
+
#error ${moduleName}'s autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "${moduleName}", and try building the app first.
|
|
65
|
+
#endif
|
|
66
|
+
`;
|
|
67
|
+
return {
|
|
68
|
+
content: code,
|
|
69
|
+
language: 'c++',
|
|
70
|
+
name: filename,
|
|
71
|
+
platform: 'ios',
|
|
72
|
+
subdirectory: [],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { NitroUserConfig } from './NitroUserConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the properly parsed `nitro.json` config of the current executing directory.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NitroConfig {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private static singleton;
|
|
8
|
+
constructor(config: NitroUserConfig);
|
|
9
|
+
static get current(): NitroConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`).
|
|
12
|
+
* This will be loaded via `System.loadLibrary(...)`.
|
|
13
|
+
* @example `NitroTest`
|
|
14
|
+
*/
|
|
15
|
+
getAndroidCxxLibName(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the iOS module name (aka Pod name) of the module that will be generated.
|
|
18
|
+
* @example `NitroTest`
|
|
19
|
+
*/
|
|
20
|
+
getIosModuleName(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Represents the C++ namespace of the module that will be generated.
|
|
23
|
+
* This can have multiple sub-namespaces, and is always relative to `margelo::nitro`.
|
|
24
|
+
* @example `['image']` -> `margelo::nitro::image`
|
|
25
|
+
*/
|
|
26
|
+
getCxxNamespace(language: 'c++' | 'swift', ...subDefinitionName: string[]): string;
|
|
27
|
+
/**
|
|
28
|
+
* Represents the Android namespace of the module that will be generated.
|
|
29
|
+
* This can have multiple sub-namespaces, and is always relative to `com.margelo.nitro`.
|
|
30
|
+
* @example `['image']` -> `com.margelo.nitro.image`
|
|
31
|
+
*/
|
|
32
|
+
getAndroidPackage(language: 'java/kotlin' | 'c++/jni', ...subPackage: string[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Return the directory of the android package, and a given sub-package.
|
|
35
|
+
* This will be used on android to put files from a package in their respective package folder.
|
|
36
|
+
*/
|
|
37
|
+
getAndroidPackageDirectory(...subPackage: string[]): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Get the autolinking configuration of all HybridObjects.
|
|
40
|
+
* Those will be generated and default-constructed.
|
|
41
|
+
*/
|
|
42
|
+
getAutolinkedHybridObjects(): NitroUserConfig['autolinking'];
|
|
43
|
+
/**
|
|
44
|
+
* Get the paths that will be ignored when loading the TypeScript project.
|
|
45
|
+
* In most cases, this just contains `node_modules/`.
|
|
46
|
+
*/
|
|
47
|
+
getIgnorePaths(): string[];
|
|
48
|
+
getGitAttributesGeneratedFlag(): boolean;
|
|
49
|
+
get isExternalConfig(): boolean;
|
|
50
|
+
getSwiftBridgeHeaderName(): string;
|
|
51
|
+
getSwiftBridgeNamespace(language: 'c++' | 'swift'): string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { readUserConfig } from './getConfig.js';
|
|
3
|
+
const CXX_BASE_NAMESPACE = ['margelo', 'nitro'];
|
|
4
|
+
const ANDROID_BASE_NAMESPACE = ['com', 'margelo', 'nitro'];
|
|
5
|
+
/**
|
|
6
|
+
* Represents the properly parsed `nitro.json` config of the current executing directory.
|
|
7
|
+
*/
|
|
8
|
+
export class NitroConfig {
|
|
9
|
+
config;
|
|
10
|
+
static singleton;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
static get current() {
|
|
15
|
+
if (this.singleton == null) {
|
|
16
|
+
console.log(chalk.reset(`🔧 Loading ${chalk.underline('nitro.json')} config...`));
|
|
17
|
+
const defaultConfigPath = './nitro.json';
|
|
18
|
+
const config = readUserConfig(defaultConfigPath);
|
|
19
|
+
this.singleton = new NitroConfig(config);
|
|
20
|
+
}
|
|
21
|
+
return this.singleton;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`).
|
|
25
|
+
* This will be loaded via `System.loadLibrary(...)`.
|
|
26
|
+
* @example `NitroTest`
|
|
27
|
+
*/
|
|
28
|
+
getAndroidCxxLibName() {
|
|
29
|
+
return this.config.android.androidCxxLibName;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the iOS module name (aka Pod name) of the module that will be generated.
|
|
33
|
+
* @example `NitroTest`
|
|
34
|
+
*/
|
|
35
|
+
getIosModuleName() {
|
|
36
|
+
return this.config.ios.iosModuleName;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Represents the C++ namespace of the module that will be generated.
|
|
40
|
+
* This can have multiple sub-namespaces, and is always relative to `margelo::nitro`.
|
|
41
|
+
* @example `['image']` -> `margelo::nitro::image`
|
|
42
|
+
*/
|
|
43
|
+
getCxxNamespace(language, ...subDefinitionName) {
|
|
44
|
+
const userNamespace = this.config.cxxNamespace;
|
|
45
|
+
const namespace = [
|
|
46
|
+
...CXX_BASE_NAMESPACE,
|
|
47
|
+
...userNamespace,
|
|
48
|
+
...subDefinitionName,
|
|
49
|
+
];
|
|
50
|
+
switch (language) {
|
|
51
|
+
case 'c++':
|
|
52
|
+
return namespace.join('::');
|
|
53
|
+
case 'swift':
|
|
54
|
+
return namespace.join('.');
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Invalid language for getCxxNamespace: ${language}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Represents the Android namespace of the module that will be generated.
|
|
61
|
+
* This can have multiple sub-namespaces, and is always relative to `com.margelo.nitro`.
|
|
62
|
+
* @example `['image']` -> `com.margelo.nitro.image`
|
|
63
|
+
*/
|
|
64
|
+
getAndroidPackage(language, ...subPackage) {
|
|
65
|
+
const userPackage = this.config.android.androidNamespace;
|
|
66
|
+
const namespace = [...ANDROID_BASE_NAMESPACE, ...userPackage, ...subPackage];
|
|
67
|
+
switch (language) {
|
|
68
|
+
case 'java/kotlin':
|
|
69
|
+
return namespace.join('.');
|
|
70
|
+
case 'c++/jni':
|
|
71
|
+
return namespace.join('/');
|
|
72
|
+
default:
|
|
73
|
+
throw new Error(`Invalid language for getAndroidPackage: ${language}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Return the directory of the android package, and a given sub-package.
|
|
78
|
+
* This will be used on android to put files from a package in their respective package folder.
|
|
79
|
+
*/
|
|
80
|
+
getAndroidPackageDirectory(...subPackage) {
|
|
81
|
+
const userPackage = this.config.android.androidNamespace;
|
|
82
|
+
return [...ANDROID_BASE_NAMESPACE, ...userPackage, ...subPackage];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the autolinking configuration of all HybridObjects.
|
|
86
|
+
* Those will be generated and default-constructed.
|
|
87
|
+
*/
|
|
88
|
+
getAutolinkedHybridObjects() {
|
|
89
|
+
return this.config.autolinking;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the paths that will be ignored when loading the TypeScript project.
|
|
93
|
+
* In most cases, this just contains `node_modules/`.
|
|
94
|
+
*/
|
|
95
|
+
getIgnorePaths() {
|
|
96
|
+
return this.config.ignorePaths ?? [];
|
|
97
|
+
}
|
|
98
|
+
getGitAttributesGeneratedFlag() {
|
|
99
|
+
return this.config.gitAttributesGeneratedFlag ?? false;
|
|
100
|
+
}
|
|
101
|
+
get isExternalConfig() {
|
|
102
|
+
// If the C++ namespaces are NOT equal, we are an external config.
|
|
103
|
+
return (this.getCxxNamespace('c++') !== NitroConfig.current.getCxxNamespace('c++'));
|
|
104
|
+
}
|
|
105
|
+
getSwiftBridgeHeaderName() {
|
|
106
|
+
const moduleName = this.getIosModuleName();
|
|
107
|
+
return `${moduleName}-Swift-Cxx-Bridge`;
|
|
108
|
+
}
|
|
109
|
+
getSwiftBridgeNamespace(language) {
|
|
110
|
+
return this.getCxxNamespace(language, 'bridge', 'swift');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const NitroUserConfigSchema: z.ZodObject<{
|
|
3
|
+
cxxNamespace: z.ZodArray<z.ZodString>;
|
|
4
|
+
ios: z.ZodObject<{
|
|
5
|
+
iosModuleName: z.ZodString;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
android: z.ZodObject<{
|
|
8
|
+
androidNamespace: z.ZodArray<z.ZodString>;
|
|
9
|
+
androidCxxLibName: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
autolinking: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
12
|
+
cpp: z.ZodOptional<z.ZodString>;
|
|
13
|
+
swift: z.ZodOptional<z.ZodString>;
|
|
14
|
+
kotlin: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>>;
|
|
16
|
+
ignorePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
17
|
+
gitAttributesGeneratedFlag: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/**
|
|
20
|
+
* Represents the structure of a `nitro.json` config file.
|
|
21
|
+
*/
|
|
22
|
+
export type NitroUserConfig = z.infer<typeof NitroUserConfigSchema>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Namespaces and package names in C++/Java will be matched with a regex.
|
|
3
|
+
const safeNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
4
|
+
const isNotReservedKeyword = (val) => !['core', 'nitro', 'NitroModules'].includes(val);
|
|
5
|
+
const isReservedKeywordError = {
|
|
6
|
+
message: `This value is reserved and cannot be used!`,
|
|
7
|
+
};
|
|
8
|
+
export const NitroUserConfigSchema = z.object({
|
|
9
|
+
/**
|
|
10
|
+
* Represents the C++ namespace of the module that will be generated.
|
|
11
|
+
*
|
|
12
|
+
* This can have multiple sub-namespaces, and is always relative to `margelo::nitro`.
|
|
13
|
+
* @example `['image']` -> `margelo::nitro::image`
|
|
14
|
+
*/
|
|
15
|
+
cxxNamespace: z
|
|
16
|
+
.array(z
|
|
17
|
+
.string()
|
|
18
|
+
.regex(safeNamePattern)
|
|
19
|
+
.refine(isNotReservedKeyword, isReservedKeywordError))
|
|
20
|
+
.min(1),
|
|
21
|
+
/**
|
|
22
|
+
* iOS specific options.
|
|
23
|
+
*/
|
|
24
|
+
ios: z.object({
|
|
25
|
+
/**
|
|
26
|
+
* Represents the iOS module name of the module that will be generated.
|
|
27
|
+
*
|
|
28
|
+
* This will be used to generate Swift bridges, as those are always namespaced within the clang module.
|
|
29
|
+
*
|
|
30
|
+
* If you are using CocoaPods, this should be the Pod name defined in the `.podspec`.
|
|
31
|
+
* @example `NitroTest`
|
|
32
|
+
*/
|
|
33
|
+
iosModuleName: z
|
|
34
|
+
.string()
|
|
35
|
+
.regex(safeNamePattern)
|
|
36
|
+
.refine(isNotReservedKeyword, isReservedKeywordError),
|
|
37
|
+
}),
|
|
38
|
+
/**
|
|
39
|
+
* Android specific options.
|
|
40
|
+
*/
|
|
41
|
+
android: z.object({
|
|
42
|
+
/**
|
|
43
|
+
* Represents the Android namespace ("package") of the module that will be generated.
|
|
44
|
+
*
|
|
45
|
+
* This can have multiple sub-namespaces, and is always relative to `com.margelo.nitro`.
|
|
46
|
+
* @example `['image']` -> `com.margelo.nitro.image`
|
|
47
|
+
*/
|
|
48
|
+
androidNamespace: z
|
|
49
|
+
.array(z
|
|
50
|
+
.string()
|
|
51
|
+
.regex(safeNamePattern)
|
|
52
|
+
.refine(isNotReservedKeyword, isReservedKeywordError))
|
|
53
|
+
.min(1),
|
|
54
|
+
/**
|
|
55
|
+
* Represents the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`).
|
|
56
|
+
* This will be loaded via `System.loadLibrary(...)`.
|
|
57
|
+
* @example `NitroTest`
|
|
58
|
+
*/
|
|
59
|
+
androidCxxLibName: z
|
|
60
|
+
.string()
|
|
61
|
+
.regex(safeNamePattern)
|
|
62
|
+
.refine(isNotReservedKeyword, isReservedKeywordError),
|
|
63
|
+
}),
|
|
64
|
+
/**
|
|
65
|
+
* Configures the code that gets generated for autolinking (registering)
|
|
66
|
+
* Hybrid Object constructors.
|
|
67
|
+
*
|
|
68
|
+
* Each class listed here needs to have a default constructor/initializer that takes
|
|
69
|
+
* zero arguments.
|
|
70
|
+
*/
|
|
71
|
+
autolinking: z.record(z.string(), z.object({
|
|
72
|
+
cpp: z.string().optional(),
|
|
73
|
+
swift: z.string().optional(),
|
|
74
|
+
kotlin: z.string().optional(),
|
|
75
|
+
})),
|
|
76
|
+
/**
|
|
77
|
+
* A list of paths relative to the project directory that should be ignored by nitrogen.
|
|
78
|
+
* Nitrogen will not look for `.nitro.ts` files in these directories.
|
|
79
|
+
*/
|
|
80
|
+
ignorePaths: z.array(z.string()).optional(),
|
|
81
|
+
/**
|
|
82
|
+
* Configures whether all nitro-generated files are marked as
|
|
83
|
+
* [`linguist-generated`](https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github)
|
|
84
|
+
* for GitHub. This disables diffing for generated content and excludes them from language statistics.
|
|
85
|
+
* This is controlled via `nitrogen/generated/.gitattributes`.
|
|
86
|
+
*/
|
|
87
|
+
gitAttributesGeneratedFlag: z.boolean().optional().default(true),
|
|
88
|
+
});
|