-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration style updated JSON to JS
- Loading branch information
Showing
7 changed files
with
304 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
node_modules | ||
dist | ||
.vscode | ||
dummy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
{ | ||
|
||
"bracketSameLine": true, | ||
"semi": true, | ||
"proseWrap": "always", | ||
"printWidth": 75, | ||
"arrowParens": "always", | ||
"singleAttributePerLine": true, | ||
"trailingComma": "all", | ||
"embeddedLanguageFormatting": "auto", | ||
"experimentalTernaries": true, | ||
"parser": "typescript", | ||
"tabWidth": 2, | ||
"useTabs": true | ||
} | ||
"bracketSameLine": true, | ||
"semi": true, | ||
"proseWrap": "always", | ||
"printWidth": 75, | ||
"arrowParens": "always", | ||
"singleAttributePerLine": true, | ||
"trailingComma": "all", | ||
"embeddedLanguageFormatting": "auto", | ||
"experimentalTernaries": true, | ||
"parser": "typescript", | ||
"tabWidth": 2, | ||
"useTabs": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
import { existsSync, readFileSync } from "fs"; | ||
import { join } from "path"; | ||
import { configurationOptions } from "./lib/options"; | ||
import { existsSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
import { configurationOptions } from "./lib/types"; | ||
|
||
const CONFIG_FILE_NAME = ".richiejs"; | ||
export default function loadConfig(): configurationOptions { | ||
const CONFIG_FILE_NAME = "richie.config.js"; | ||
|
||
const projectConfigFile = join(process.cwd(), CONFIG_FILE_NAME); | ||
const projectHasConfig = existsSync(projectConfigFile); | ||
const projectConfigFile = join(process.cwd(), CONFIG_FILE_NAME); | ||
const projectHasConfig = existsSync(projectConfigFile); | ||
|
||
let projectConfig: configurationOptions = {} as configurationOptions; | ||
let defaultConfig: configurationOptions = {} as configurationOptions; | ||
let projectConfig: configurationOptions = {} as configurationOptions; | ||
let defaultConfig: configurationOptions = {} as configurationOptions; | ||
|
||
if (projectHasConfig) { | ||
//load project config | ||
try { | ||
projectConfig = JSON.parse( | ||
readFileSync(projectConfigFile, { encoding: "utf8" }), | ||
); | ||
} catch (err) { | ||
if (err instanceof SyntaxError) { | ||
console.log( | ||
"Error: Check configuration file if there any syntax mistake", | ||
); | ||
} else { | ||
console.log("Unexpected Error while loading settings"); | ||
if (projectHasConfig) { | ||
//load project config | ||
try { | ||
projectConfig = require(projectConfigFile).default; | ||
} catch (err) { | ||
console.log("Error while loading settings\n", err); | ||
process.exit(1); | ||
} | ||
process.exit(1); | ||
} | ||
} | ||
//load default configuration | ||
defaultConfig = JSON.parse( | ||
readFileSync(join(__dirname, CONFIG_FILE_NAME), { encoding: "utf8" }), | ||
); | ||
|
||
const configurations: configurationOptions = { | ||
...defaultConfig, | ||
...projectConfig, | ||
}; | ||
//load default configuration | ||
defaultConfig = require(join(__dirname, CONFIG_FILE_NAME)).default; | ||
|
||
const configurations: configurationOptions = { | ||
...defaultConfig, | ||
...projectConfig, | ||
}; | ||
|
||
export default configurations; | ||
return configurations; | ||
} |
Oops, something went wrong.