From f7802e233930e11e31f19a7ee2eaec379c248a96 Mon Sep 17 00:00:00 2001 From: Patrick Kabwe Date: Wed, 4 Dec 2024 13:23:26 +0200 Subject: [PATCH] feat: Add a `nitro.schema.json` schema to validate `nitro.json` files (#390) * chore(nitro-config): adds a json schema for the nitro config file * chore: adds usage of nitro.schema.json * chore: adds usage of nitro.schema.json * fix: Format, move schema to docs, remote --------- Co-authored-by: Marc Rousavy --- docs/static/nitro.schema.json | 99 +++++++++++++++++++ .../nitrogen/src/config/NitroUserConfig.ts | 2 +- packages/react-native-nitro-image/nitro.json | 13 ++- packages/template/nitro.json | 13 ++- 4 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 docs/static/nitro.schema.json diff --git a/docs/static/nitro.schema.json b/docs/static/nitro.schema.json new file mode 100644 index 000000000..f2554a284 --- /dev/null +++ b/docs/static/nitro.schema.json @@ -0,0 +1,99 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Nitro Modules Configuration", + "type": "object", + "required": [ + "cxxNamespace", + "ios", + "android", + "autolinking" + ], + "properties": { + "cxxNamespace": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "description": "Represents the C++ namespace of the module that will be generated. This can have multiple sub-namespaces, and is always relative to `margelo::nitro`." + }, + "ios": { + "type": "object", + "required": [ + "iosModuleName" + ], + "properties": { + "iosModuleName": { + "type": "string", + "minLength": 1, + "description": "Represents the iOS module name of the module that will be generated This will be used to generate Swift bridges, as those are always namespaced within the clang module. If you are using CocoaPods, this should be the Pod name defined in the `.podspec`." + } + }, + "description": "Required: iOS configuration" + }, + "android": { + "type": "object", + "required": [ + "androidNamespace", + "androidCxxLibName" + ], + "properties": { + "androidNamespace": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "description": "Represents the Android namespace ('package') of the module that will be generated. This can have multiple sub-namespaces, and is always relative to `com.margelo.nitro`." + }, + "androidCxxLibName": { + "type": "string", + "minLength": 1, + "description": "Represents the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`). This will be loaded via `System.loadLibrary(...)`." + } + }, + "description": "Required: Android configuration" + }, + "autolinking": { + "type": "object", + "description": "Configures the code that gets generated for autolinking (registering) Hybrid Object constructors.", + "patternProperties": { + "^.*$": { + "type": "object", + "oneOf": [ + { + "properties": { + "cpp": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "cpp" + ] + }, + { + "properties": { + "swift": { + "type": "string" + }, + "kotlin": { + "type": "string" + } + }, + "minProperties": 1, + "additionalProperties": false + } + ] + } + } + }, + "ignorePaths": { + "type": "array", + "items": { + "type": "string" + }, + "description": "A list of paths relative to the project directory that should be ignored by nitrogen. Nitrogen will not look for `.nitro.ts` files in these directories." + } + } +} diff --git a/packages/nitrogen/src/config/NitroUserConfig.ts b/packages/nitrogen/src/config/NitroUserConfig.ts index d6432bb2c..e0a793266 100644 --- a/packages/nitrogen/src/config/NitroUserConfig.ts +++ b/packages/nitrogen/src/config/NitroUserConfig.ts @@ -64,7 +64,7 @@ export const NitroUserConfigSchema = z.object({ .min(1), /** - * Returns the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`). + * Represents the name of the Android C++ library (aka name in CMakeLists.txt `add_library(..)`). * This will be loaded via `System.loadLibrary(...)`. * @example `NitroImage` */ diff --git a/packages/react-native-nitro-image/nitro.json b/packages/react-native-nitro-image/nitro.json index 5f3dedacb..91edec392 100644 --- a/packages/react-native-nitro-image/nitro.json +++ b/packages/react-native-nitro-image/nitro.json @@ -1,10 +1,15 @@ { - "cxxNamespace": ["image"], + "$schema": "https://nitro.margelo.com/nitro.schema.json", + "cxxNamespace": [ + "image" + ], "ios": { "iosModuleName": "NitroImage" }, "android": { - "androidNamespace": ["image"], + "androidNamespace": [ + "image" + ], "androidCxxLibName": "NitroImage" }, "autolinking": { @@ -28,5 +33,7 @@ "kotlin": "HybridChild" } }, - "ignorePaths": ["node_modules"] + "ignorePaths": [ + "node_modules" + ] } diff --git a/packages/template/nitro.json b/packages/template/nitro.json index 104c4e837..67184f6cd 100644 --- a/packages/template/nitro.json +++ b/packages/template/nitro.json @@ -1,12 +1,19 @@ { - "cxxNamespace": ["<>"], + "$schema": "https://nitro.margelo.com/nitro.schema.json", + "cxxNamespace": [ + "<>" + ], "ios": { "iosModuleName": "<>" }, "android": { - "androidNamespace": ["<>"], + "androidNamespace": [ + "<>" + ], "androidCxxLibName": "<>" }, "autolinking": {}, - "ignorePaths": ["node_modules"] + "ignorePaths": [ + "node_modules" + ] }