index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "build", {
  6. enumerable: true,
  7. get: ()=>build
  8. });
  9. const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
  10. const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
  11. const _resolveConfigPath = require("../../../util/resolveConfigPath");
  12. const _plugin = require("./plugin");
  13. function _interopRequireDefault(obj) {
  14. return obj && obj.__esModule ? obj : {
  15. default: obj
  16. };
  17. }
  18. async function build(args) {
  19. let input = args["--input"];
  20. let shouldWatch = args["--watch"];
  21. // TODO: Deprecate this in future versions
  22. if (!input && args["_"][1]) {
  23. console.error("[deprecation] Running tailwindcss without -i, please provide an input file.");
  24. input = args["--input"] = args["_"][1];
  25. }
  26. if (input && input !== "-" && !_fs.default.existsSync(input = _path.default.resolve(input))) {
  27. console.error(`Specified input file ${args["--input"]} does not exist.`);
  28. process.exit(9);
  29. }
  30. if (args["--config"] && !_fs.default.existsSync(args["--config"] = _path.default.resolve(args["--config"]))) {
  31. console.error(`Specified config file ${args["--config"]} does not exist.`);
  32. process.exit(9);
  33. }
  34. // TODO: Reference the @config path here if exists
  35. let configPath = args["--config"] ? args["--config"] : (0, _resolveConfigPath.resolveDefaultConfigPath)();
  36. let processor = await (0, _plugin.createProcessor)(args, configPath);
  37. if (shouldWatch) {
  38. // Abort the watcher if stdin is closed to avoid zombie processes
  39. // You can disable this behavior with --watch=always
  40. if (args["--watch"] !== "always") {
  41. process.stdin.on("end", ()=>process.exit(0));
  42. }
  43. process.stdin.resume();
  44. await processor.watch();
  45. } else {
  46. await processor.build().catch((e)=>{
  47. console.error(e);
  48. process.exit(1);
  49. });
  50. }
  51. }