printConfig.js 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const resolveConfig = require('./resolveConfig');
  3. const globby = require('globby');
  4. /** @typedef {import('stylelint').Config} StylelintConfig */
  5. /**
  6. * @param {import('stylelint').LinterOptions} options
  7. * @returns {Promise<StylelintConfig | null>}
  8. */
  9. module.exports = async function printConfig({
  10. cwd = process.cwd(),
  11. code,
  12. config,
  13. configBasedir,
  14. configFile,
  15. globbyOptions,
  16. files,
  17. }) {
  18. const isCodeNotFile = code !== undefined;
  19. const filePath = files && files[0];
  20. if (!files || files.length !== 1 || !filePath || isCodeNotFile) {
  21. return Promise.reject(
  22. new Error('The --print-config option must be used with exactly one file path.'),
  23. );
  24. }
  25. if (globby.hasMagic(filePath)) {
  26. return Promise.reject(new Error('The --print-config option does not support globs.'));
  27. }
  28. return (
  29. (await resolveConfig(filePath, {
  30. cwd: (globbyOptions && globbyOptions.cwd) || cwd,
  31. config,
  32. configBasedir,
  33. configFile,
  34. })) || null
  35. );
  36. };