Skip to content

Commit 8014781

Browse files
BoltsJFyorl
andauthored
Add --config command line flag (#50)
Co-authored-by: fyorl <kim.mantas@gmail.com>
1 parent 2dcaacc commit 8014781

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,18 @@ export default class Config {
104104
#writeConfig() {
105105
fs.writeFileSync(this.configPath, yaml.dump(this.#config));
106106
}
107+
108+
/* -------------------------------------------- */
109+
110+
/**
111+
* Load a local configuration file
112+
* @param {string} configFile The path to the config file
113+
*/
114+
loadLocalConf(configFile) {
115+
if ( !fs.existsSync(configFile) ) return;
116+
/** @type {Record<string, any>} */
117+
const conf = yaml.load(fs.readFileSync(configFile, "utf8"));
118+
this.configPath = configFile;
119+
for ( const key of Object.keys(conf) ) this.#config[key] = conf[key];
120+
}
107121
}

fvtt.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import { hideBin } from "yargs/helpers";
55
import { getCommand as configureCommand } from "./commands/configuration.mjs";
66
import { getCommand as packageCommand } from "./commands/package.mjs";
77
import { getCommand as launchCommand } from "./commands/launch.mjs";
8+
import Config from "./config.mjs";
89

910
const argv = yargs(hideBin(process.argv))
1011
.usage("Usage: $0 <command> [options]")
12+
.config("config", "Path to YAML config file", function(configFile) {
13+
Config.instance.loadLocalConf(configFile);
14+
return Config.instance.getAll();
15+
})
1116
.command(configureCommand())
1217
.command(packageCommand())
1318
.command(launchCommand())

0 commit comments

Comments
 (0)