@blocofy/cli 0.1.1 → 0.1.2

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
@@ -16,7 +16,7 @@ import { credentialsPath, loadCredentials, saveCredentials } from "../lib/creden
16
16
  import { startDevServer } from "../lib/dev-server.mjs";
17
17
  import { pullTheme, pushTheme } from "../lib/theme-sync.mjs";
18
18
 
19
- const VERSION = "0.1.1";
19
+ const VERSION = "0.1.2";
20
20
  const args = process.argv.slice(2);
21
21
 
22
22
  /** Parse `--key value` and `--flag` (boolean) arguments. */
@@ -49,6 +49,7 @@ Usage:
49
49
  --port <n> (default 3030)
50
50
  blocofy theme pull [dir] Download the live theme to disk. dir defaults to cwd.
51
51
  blocofy theme push [dir] Write the local theme to the live site (create/update; no delete).
52
+ --draft write to a draft theme instead (preview & publish from the admin panel)
52
53
  blocofy --version
53
54
  blocofy --help
54
55
 
@@ -105,6 +106,7 @@ async function themePull(rest) {
105
106
  }
106
107
 
107
108
  async function themePush(rest) {
109
+ const flags = parseFlags(rest);
108
110
  const positional = rest.filter((a) => !a.startsWith("--"));
109
111
  const dir = resolve(positional[0] ?? process.cwd());
110
112
  if (!existsSync(dir)) {
@@ -112,11 +114,17 @@ async function themePush(rest) {
112
114
  process.exit(1);
113
115
  }
114
116
  const creds = requireCreds();
115
- const result = await pushTheme({ dir, url: creds.url, token: creds.token });
116
- const extra = result.skippedDeletes
117
- ? `, ${result.skippedDeletes} remote file(s) absent locally (not deleted)`
118
- : "";
119
- console.log(`Push: ${result.created} created, ${result.updated} updated${extra}.`);
117
+ const draft = Boolean(flags.draft);
118
+ const result = await pushTheme({ dir, url: creds.url, token: creds.token, draft });
119
+ if (result.draft) {
120
+ console.log(`Pushed to draft theme #${result.instanceId} (${result.created} created, ${result.updated} updated).`);
121
+ console.log(`Preview & publish it in the admin panel: Theme → Theme library → "Open in editor".`);
122
+ } else {
123
+ const extra = result.skippedDeletes
124
+ ? `, ${result.skippedDeletes} remote file(s) absent locally (not deleted)`
125
+ : "";
126
+ console.log(`Push: ${result.created} created, ${result.updated} updated${extra}.`);
127
+ }
120
128
  }
121
129
 
122
130
  function themeDev(rest) {
@@ -34,14 +34,18 @@ export async function pullTheme({ dir, url, token }) {
34
34
  return { count };
35
35
  }
36
36
 
37
- /** Write the local theme to the live site (create/update; no delete). */
38
- export async function pushTheme({ dir, url, token }) {
37
+ /**
38
+ * Write the local theme to the site (create/update; no delete). With `draft`,
39
+ * writes to a draft theme instance instead of the live theme — preview & publish
40
+ * it from the admin panel without affecting the live site.
41
+ */
42
+ export async function pushTheme({ dir, url, token, draft = false }) {
39
43
  const base = url.replace(/\/+$/, "");
40
44
  const files = readLocalTemplates(dir);
41
45
  const res = await fetch(`${base}/api/dev/theme`, {
42
46
  method: "POST",
43
47
  headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
44
- body: JSON.stringify({ files }),
48
+ body: JSON.stringify({ files, draft }),
45
49
  });
46
50
  if (!res.ok) throw new Error(await errorText(res));
47
51
  return res.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocofy/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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",