-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ff1144
commit 0a1fc6e
Showing
5 changed files
with
49 additions
and
767 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
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,33 @@ | ||
import fs from "node:fs"; | ||
|
||
import yaml from "yaml"; | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
|
||
import { container } from "../../cli.mjs"; | ||
|
||
/** @type {yaml.Document.Parsed<Record<string, any>>} */ | ||
export function getConfig(path) { | ||
const fileBody = fs.readFileSync(path, { encoding: "utf8" }); | ||
return yaml.parseDocument(fileBody); | ||
} | ||
|
||
let parsedProfile; | ||
export function configParser(path) { | ||
const logger = container.resolve("logger"); | ||
|
||
if (parsedProfile) return parsedProfile; | ||
|
||
logger.debug(`Reading config from ${path}...`, "config"); | ||
const config = getConfig(path); | ||
const argv = yargs(hideBin(process.argv)).options({ | ||
profile: { | ||
default: "default", | ||
}, | ||
}).argv; | ||
logger.debug(`Using profile ${argv.profile}...`, "config"); | ||
parsedProfile = config.toJSON()[argv.profile]; | ||
logger.debug(`Applying config: ${JSON.stringify(parsedProfile, null, 4)}`); | ||
|
||
return parsedProfile; | ||
} |
Oops, something went wrong.