index.js 2.0 KB

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