bin: remove .js support

This commit is contained in:
Micooz 2017-09-05 14:33:42 +08:00
parent 94be72599b
commit 947a260285
No known key found for this signature in database
GPG Key ID: 002FB5DD584D6CB1

18
bin/bootstrap.js vendored

@ -1,28 +1,16 @@
const cluster = require('cluster');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
/**
* get raw config object from js or json
* get raw config object from json
* @param file
* @returns {object}
*/
function obtainConfig(file) {
let json;
try {
const ext = path.extname(file);
// TODO: remove .js support in v2.6.x for security reason
if (ext === '.js') {
// require .js directly
delete require.cache[require.resolve(file)];
json = require(file);
console.warn(chalk.yellow.underline('\n>> WARN: using .js configuration will be deprecated in v2.6.x, please use .json instead. <<\n'));
} else {
// others are treated as .json
const jsonFile = fs.readFileSync(file);
json = JSON.parse(jsonFile);
}
const jsonFile = fs.readFileSync(file);
json = JSON.parse(jsonFile);
} catch (err) {
throw Error(`fail to load/parse your '${file}': ${err.message}`);
}