printConfig.js 947 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. if (!files || files.length !== 1 || isCodeNotFile) {
  20. return Promise.reject(
  21. new Error('The --print-config option must be used with exactly one file path.'),
  22. );
  23. }
  24. const filePath = files[0];
  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. };