@mycatalog/cli 0.1.2 → 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
@@ -4,15 +4,56 @@
4
4
 
5
5
  ## Install
6
6
 
7
+ Requires Node.js 22 or later (`node --version`).
8
+
7
9
  ```sh
8
- npm install --global @mycatalog/cli
9
- mycatalog login
10
+ npm install -g @mycatalog/cli # -g is required: it puts the `mycatalog` command on your PATH
11
+ mycatalog --version
12
+ ```
13
+
14
+ > **Do not** use `npm i @mycatalog/cli` (without `-g`) to get the command. That only adds the package to the current
15
+ > folder's `node_modules`, and your shell will say `command not found: mycatalog`.
16
+
17
+ No install at all? Run any command with `npx`:
18
+
19
+ ```sh
20
+ npx @mycatalog/cli login
21
+ npx @mycatalog/cli theme dev
22
+ ```
23
+
24
+ ### `command not found: mycatalog`
25
+
26
+ 1. Install globally: `npm install -g @mycatalog/cli`.
27
+ 2. Still missing? Your npm global folder is not on PATH. Run `npm config get prefix`; its `bin` folder (for example
28
+ `/usr/local/bin` or `~/.npm-global/bin`) must be in your PATH. Add it to `~/.zshrc`, then open a new terminal:
29
+ `export PATH="$(npm config get prefix)/bin:$PATH"`.
30
+ 3. `EACCES` permission error on install: do not use `sudo`. Use a Node version manager (nvm, fnm) or set
31
+ `npm config set prefix ~/.npm-global` and add `~/.npm-global/bin` to PATH.
32
+
33
+ ## Quick start
34
+
35
+ ```sh
36
+ mycatalog login # shows a code; approve it in your browser
37
+ mycatalog whoami # your account and store ids
38
+ mycatalog theme list # your themes and version ids
39
+ mycatalog theme init my-theme # or cd into an existing theme folder
40
+ cd my-theme # set themeId, versionId and storeId in mycatalog.json
41
+ mycatalog theme check # same checks as the server
42
+ mycatalog theme dev # upload, pick a store, print a preview link, re-upload on save
10
43
  ```
11
44
 
12
45
  Login uses the OAuth device flow. It displays a code and verification page, then asks before opening the browser. Use
13
46
  `--open` to open the page immediately. Local development may use `--api-url http://localhost:3000
14
47
  --insecure-localhost`; plain HTTP is limited to loopback hosts.
15
48
 
49
+ ## Update
50
+
51
+ ```sh
52
+ npm install -g @mycatalog/cli@latest
53
+ ```
54
+
55
+ The CLI tells you about a new version at most once a day; it never updates itself.
56
+
16
57
  ## Commands
17
58
 
18
59
  - `mycatalog login [--api-url URL] [--insecure-localhost] [--open]` — authenticate with the device flow.
@@ -27,7 +68,7 @@ Login uses the OAuth device flow. It displays a code and verification page, then
27
68
  - `mycatalog theme check` — run local folder, JSON, markup, CSS animation, and size checks.
28
69
  - `mycatalog --help`, `mycatalog theme --help`, `mycatalog --version` — show usage or version.
29
70
 
30
- 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
31
72
  only and cannot change the API host that receives credentials. Global `--json` enables machine-readable output;
32
73
  `--verbose` is reserved for safe diagnostics.
33
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.2";
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.2",
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" },