index.js 2.0 KB

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