@mycatalog/cli 0.1.3 → 0.1.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/README.md CHANGED
@@ -34,11 +34,12 @@ npx @mycatalog/cli theme dev
34
34
 
35
35
  ```sh
36
36
  mycatalog login # shows a code; approve it in your browser
37
+ mycatalog whoami # your account and store ids
37
38
  mycatalog theme list # your themes and version ids
38
39
  mycatalog theme init my-theme # or cd into an existing theme folder
39
40
  cd my-theme # set themeId, versionId and storeId in mycatalog.json
40
41
  mycatalog theme check # same checks as the server
41
- mycatalog theme dev # upload, print a preview link, re-upload on save
42
+ mycatalog theme dev # upload, pick a store, print a preview link, re-upload on save
42
43
  ```
43
44
 
44
45
  Login uses the OAuth device flow. It displays a code and verification page, then asks before opening the browser. Use
@@ -67,7 +68,7 @@ The CLI tells you about a new version at most once a day; it never updates itsel
67
68
  - `mycatalog theme check` — run local folder, JSON, markup, CSS animation, and size checks.
68
69
  - `mycatalog --help`, `mycatalog theme --help`, `mycatalog --version` — show usage or version.
69
70
 
70
- Set `themeId`, `versionId`, and optionally `storeId` in the project's `mycatalog.json`. The file contains identifiers
71
+ Set `themeId`, `versionId`, and optionally `storeId` in the project's `mycatalog.json`. All three are IDs, never names or slugs: get `themeId`/`versionId` from `mycatalog theme list` and `storeId` from `mycatalog whoami` (a store slug like `my-store` returns "Not found"). The file contains identifiers
71
72
  only and cannot change the API host that receives credentials. Global `--json` enables machine-readable output;
72
73
  `--verbose` is reserved for safe diagnostics.
73
74
 
package/dist/bin.js CHANGED
@@ -5,7 +5,7 @@ import { Api } from "./core/api.js";
5
5
  import * as theme from "./commands/theme/index.js";
6
6
  import { print, redact } from "./core/output.js";
7
7
  import { checkForUpdate } from "./core/update.js";
8
- const VERSION = "0.1.3";
8
+ const VERSION = "0.1.4";
9
9
  const HELP = `mycatalog <command>
10
10
 
11
11
  Commands:
@@ -16,7 +16,14 @@ export declare function localeBundle(files: {
16
16
  export declare function list(): Promise<void>;
17
17
  /** Pull safe theme section files and preserve local edits unless --force is supplied. */
18
18
  export declare function pull(version?: string, force?: boolean): Promise<void>;
19
+ type StoreChoice = {
20
+ id: string;
21
+ name: string;
22
+ };
23
+ /** Resolve a menu answer (1-based number or exact store ID) to a store ID, or undefined if invalid. */
24
+ export declare function pickStore(stores: StoreChoice[], answer: string): string | undefined;
19
25
  /** Print a preview URL for the configured draft and an explicitly selected owned store. */
20
26
  export declare function preview(store?: string): Promise<void>;
21
27
  /** Push once and debounce subsequent file changes into draft uploads. */
22
28
  export declare function dev(store?: string): Promise<void>;
29
+ export {};
@@ -296,18 +296,51 @@ async function writePulledFile(root, path, contents, force) {
296
296
  mode: 0o644,
297
297
  });
298
298
  }
299
+ /** Resolve a menu answer (1-based number or exact store ID) to a store ID, or undefined if invalid. */
300
+ export function pickStore(stores, answer) {
301
+ const value = answer.trim();
302
+ const index = /^\d+$/.test(value) ? Number(value) - 1 : -1;
303
+ return stores[index]?.id ?? stores.find((s) => s.id === value)?.id;
304
+ }
305
+ /** Ask which owned store to preview on; one store is chosen automatically. */
306
+ async function selectStore(api) {
307
+ const me = await api.request("/api/cli/me");
308
+ const stores = Array.isArray(me.stores) ? me.stores.filter((s) => typeof s?.id === "string") : [];
309
+ if (stores.length === 0)
310
+ throw new Error("You don't own any stores. Create one in the dashboard, then try again.");
311
+ if (stores.length === 1) {
312
+ console.log(`Using store ${clean(String(stores[0].name))} (${clean(stores[0].id)})`);
313
+ return stores[0].id;
314
+ }
315
+ stores.forEach((s, i) => console.log(` ${i + 1}) ${clean(String(s.name))} ${clean(s.id)}`));
316
+ if (!stdin.isTTY || !stdout.isTTY)
317
+ throw new Error("Provide --store or set storeId in mycatalog.json");
318
+ const readline = createInterface({ input: stdin, output: stdout });
319
+ try {
320
+ const id = pickStore(stores, await readline.question(`Choose a store [1-${stores.length}]: `));
321
+ if (!id)
322
+ throw new Error("Invalid choice. Run again, or pass --store <id>.");
323
+ console.log(`Tip: set "storeId": "${clean(id)}" in mycatalog.json to skip this question.`);
324
+ return id;
325
+ }
326
+ finally {
327
+ readline.close();
328
+ }
329
+ }
299
330
  /** Print a preview URL for the configured draft and an explicitly selected owned store. */
300
331
  export async function preview(store) {
301
332
  const config = await loadConfig();
302
333
  const ids = requireIds(config);
303
- const storeId = store || config.storeId;
304
- if (!storeId) {
305
- throw new Error("Provide --store or set storeId in mycatalog.json");
306
- }
307
- const response = await (await Api.fromStore()).request(`${versionPath(ids.themeId, ids.versionId)}/preview`, {
334
+ const api = await Api.fromStore();
335
+ const storeId = store || config.storeId || await selectStore(api);
336
+ const response = await api.request(`${versionPath(ids.themeId, ids.versionId)}/preview`, {
308
337
  method: "POST",
309
338
  headers: { "content-type": "application/json" },
310
339
  body: JSON.stringify({ storeId }),
340
+ }).catch((error) => {
341
+ if (!/\(404\)|not found/i.test(error.message))
342
+ throw error;
343
+ throw new Error(`${error.message}. Check mycatalog.json: storeId must be a store ID from \`mycatalog whoami\` (not a slug such as "my-store") for a store you own, and themeId/versionId must come from \`mycatalog theme list\`.`);
311
344
  });
312
345
  if (typeof response.url !== "string") {
313
346
  throw new Error("Preview response did not include a URL");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycatalog/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "MyCatalog theme developer CLI",
5
5
  "license": "MIT",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/mycatalog-io/cli.git" },