Skip to content

Commit

Permalink
feat: migrate to cosmiconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
robrechtme authored Sep 20, 2022
2 parents 3522954 + 1ef1b1f commit 0afc502
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 113 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"chalk": "^4.1.2",
"cli-progress": "^3.11.1",
"commander": "^9.3.0",
"cosmiconfig": "^7.0.1",
"deep-object-diff": "^1.1.7",
"inquirer": "^8.2.4",
"isomorphic-unfetch": "^3.1.0",
"rcfile": "^1.0.3"
"isomorphic-unfetch": "^3.1.0"
},
"devDependencies": {
"@types/cli-progress": "3.11.0",
Expand Down
14 changes: 4 additions & 10 deletions src/util/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { statSync } from "fs";
import rcfile from "rcfile";
import { Config } from "../../types";
import path from "path";
import { cosmiconfig } from "cosmiconfig";

const getConfigPath = () => path.resolve(process.cwd(), "loco.config.js");
const explorer = cosmiconfig("loco");

export const readConfig = async (): Promise<Config> => {
try {
statSync(getConfigPath());
return await import(getConfigPath());
} catch {
return rcfile("loco", { defaultExtension: ".json" });
}
const result = await explorer.search();
return result?.config ?? {};
};
Loading

0 comments on commit 0afc502

Please sign in to comment.