prepareOptions.js 618 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. module.exports = function prepareOptions(options, argv) {
  3. argv = argv || {};
  4. options = handleExport(options);
  5. return Array.isArray(options)
  6. ? options.map(_options => handleFunction(_options, argv))
  7. : handleFunction(options, argv);
  8. };
  9. function handleExport(options) {
  10. const isES6DefaultExported =
  11. typeof options === "object" &&
  12. options !== null &&
  13. typeof options.default !== "undefined";
  14. return isES6DefaultExported ? options.default : options;
  15. }
  16. function handleFunction(options, argv) {
  17. if (typeof options === "function") {
  18. options = options(argv.env, argv);
  19. }
  20. return options;
  21. }