var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var fsWatching_exports = {};
__export(fsWatching_exports, {
  startWatchers: () => startWatchers,
  stopWatchers: () => stopWatchers
});
module.exports = __toCommonJS(fsWatching_exports);
var import_ends_with = __toESM(require("@babel/runtime-corejs3/core-js/instance/ends-with"));
var import_starts_with = __toESM(require("@babel/runtime-corejs3/core-js/instance/starts-with"));
var import_node_path = __toESM(require("node:path"));
var import_chokidar = __toESM(require("chokidar"));
var import_realtime = require("@cedarjs/realtime");
var import_mailRenderers = require("../services/mailRenderers/mailRenderers");
var import_mailTemplates = require("../services/mailTemplates/mailTemplates");
var import_project = require("./project");
let watcher;
async function startWatchers() {
  const userPaths = (0, import_project.getUserProjectPaths)();
  watcher = import_chokidar.default.watch(`**/*.*`, {
    cwd: userPaths.api.dist,
    ignoreInitial: true,
    usePolling: true,
    interval: 500
  });
  const listenOnEventsForDist = ["ready", "add", "change"];
  for (let i = 0; i < listenOnEventsForDist.length; i++) {
    watcher.on(listenOnEventsForDist[i], async (pathThatChanged) => {
      if (pathThatChanged === void 0) {
        return;
      }
      if ((0, import_ends_with.default)(pathThatChanged).call(pathThatChanged, ".js.map")) {
        return;
      }
      if (pathThatChanged === import_node_path.default.join("lib", "mailer.js")) {
        await (0, import_mailRenderers.resyncMailRenderers)();
        return;
      }
      if ((0, import_starts_with.default)(pathThatChanged).call(pathThatChanged, "mail" + import_node_path.default.sep)) {
        await (0, import_mailTemplates.resyncMailTemplate)({
          rawTemplateDistPath: import_node_path.default.join(userPaths.api.dist, pathThatChanged)
        });
        await import_realtime.liveQueryStore?.invalidate("Query.mailSMTPCount");
        return;
      }
    });
  }
}
async function stopWatchers() {
  if (watcher !== void 0) {
    await watcher.close();
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  startWatchers,
  stopWatchers
});
//# sourceMappingURL=fsWatching.js.map
