No Description

resolveConfigPath.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. function _export(target, all) {
  6. for(var name in all)Object.defineProperty(target, name, {
  7. enumerable: true,
  8. get: all[name]
  9. });
  10. }
  11. _export(exports, {
  12. default: function() {
  13. return resolveConfigPath;
  14. },
  15. resolveDefaultConfigPath: function() {
  16. return resolveDefaultConfigPath;
  17. }
  18. });
  19. const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
  20. const _path = /*#__PURE__*/ _interop_require_default(require("path"));
  21. function _interop_require_default(obj) {
  22. return obj && obj.__esModule ? obj : {
  23. default: obj
  24. };
  25. }
  26. const defaultConfigFiles = [
  27. "./tailwind.config.js",
  28. "./tailwind.config.cjs",
  29. "./tailwind.config.mjs",
  30. "./tailwind.config.ts"
  31. ];
  32. function isObject(value) {
  33. return typeof value === "object" && value !== null;
  34. }
  35. function isEmpty(obj) {
  36. return Object.keys(obj).length === 0;
  37. }
  38. function isString(value) {
  39. return typeof value === "string" || value instanceof String;
  40. }
  41. function resolveConfigPath(pathOrConfig) {
  42. // require('tailwindcss')({ theme: ..., variants: ... })
  43. if (isObject(pathOrConfig) && pathOrConfig.config === undefined && !isEmpty(pathOrConfig)) {
  44. return null;
  45. }
  46. // require('tailwindcss')({ config: 'custom-config.js' })
  47. if (isObject(pathOrConfig) && pathOrConfig.config !== undefined && isString(pathOrConfig.config)) {
  48. return _path.default.resolve(pathOrConfig.config);
  49. }
  50. // require('tailwindcss')({ config: { theme: ..., variants: ... } })
  51. if (isObject(pathOrConfig) && pathOrConfig.config !== undefined && isObject(pathOrConfig.config)) {
  52. return null;
  53. }
  54. // require('tailwindcss')('custom-config.js')
  55. if (isString(pathOrConfig)) {
  56. return _path.default.resolve(pathOrConfig);
  57. }
  58. // require('tailwindcss')
  59. return resolveDefaultConfigPath();
  60. }
  61. function resolveDefaultConfigPath() {
  62. for (const configFile of defaultConfigFiles){
  63. try {
  64. const configPath = _path.default.resolve(configFile);
  65. _fs.default.accessSync(configPath);
  66. return configPath;
  67. } catch (err) {}
  68. }
  69. return null;
  70. }