Skip to content

Commit

Permalink
Configuration style updated JSON to JS
Browse files Browse the repository at this point in the history
  • Loading branch information
darsan-in committed Nov 19, 2024
1 parent 17f8385 commit 0252c2d
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 267 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
node_modules
dist
.vscode
dummy
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
27 changes: 13 additions & 14 deletions .prettierrc
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
}
219 changes: 0 additions & 219 deletions .richiejs

This file was deleted.

57 changes: 25 additions & 32 deletions configLoader.ts
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;
}
Loading

0 comments on commit 0252c2d

Please sign in to comment.