Skip to content

Commit

Permalink
feat: Add a nitro.schema.json schema to validate nitro.json files (
Browse files Browse the repository at this point in the history
…#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 <[email protected]>
  • Loading branch information
patrickkabwe and mrousavy authored Dec 4, 2024
1 parent 4ffa3ae commit f7802e2
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 7 deletions.
99 changes: 99 additions & 0 deletions docs/static/nitro.schema.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
2 changes: 1 addition & 1 deletion packages/nitrogen/src/config/NitroUserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*/
Expand Down
13 changes: 10 additions & 3 deletions packages/react-native-nitro-image/nitro.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -28,5 +33,7 @@
"kotlin": "HybridChild"
}
},
"ignorePaths": ["node_modules"]
"ignorePaths": [
"node_modules"
]
}
13 changes: 10 additions & 3 deletions packages/template/nitro.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"cxxNamespace": ["<<cxxNamespace>>"],
"$schema": "https://nitro.margelo.com/nitro.schema.json",
"cxxNamespace": [
"<<cxxNamespace>>"
],
"ios": {
"iosModuleName": "<<iosModuleName>>"
},
"android": {
"androidNamespace": ["<<androidNamespace>>"],
"androidNamespace": [
"<<androidNamespace>>"
],
"androidCxxLibName": "<<androidCxxLibName>>"
},
"autolinking": {},
"ignorePaths": ["node_modules"]
"ignorePaths": [
"node_modules"
]
}

0 comments on commit f7802e2

Please sign in to comment.