const cluster = require('cluster');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');

/**
 * get raw config object from js or 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);
    }
  } catch (err) {
    throw Error(`fail to load/parse your '${file}': ${err.message}`);
  }
  return json;
}

module.exports = function bootstrap(configPath, {Hub, Config}) {
  try {
    Config.init(obtainConfig(configPath));
    if (cluster.isMaster && __WORKERS__ > 0) {
      for (let i = 0; i < __WORKERS__; ++i) {
        cluster.fork();
      }
      console.log(`==> [bootstrap] started ${__WORKERS__} workers`);
    } else {
      const hub = new Hub();
      hub.on('close', () => process.exit(0));
      hub.run();
      process.on('SIGINT', () => hub.terminate());
    }
  } catch (err) {
    console.error(err);
    process.exit(-1);
  }
};

@@ -58,70 +58,8 @@
 s');
-%0Aconst path = require('path');%0Aconst chalk = require('chalk');
 %0A%0A/*
@@ -94,14 +94,8 @@
 rom 
-js or 
 json
@@ -189,435 +189,8 @@
 y %7B%0A
-    const ext = path.extname(file);%0A    // TODO: remove .js support in v2.6.x for security reason%0A    if (ext === '.js') %7B%0A      // require .js directly%0A      delete require.cache%5Brequire.resolve(file)%5D;%0A      json = require(file);%0A      console.warn(chalk.yellow.underline('%5Cn%3E%3E WARN: using .js configuration will be deprecated in v2.6.x, please use .json instead. %3C%3C%5Cn'));%0A    %7D else %7B%0A      // others are treated as .json%0A  
     
@@ -233,18 +233,16 @@
 e);%0A    
- 
- 
 json = J
@@ -262,22 +262,16 @@
 nFile);%0A
-    %7D%0A
   %7D catc

remove .js support