From 2cecbc3e46a89b19aa0643c149d74d7cf58465d6 Mon Sep 17 00:00:00 2001 From: Dragory Date: Wed, 8 Aug 2018 01:32:22 +0300 Subject: [PATCH] Add support for a .js config file --- CHANGELOG.md | 3 +++ src/config.js | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba0d33..41c689b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v2.16.0 +* Add support for a .js config file (export config with `module.exports`) + ## v2.15.2 * Update several other packages as well diff --git a/src/config.js b/src/config.js index 4d7cd86..54ad5c9 100644 --- a/src/config.js +++ b/src/config.js @@ -9,7 +9,8 @@ const configFiles = [ 'config.json', 'config.json5', 'config.json.json', - 'config.json.txt' + 'config.json.txt', + 'config.js' ]; let foundConfigFile; @@ -28,8 +29,12 @@ if (! foundConfigFile) { // Parse the config using JSON5 try { - const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile); - userConfig = json5.parse(raw); + if (foundConfigFile.endsWith('.js')) { + userConfig = require(`../${foundConfigFile}`); + } else { + const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile); + userConfig = json5.parse(raw); + } } catch (e) { throw new Error(`Error reading config file! The error given was: ${e.message}`); }