@sleekcms/sync 1.0.0

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.
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * File watching + debounced sync trigger.
4
+ *
5
+ * All push/pull logic lives in setup-site.ts. This module only:
6
+ * - watches the workspace with chokidar
7
+ * - debounces change events
8
+ * - calls back into a provided `onSync` handler that invokes syncSite()
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.init = init;
15
+ exports.setShuttingDown = setShuttingDown;
16
+ exports.monitorFiles = monitorFiles;
17
+ exports.stopWatching = stopWatching;
18
+ const path_1 = __importDefault(require("path"));
19
+ const chokidar_1 = __importDefault(require("chokidar"));
20
+ const DEBOUNCE_DELAY = 5000;
21
+ let watcher = null;
22
+ let isShuttingDown = false;
23
+ let debounceTimer = null;
24
+ let dirty = false;
25
+ let syncInFlight = false;
26
+ let viewsDir = null;
27
+ let onSync = null;
28
+ function init(options) {
29
+ viewsDir = options.viewsDir;
30
+ onSync = options.onSync;
31
+ }
32
+ function setShuttingDown(value) {
33
+ isShuttingDown = value;
34
+ }
35
+ async function flush() {
36
+ debounceTimer = null;
37
+ if (!dirty || isShuttingDown)
38
+ return;
39
+ if (syncInFlight) {
40
+ // Re-arm to retry after the current sync finishes.
41
+ debounceTimer = setTimeout(flush, DEBOUNCE_DELAY);
42
+ return;
43
+ }
44
+ dirty = false;
45
+ syncInFlight = true;
46
+ try {
47
+ if (onSync)
48
+ await onSync();
49
+ }
50
+ catch (err) {
51
+ const e = err;
52
+ console.error("❌ Sync failed:", e.body || e.message);
53
+ }
54
+ finally {
55
+ syncInFlight = false;
56
+ }
57
+ }
58
+ function scheduleSync() {
59
+ if (isShuttingDown)
60
+ return;
61
+ dirty = true;
62
+ if (debounceTimer)
63
+ clearTimeout(debounceTimer);
64
+ debounceTimer = setTimeout(flush, DEBOUNCE_DELAY);
65
+ }
66
+ function watchTargets(rootDir) {
67
+ return [path_1.default.join(rootDir, "src")];
68
+ }
69
+ function monitorFiles() {
70
+ if (!viewsDir)
71
+ throw new Error("watcher.init must be called before monitorFiles");
72
+ const watchedFolder = path_1.default.join(viewsDir, "src");
73
+ console.log(`👀 Watching folder: ${watchedFolder}`);
74
+ watcher = chokidar_1.default.watch(watchTargets(viewsDir), {
75
+ persistent: true,
76
+ ignoreInitial: true,
77
+ })
78
+ .on("change", () => { scheduleSync(); })
79
+ .on("add", () => { scheduleSync(); })
80
+ .on("unlink", () => { scheduleSync(); });
81
+ }
82
+ async function stopWatching() {
83
+ if (watcher) {
84
+ await watcher.close();
85
+ watcher = null;
86
+ }
87
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@sleekcms/sync",
3
+ "version": "1.0.0",
4
+ "description": "Edit SleekCMS sites locally — models, content, templates, images — with live two-way sync and AI agent support.",
5
+ "keywords": [
6
+ "sleekcms",
7
+ "cms",
8
+ "sync",
9
+ "cli",
10
+ "ejs",
11
+ "headless-cms",
12
+ "ai-agent"
13
+ ],
14
+ "homepage": "https://sleekcms.com",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/sleekcms/cms-sync.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/sleekcms/cms-sync/issues"
21
+ },
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "bin": {
25
+ "sleekcms": "dist/index.js"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc && cp src/AGENT.md dist/ && chmod +x dist/index.js dist/setup-site.js dist/sync-site.js",
32
+ "dev": "tsx src/index.ts",
33
+ "typecheck": "tsc --noEmit",
34
+ "clean": "rm -rf dist",
35
+ "test": "node --import tsx --test __tests__/*.test.ts",
36
+ "prepublishOnly": "npm run clean && npm run build",
37
+ "publish:npm": "npm publish --access public"
38
+ },
39
+ "author": "Yusuf Bhabhrawala",
40
+ "license": "ISC",
41
+ "dependencies": {
42
+ "chokidar": "^4.0.3",
43
+ "commander": "^13.1.0",
44
+ "fs-extra": "^11.3.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/fs-extra": "^11.0.4",
48
+ "@types/node": "^22.10.0",
49
+ "tsx": "^4.19.2",
50
+ "typescript": "^5.7.2"
51
+ }
52
+ }