@sleekcms/sync 1.4.2 → 1.4.4

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/AGENT.md CHANGED
@@ -246,6 +246,8 @@ The `_block` value is the block's key (e.g., `"hero"`, `"cta"`) — never a nume
246
246
 
247
247
  Like blocks, stacks cannot be nested inside block models. Stack items themselves may contain groups, collections, and entry references, but not other stacks or blocks.
248
248
 
249
+ If the Blocks are only used in one page, simply structure the model as nested fields. Do not use Block or Stack fields in those cases.
250
+
249
251
  **Entry reference** — Use `entry(key)` for one, `[entry(key)]` for many:
250
252
  ```
251
253
  {
@@ -730,4 +732,4 @@ Template:
730
732
  17. Always create RSS feed for blogs and link them in meta so it is discoverable. Use "rss.xml" as the key.
731
733
  18. Make the sites extremely SEO friendly and sharing friendly.
732
734
  19. When naming files for models, use - (dash) as word separator. Don't use _ (underscore) as it is mapped to / (slash) in path
733
-
735
+ 20. Not all content details need to be modeled. If there is content which is not meant to be updated, such as button labels, links etc. you can inline that in the EJS view instead of adding fields to model and using from there. Decide what is relevant.
package/dist/cli.d.ts CHANGED
@@ -9,6 +9,7 @@ export interface CliOptions {
9
9
  }
10
10
  export interface KeyboardHandlers {
11
11
  onExit?: () => void | Promise<unknown>;
12
+ onQuit?: () => void | Promise<unknown>;
12
13
  onRefetch?: () => void | Promise<unknown>;
13
14
  }
14
15
  export declare function parseArgs(): CliOptions;
package/dist/cli.js CHANGED
@@ -67,7 +67,7 @@ function commandExists(cmd) {
67
67
  }
68
68
  }
69
69
  function showWatchHelp() {
70
- console.log("📋 Commands: [r] Re-fetch all files [x] Exit\n");
70
+ console.log("📋 Commands: [r] Re-fetch all files [x] Exit (cleanup) [q] Quit (keep files)\n");
71
71
  }
72
72
  function setupKeyboardInput(handlers) {
73
73
  if (process.stdin.isTTY) {
@@ -93,6 +93,9 @@ function setupKeyboardInput(handlers) {
93
93
  else if (cmd === "x" && handlers.onExit) {
94
94
  await handlers.onExit();
95
95
  }
96
+ else if (cmd === "q" && handlers.onQuit) {
97
+ await handlers.onQuit();
98
+ }
96
99
  });
97
100
  }
98
101
  const EDITOR_CANDIDATES = [
@@ -112,13 +115,14 @@ function showEditorMenu(viewsDir, handlers) {
112
115
  console.log("\n📂 Open in editor:");
113
116
  editors.forEach(e => console.log(` [${e.key}] ${e.name}`));
114
117
  console.log(" [Enter] Skip");
115
- console.log(" [x] Quit\n");
118
+ console.log(" [x] Exit (cleanup)");
119
+ console.log(" [q] Quit (keep files)\n");
116
120
  const rl = readline_1.default.createInterface({
117
121
  input: process.stdin,
118
122
  output: process.stdout,
119
123
  });
120
- // Count lines to clear (menu header + editors + skip + quit + empty + prompt)
121
- const linesToClear = editors.length + 5;
124
+ // Count lines to clear (menu header + editors + skip + exit + quit + empty + prompt)
125
+ const linesToClear = editors.length + 6;
122
126
  rl.question("Select editor: ", async (answer) => {
123
127
  rl.close();
124
128
  // Clear the menu lines
@@ -127,11 +131,17 @@ function showEditorMenu(viewsDir, handlers) {
127
131
  process.stdout.write("\x1b[2K\n"); // Clear each line
128
132
  }
129
133
  process.stdout.write(`\x1b[${linesToClear}A`); // Move back up
130
- if (answer.trim().toLowerCase() === "x") {
134
+ const choice = answer.trim().toLowerCase();
135
+ if (choice === "x") {
131
136
  if (handlers.onExit)
132
137
  await handlers.onExit();
133
138
  return;
134
139
  }
140
+ if (choice === "q") {
141
+ if (handlers.onQuit)
142
+ await handlers.onQuit();
143
+ return;
144
+ }
135
145
  const selected = editors.find(e => e.key === answer.trim());
136
146
  if (selected) {
137
147
  console.log(`👀 Watching for changes... (opened ${selected.name})`);
package/dist/index.js CHANGED
@@ -116,6 +116,17 @@ async function handleExit() {
116
116
  await cleanupFiles(VIEWS_DIR);
117
117
  process.exit(0);
118
118
  }
119
+ async function handleQuit() {
120
+ if (isShuttingDown)
121
+ return;
122
+ isShuttingDown = true;
123
+ watcher.setShuttingDown(true);
124
+ console.log("\n⚠️ Quitting (keeping files)...");
125
+ await watcher.stopWatching();
126
+ if (VIEWS_DIR)
127
+ console.log(`📁 Workspace left at: ${VIEWS_DIR}`);
128
+ process.exit(0);
129
+ }
119
130
  async function main() {
120
131
  await initConfig();
121
132
  try {
@@ -135,6 +146,7 @@ async function main() {
135
146
  console.log(`\n⚠️ Files will be cleaned up on exit (Ctrl+C).`);
136
147
  cli.showEditorMenu(VIEWS_DIR, {
137
148
  onExit: handleExit,
149
+ onQuit: handleQuit,
138
150
  onRefetch: () => runSync({ flush: true }),
139
151
  });
140
152
  process.on("SIGINT", async () => {
@@ -172,11 +172,18 @@ async function pushLocalChanges(viewsDir, fileMap, apiBase, token) {
172
172
  console.error("❌ Error saving files:", e.body || e.message);
173
173
  return 0;
174
174
  }
175
- const errors = await loadErrors(viewsDir);
175
+ const errors = await getSessionErrors(viewsDir);
176
176
  let pushed = 0;
177
+ const resultsByPath = indexSaveResultsByPath(results);
177
178
  for (let i = 0; i < changes.length; i++) {
178
179
  const c = changes[i];
179
- const r = results[i] || {};
180
+ const r = getSaveResult(c, i, results, resultsByPath);
181
+ if (!r) {
182
+ const msg = "No save response returned";
183
+ errors[c.rel] = msg;
184
+ console.error(`❌ Error saving ${c.rel}: ${msg}`);
185
+ continue;
186
+ }
180
187
  if (r.error) {
181
188
  errors[c.rel] = r.error;
182
189
  console.error(`❌ Error saving ${c.rel}: ${r.error}`);
@@ -194,10 +201,37 @@ async function pushLocalChanges(viewsDir, fileMap, apiBase, token) {
194
201
  console.log(`✅ ${c.prior ? "Updated" : "Created"} ${c.rel}`);
195
202
  pushed++;
196
203
  }
197
- await saveErrors(viewsDir, errors);
204
+ await dumpErrors(viewsDir, errors);
198
205
  return pushed;
199
206
  }
207
+ function indexSaveResultsByPath(results) {
208
+ const byPath = new Map();
209
+ for (const result of results) {
210
+ if (result.path)
211
+ byPath.set(result.path, result);
212
+ }
213
+ return byPath;
214
+ }
215
+ function getSaveResult(change, index, results, resultsByPath) {
216
+ const resultByPath = resultsByPath.get(change.rel);
217
+ if (resultByPath)
218
+ return resultByPath;
219
+ const resultByIndex = results[index];
220
+ if (!resultByIndex?.path || resultByIndex.path === change.rel)
221
+ return resultByIndex;
222
+ return undefined;
223
+ }
200
224
  const ERROR_LOG = "sync-errors.log";
225
+ const syncErrorsByWorkspace = new Map();
226
+ async function getSessionErrors(viewsDir) {
227
+ const workspace = path_1.default.resolve(viewsDir);
228
+ const cached = syncErrorsByWorkspace.get(workspace);
229
+ if (cached)
230
+ return cached;
231
+ const errors = await loadErrors(workspace);
232
+ syncErrorsByWorkspace.set(workspace, errors);
233
+ return errors;
234
+ }
201
235
  async function loadErrors(viewsDir) {
202
236
  const file = path_1.default.join(viewsDir, ERROR_LOG);
203
237
  if (!(await fs_extra_1.default.pathExists(file)))
@@ -211,7 +245,7 @@ async function loadErrors(viewsDir) {
211
245
  }
212
246
  return errors;
213
247
  }
214
- async function saveErrors(viewsDir, errors) {
248
+ async function dumpErrors(viewsDir, errors) {
215
249
  const file = path_1.default.join(viewsDir, ERROR_LOG);
216
250
  const entries = Object.entries(errors);
217
251
  if (entries.length === 0) {
@@ -221,6 +255,8 @@ async function saveErrors(viewsDir, errors) {
221
255
  await fs_extra_1.default.outputFile(file, entries.map(([p, msg]) => `${p}: ${msg}`).join("\n") + "\n");
222
256
  }
223
257
  async function pullServerState(viewsDir, apiBase, token) {
258
+ syncErrorsByWorkspace.delete(path_1.default.resolve(viewsDir));
259
+ await fs_extra_1.default.remove(path_1.default.join(viewsDir, ERROR_LOG));
224
260
  console.log("📥 Fetching files...");
225
261
  const files = await request(apiBase, token, "GET", "/get_files");
226
262
  const fileMap = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleekcms/sync",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
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",