combine-config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. /**
  3. * Dependencies
  4. */
  5. const parseConfig = require('./parse-config');
  6. /**
  7. * Combine CLI script arguments with config options
  8. */
  9. module.exports = function combineConfig(config, argv) {
  10. //Extract options from config
  11. let {
  12. from, to, files, ignore, encoding, verbose,
  13. allowEmptyPaths, disableGlobs, isRegex, dry, quiet,
  14. } = config;
  15. //Get from/to parameters from CLI args if not defined in options
  16. if (typeof from === 'undefined') {
  17. from = argv._.shift();
  18. }
  19. if (typeof to === 'undefined') {
  20. to = argv._.shift();
  21. }
  22. //Get files and ignored files
  23. if (typeof files === 'undefined') {
  24. files = argv._;
  25. }
  26. if (typeof ignore === 'undefined' && typeof argv.ignore !== 'undefined') {
  27. ignore = argv.ignore;
  28. }
  29. //Other parameters
  30. if (typeof encoding === 'undefined') {
  31. encoding = argv.encoding;
  32. }
  33. if (typeof disableGlobs === 'undefined') {
  34. disableGlobs = !!argv.disableGlobs;
  35. }
  36. if (typeof isRegex === 'undefined') {
  37. isRegex = !!argv.isRegex;
  38. }
  39. if (typeof verbose === 'undefined') {
  40. verbose = !!argv.verbose;
  41. }
  42. if (typeof dry === 'undefined') {
  43. dry = !!argv.dry;
  44. }
  45. if (typeof quiet === 'undefined') {
  46. quiet = !!argv.quiet;
  47. }
  48. //Return through parser to validate
  49. return parseConfig({
  50. from, to, files, ignore, encoding, verbose,
  51. allowEmptyPaths, disableGlobs, isRegex, dry, quiet,
  52. });
  53. };