diff --git a/lib/config.js b/lib/config.js index 94db0a5..6a6b842 100644 --- a/lib/config.js +++ b/lib/config.js @@ -11,43 +11,46 @@ const path = require("path"); const _ = require("lodash"); -const configDir = process.env.NODE_CONFIG_DIR || path.join(require.main.filename, "..", "/config"); -const currentDir = path.join(__dirname, "config"); -process.env.NODE_CONFIG_DIR = currentDir; - -let dirs; -try { - dirs = fs.readdirSync(configDir); -} catch(e) { - // ... -} -dirs = dirs || []; - const template = fs.readFileSync(`${__dirname}/config/_template`, { encoding: "utf8" }); +const currentDir = path.join(__dirname, "config"); function copy(_path, type) { const js = _.template(template)({ path: _path, type: type }); fs.writeFileSync(`${__dirname}/config/${type}.js`, js, { encoding: "utf8" }); } -for(let i = 0; i < dirs.length; i++) { - let stat; +if(process.env.AKYUU_NO_GENERATE_CONFIG !== "true") { + const configDir = process.env.NODE_CONFIG_DIR || path.join(require.main.filename, "..", "/config"); + + let dirs; try { - stat = fs.statSync(path.join(configDir, dirs[i])); + dirs = fs.readdirSync(configDir); } catch(e) { - stat = null; + // ... } + dirs = dirs || []; + + for(let i = 0; i < dirs.length; i++) { + let stat; + try { + stat = fs.statSync(path.join(configDir, dirs[i])); + } catch(e) { + stat = null; + } - if(!stat) continue; - if(stat.isDirectory()) { - copy(configDir, dirs[i]); - } else if(stat.isFile()) { - if(dirs[i].endsWith(".js")) { - copy(configDir, dirs[i].substr(dirs[i].length - 3)); - } else if(dirs[i].endsWith(".json")) { - copy(configDir, dirs[i].substr(dirs[i].length - 5)); + if(!stat) continue; + if(stat.isDirectory()) { + copy(configDir, dirs[i]); + } else if(stat.isFile()) { + if(dirs[i].endsWith(".js")) { + copy(configDir, dirs[i].substr(dirs[i].length - 3)); + } else if(dirs[i].endsWith(".json")) { + copy(configDir, dirs[i].substr(dirs[i].length - 5)); + } } } } +process.env.NODE_CONFIG_DIR = currentDir; + module.exports = require("config");