env-flags.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. var path = require('path');
  3. var copyProps = require('copy-props');
  4. var toFrom = {
  5. configPath: 'flags.gulpfile',
  6. configBase: 'flags.gulpfile',
  7. require: 'flags.require',
  8. nodeFlags: 'flags.nodeFlags',
  9. };
  10. function mergeConfigToEnvFlags(env, config, cliOpts) {
  11. // This must reverse because `flags.gulpfile` determines 2 different properties
  12. var reverse = true;
  13. return copyProps(env, config, toFrom, convert, reverse);
  14. function convert(configInfo, envInfo) {
  15. if (envInfo.keyChain === 'configBase') {
  16. if (cliOpts.gulpfile === undefined) {
  17. return path.dirname(configInfo.value);
  18. }
  19. return;
  20. }
  21. if (envInfo.keyChain === 'configPath') {
  22. if (cliOpts.gulpfile === undefined) {
  23. return configInfo.value;
  24. }
  25. return;
  26. }
  27. if (envInfo.keyChain === 'require') {
  28. return [].concat(envInfo.value, configInfo.value);
  29. }
  30. /* istanbul ignore else */
  31. if (envInfo.keyChain === 'nodeFlags') {
  32. return [].concat(configInfo.value || []);
  33. }
  34. }
  35. }
  36. module.exports = mergeConfigToEnvFlags;