@sleekcms/sync 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -126,7 +126,7 @@ async function main() {
126
126
  console.error("❌ Sync failed:", e.body || e.message);
127
127
  process.exit(1);
128
128
  }
129
- watcher.init({ viewsDir: VIEWS_DIR, onSync: runSync });
129
+ watcher.init({ viewsDir: VIEWS_DIR, onSync: runSync, onIdle: handleExit });
130
130
  watcher.monitorFiles();
131
131
  console.log(`\n✅ Ready! Editing session started for site - ${site.name}.`);
132
132
  console.log(`\n📁 Workspace created at: ${VIEWS_DIR}`);
package/dist/watcher.d.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  interface WatcherOptions {
10
10
  viewsDir: string;
11
11
  onSync: () => Promise<unknown>;
12
+ onIdle?: () => void;
12
13
  }
13
14
  export declare function init(options: WatcherOptions): void;
14
15
  export declare function setShuttingDown(value: boolean): void;
package/dist/watcher.js CHANGED
@@ -18,16 +18,33 @@ exports.stopWatching = stopWatching;
18
18
  const path_1 = __importDefault(require("path"));
19
19
  const chokidar_1 = __importDefault(require("chokidar"));
20
20
  const DEBOUNCE_DELAY = 5000;
21
+ const IDLE_TIMEOUT_MS = 30 * 60 * 1000;
21
22
  let watcher = null;
22
23
  let isShuttingDown = false;
23
24
  let debounceTimer = null;
25
+ let idleTimer = null;
24
26
  let dirty = false;
25
27
  let syncInFlight = false;
26
28
  let viewsDir = null;
27
29
  let onSync = null;
30
+ let onIdle = null;
28
31
  function init(options) {
29
32
  viewsDir = options.viewsDir;
30
33
  onSync = options.onSync;
34
+ onIdle = options.onIdle ?? null;
35
+ }
36
+ function resetIdleTimer() {
37
+ if (idleTimer)
38
+ clearTimeout(idleTimer);
39
+ if (isShuttingDown || !onIdle)
40
+ return;
41
+ idleTimer = setTimeout(() => {
42
+ idleTimer = null;
43
+ if (isShuttingDown)
44
+ return;
45
+ console.log(`\n💤 No changes for ${IDLE_TIMEOUT_MS / 60000} minutes. Terminating.`);
46
+ onIdle?.();
47
+ }, IDLE_TIMEOUT_MS);
31
48
  }
32
49
  function setShuttingDown(value) {
33
50
  isShuttingDown = value;
@@ -62,6 +79,7 @@ function scheduleSync() {
62
79
  if (debounceTimer)
63
80
  clearTimeout(debounceTimer);
64
81
  debounceTimer = setTimeout(flush, DEBOUNCE_DELAY);
82
+ resetIdleTimer();
65
83
  }
66
84
  function watchTargets(rootDir) {
67
85
  return [path_1.default.join(rootDir, "src")];
@@ -79,8 +97,13 @@ function monitorFiles() {
79
97
  .on("change", () => { scheduleSync(); })
80
98
  .on("add", () => { scheduleSync(); })
81
99
  .on("unlink", () => { scheduleSync(); });
100
+ resetIdleTimer();
82
101
  }
83
102
  async function stopWatching() {
103
+ if (idleTimer) {
104
+ clearTimeout(idleTimer);
105
+ idleTimer = null;
106
+ }
84
107
  if (watcher) {
85
108
  await watcher.close();
86
109
  watcher = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleekcms/sync",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Edit SleekCMS sites locally — models, content, templates, images — with live two-way sync and AI agent support.",
5
5
  "keywords": [
6
6
  "sleekcms",