@blocofy/cli 0.1.10 → 0.1.11

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/bin/blocofy.mjs CHANGED
@@ -12,7 +12,7 @@ import { existsSync } from "node:fs";
12
12
  import { resolve } from "node:path";
13
13
  import { createInterface } from "node:readline/promises";
14
14
 
15
- import { pushContent } from "../lib/content-sync.mjs";
15
+ import { pullContent, pushContent } from "../lib/content-sync.mjs";
16
16
  import { credentialsPath, loadCredentials, saveCredentials } from "../lib/credentials.mjs";
17
17
  import { startDevServer } from "../lib/dev-server.mjs";
18
18
  import { readLocalTemplates } from "../lib/local-theme.mjs";
@@ -21,7 +21,7 @@ import { fetchDevSession, pullTheme, pushTheme } from "../lib/theme-sync.mjs";
21
21
  import { hyperlink, openUrl } from "../lib/term.mjs";
22
22
  import { isValidToken, isValidUrl, normalizeUrl } from "../lib/validate.mjs";
23
23
 
24
- const VERSION = "0.1.10";
24
+ const VERSION = "0.1.11";
25
25
  const args = process.argv.slice(2);
26
26
 
27
27
  /** Parse `--key value` and `--flag` (boolean) arguments. */
@@ -67,12 +67,13 @@ Usage
67
67
  Write the local theme to the site (create/update; no delete).
68
68
  --draft write to a draft theme — preview & publish it from the admin panel
69
69
 
70
- blocofy pages push [dir]
71
- Push local pages/*.json to the site. Updates EXISTING pages only —
72
- never creates or deletes a page. Unchanged pages are skipped.
70
+ blocofy pages pull [dir] / pages push [dir]
71
+ pull: download published pages → pages/<slug>.json.
72
+ push: write pages/*.json to the site. Updates EXISTING pages only —
73
+ never creates or deletes a page; unchanged pages are skipped.
73
74
 
74
- blocofy settings push [dir]
75
- Push local config/settings.json (theme tokens/settings + color schemes).
75
+ blocofy settings pull [dir] / settings push [dir]
76
+ Download / upload config/settings.json (theme tokens/settings + color schemes).
76
77
 
77
78
  blocofy --version
78
79
  blocofy --help
@@ -210,6 +211,14 @@ async function contentPush(scope, rest) {
210
211
  }
211
212
  }
212
213
 
214
+ async function contentPull(scope, rest) {
215
+ const positional = rest.filter((a) => !a.startsWith("--"));
216
+ const dir = resolve(positional[0] ?? process.cwd());
217
+ const creds = requireCreds();
218
+ const { count } = await pullContent({ dir, url: creds.url, token: creds.token, scope });
219
+ console.log(`Downloaded ${count} ${scope === "settings" ? "settings" : "page"} file(s) → ${dir}`);
220
+ }
221
+
213
222
  async function themeDev(rest) {
214
223
  const flags = parseFlags(rest);
215
224
  const positional = rest.filter((a) => !a.startsWith("--"));
@@ -374,11 +383,21 @@ if (first === "--version" || first === "-v") {
374
383
  console.error(error?.message ?? error);
375
384
  process.exit(1);
376
385
  });
386
+ } else if (first === "pages" && rest[0] === "pull") {
387
+ contentPull("pages", rest.slice(1)).catch((error) => {
388
+ console.error(error?.message ?? error);
389
+ process.exit(1);
390
+ });
377
391
  } else if (first === "pages" && rest[0] === "push") {
378
392
  contentPush("pages", rest.slice(1)).catch((error) => {
379
393
  console.error(error?.message ?? error);
380
394
  process.exit(1);
381
395
  });
396
+ } else if (first === "settings" && rest[0] === "pull") {
397
+ contentPull("settings", rest.slice(1)).catch((error) => {
398
+ console.error(error?.message ?? error);
399
+ process.exit(1);
400
+ });
382
401
  } else if (first === "settings" && rest[0] === "push") {
383
402
  contentPush("settings", rest.slice(1)).catch((error) => {
384
403
  console.error(error?.message ?? error);
@@ -1,11 +1,12 @@
1
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
2
- import { join, relative, sep } from "node:path";
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, relative, sep } from "node:path";
3
3
 
4
4
  /**
5
- * `blocofy pages push` / `settings push` (#119). CLI'nın yerel içerik dosyalarını
6
- * (`pages/<slug>.json` + `config/settings.json`) platformun `/api/dev/content`
7
- * endpoint'ine gönderir. Tema KODU `theme push`'a gider; bu yalnız içerik+ayar.
8
- * Güvenlik platformda: yalnız mevcut sayfayı günceller, yeni oluşturmaz, silmez.
5
+ * `blocofy pages pull/push` + `settings pull/push` (#119). CLI'nın yerel içerik
6
+ * dosyalarını (`pages/<slug>.json` + `config/settings.json`) platformun
7
+ * `/api/dev/content` endpoint'iyle çeker/gönderir. Tema KODU `theme pull/push`'a
8
+ * gider; bu yalnız içerik+ayar. Güvenlik platformda: push yalnız mevcut sayfayı
9
+ * günceller, yeni oluşturmaz, silmez.
9
10
  */
10
11
 
11
12
  async function errorText(res) {
@@ -56,3 +57,21 @@ export async function pushContent({ dir, url, token, scope }) {
56
57
  if (!res.ok) throw new Error(await errorText(res));
57
58
  return { ...(await res.json()), fileCount: Object.keys(files).length };
58
59
  }
60
+
61
+ /** Site içeriğini diske çek (pull). scope "pages" | "settings" | "all". Yazılan dosya sayısı. */
62
+ export async function pullContent({ dir, url, token, scope }) {
63
+ const base = url.replace(/\/+$/, "");
64
+ const res = await fetch(`${base}/api/dev/content?scope=${encodeURIComponent(scope)}`, {
65
+ headers: { authorization: `Bearer ${token}` },
66
+ });
67
+ if (!res.ok) throw new Error(await errorText(res));
68
+ const { files } = await res.json();
69
+ let count = 0;
70
+ for (const [path, content] of Object.entries(files ?? {})) {
71
+ const full = join(dir, ...path.split("/"));
72
+ mkdirSync(dirname(full), { recursive: true });
73
+ writeFileSync(full, typeof content === "string" ? content : "");
74
+ count += 1;
75
+ }
76
+ return { count };
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocofy/cli",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Develop your Blocofy theme locally against live data with instant preview — login, theme dev, pull, push.",
5
5
  "type": "module",
6
6
  "license": "MIT",