get-core-config.js 726 B

12345678910111213141516171819202122232425262728
  1. /* eslint global-require: "off" */
  2. /* eslint no-console: ["error", { allow: ["log"] }] */
  3. const path = require('path');
  4. let config = require('./config.json');
  5. let logged = false;
  6. function getConfig() {
  7. const args = process.argv;
  8. let configArgIndex;
  9. let configPath;
  10. args.forEach((arg, argIndex) => {
  11. if (arg === '--config') configArgIndex = argIndex;
  12. });
  13. if (configArgIndex && args[configArgIndex + 1]) {
  14. configPath = path.resolve(args[configArgIndex + 1]);
  15. }
  16. if (configPath) {
  17. config = require(configPath); // eslint-disable-line
  18. if (!logged) {
  19. console.log(`Building using custom config from ${configPath}`);
  20. }
  21. logged = true;
  22. }
  23. return config;
  24. }
  25. module.exports = getConfig;