Skip to content

Commit

Permalink
Merge pull request #8 from rawand-faraidun/dev
Browse files Browse the repository at this point in the history
config file schema
  • Loading branch information
rawand-faraidun authored Nov 26, 2023
2 parents 4f228c3 + 1da1020 commit f8a31bb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-lies-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'linguify': patch
---

Configuration file schema
28 changes: 28 additions & 0 deletions assets/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"localesPath": {
"type": "string",
"description": "Path to application locales folder",
"default": "./public/locales",
"$comment": "Path to application locales folder"
},
"locales": {
"type": "array",
"items": {
"type": "string"
},
"description": "Supported locales by your applications",
"default": ["en"],
"$comment": "Supported locales by your applications"
},
"defaultLocale": {
"type": "string",
"description": "default locale to your application",
"default": "en",
"$comment": "default locale to your application"
}
},
"required": ["localesPath", "locales", "defaultLocale"]
}
8 changes: 7 additions & 1 deletion lib/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import type { Config } from './types'
*/
export const configFileName = 'linguify.config.json'

/**
* config schema path
*/
export const configSchemaPath = 'https://github.com/rawand-faraidun/linguify/blob/main/assets/schema.json'

/**
* linguify default values
*/
export const defaultConfig: Config = {
export const defaultConfig = {
$schema: configSchemaPath,
localesPath: './public/locales',
locales: ['en'],
defaultLocale: 'en'
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { resolve } from 'path'
import findup from 'findup-sync'
import { configFileName, defaultConfig } from './defaults'
import { getUserConfig } from './functions'
import type { Config } from './types'

/**
* `node_modules` path, used to detect root
Expand Down Expand Up @@ -42,7 +43,7 @@ export const configPath = configPathExpected || configPathRoot
/**
* configuration
*/
export const config = { ...defaultConfig, ...getUserConfig() }
export const config: Config = { ...defaultConfig, ...getUserConfig() }

/**
* other languages from config
Expand Down

0 comments on commit f8a31bb

Please sign in to comment.