@sbuilder/cli 0.15.0 → 0.17.0

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
@@ -720,8 +720,11 @@ sb site pull # take what was edited in the editor
720
720
  sb site push # save edited page files as DRAFTS
721
721
  sb site push --prune --yes # also delete the pages whose file is gone (--yes off a terminal)
722
722
  sb site push --theme # also send design/theme.json (a theme save is live at once)
723
+ sb site push --settings # also send design/settings.json (store details, currency: live at once)
724
+ sb site push --functions # also send functions/*.ts (backend functions: live at once)
725
+ sb site media [--json] # each file in media/ and its address (push uploads new ones)
723
726
  sb site status # what differs from the last sync; stale translations
724
- sb site dev # watch design/ and code/ and push each save as a DRAFT
727
+ sb site dev # watch design/, code/, functions/, media/ and push each save
725
728
  sb site publish --all # make pages live (or name files)
726
729
  sb site preview design/pages/index.page.tsx # a link to that page's DRAFT, rendered (--open opens it, --html prints it); nothing published
727
730
  sb site next # serve the pages from a Next.js app (npm run dev)
@@ -1049,6 +1052,9 @@ A repo made by `sb site init` also holds, next to `design/pages/`:
1049
1052
  | Shared sections (header, footer, custom) | `design/globals/<name>.page.tsx` | `export const global = { id, name, kind }` |
1050
1053
  | Overlays (cart, pop-ups, quick view) | `design/overlays/<name>.page.tsx` | `export const overlay = { id, name, kind, allPages, pages }`: `allPages` is "shown on every page" and `pages` the page ids it is attached to — two separate facts (a pop-up shown everywhere keeps its page list); a cart and a quick view have `allPages: false, pages: []` |
1051
1054
  | The theme | `design/theme.json` | the theme document, keys sorted |
1055
+ | The site settings (store details, currency, markets, contact, social) | `design/settings.json` | the settings document, keys sorted |
1056
+ | Backend functions | `functions/<slug>.ts` (or `.js`), served at `/_wb/fn/<slug>`; `_<slug>` is a module the others import | the code itself — nothing else in the file |
1057
+ | Media (images, videos, fonts) | `media/<name>.<png, jpg, webp, svg, mp4, woff2…>` | the bytes — `sb site media` prints the address each one was uploaded as |
1052
1058
  | Translations | `design/translations/<locale>.json` | nested `{ "<entityType>": { "<entityId>": { "<field>": { value, source, sourceHash } } } }` (an id or field may contain a `/`) |
1053
1059
 
1054
1060
  These need the repo's API key (a session login skips them and says so). Every one follows the
@@ -1064,13 +1070,30 @@ off a terminal) deletes a shared section or overlay whose file is gone, or trans
1064
1070
  the file dropped, after listing them. A section still shown on pages comes back as `in_use`
1065
1071
  with the page count and is kept: the CLI never forces it.
1066
1072
 
1067
- **The theme is live the moment it is saved** (there is no publish step), so `sb site push` sends
1068
- `design/theme.json` only with `--theme`; without it the file is named as withheld and nothing is
1069
- sent. Translations you add without a `source` are sent as `machine`; `sourceHash` is the editor's
1073
+ **The theme, the settings and a function are live the moment they are saved** (there is no
1074
+ publish step), so `sb site push` sends `design/theme.json` only with `--theme`,
1075
+ `design/settings.json` only with `--settings` and `functions/` only with `--functions`; without the
1076
+ flag a changed file is named as withheld and nothing is sent. Each is guarded by the platform's
1077
+ `updatedAt`: a save made in the editor since your pull refuses yours by name. A function that does
1078
+ not compile is saved but reported as a failure (exit 1) with the first line of the error — the last
1079
+ good build keeps serving. Functions and settings are never deleted from here; delete a function in
1080
+ the editor. Secrets stay on the platform (a function reads them as `ctx.env.KEY`). Pushing
1081
+ **settings** needs a key that holds `site.update`, which the key `sb site init` makes leaves out on
1082
+ purpose (it also changes domains, payment and tax): change them in the editor, or put such a key in
1083
+ `SB_TOKEN` for that one push. Pulling them works with the repo's own key.
1084
+
1085
+ **Media is uploaded, never replaced.** `sb site push` uploads each file in `media/` that is new or
1086
+ whose bytes changed (25 MB at most; a full store is refused with how full it is) and records the
1087
+ address in `.sb-site.json`. Changed bytes get a NEW address — pages keep the old one until you point
1088
+ them at the new URL, so an upload never changes a live page by itself — and nothing is ever deleted
1089
+ from here, since a published page may still use it. `sb site media` (`--json` for a script or an
1090
+ agent) lists each file and its address.
1091
+
1092
+ Translations you add without a `source` are sent as `machine`; `sourceHash` is the editor's
1070
1093
  fingerprint of the source text, and `sb site status` and `sb site pull` name every translation
1071
1094
  whose source text has changed since it was translated as STALE.
1072
1095
 
1073
- `sb site dev` watches `design/` and `code/` and pushes each saved file as a DRAFT after 300 ms of
1096
+ `sb site dev` watches `design/`, `code/`, `functions/` and `media/` and pushes each saved file as a DRAFT after 300 ms of
1074
1097
  quiet. It is `sb site push` per file: a parse error is printed as `file:line:col` and sends
1075
1098
  nothing, a file that got a 409 (the editor changed it) is stopped and named, and it never
1076
1099
  publishes or prunes, and it does not take `--force` (that would overwrite the editor on every save). A page whose repo has no record of the last sync (a manifest from an older CLI) names any fact the file states differently from the platform instead of sending it: `sb site pull` records them.
@@ -1156,6 +1179,17 @@ component, so the published page hydrates it in the browser — every code compo
1156
1179
  `export const schema` is not a component and is skipped by name — `components/` is also the folder
1157
1180
  a Next.js app keeps its own components in.
1158
1181
 
1182
+ ## Tab completion
1183
+
1184
+ ```bash
1185
+ eval "$(sb completion zsh)" # in ~/.zshrc (bash: sb completion bash in ~/.bashrc)
1186
+ sb completion fish > ~/.config/fish/completions/sb.fish
1187
+ ```
1188
+
1189
+ Commands, subcommands and each command's flags complete with Tab. The script asks `sb` itself for
1190
+ the candidates, so a new version completes its new commands without reinstalling the script; where
1191
+ no command or flag fits (a page file for `sb site publish`), the shell completes file names.
1192
+
1159
1193
  ## `sb doctor` — check the setup
1160
1194
 
1161
1195
  ```
@@ -1308,6 +1342,8 @@ Three are read by the CLI itself:
1308
1342
  | `SB_HOST_SECRET` | a deployed `sb site next` app | the host secret `sb site next --link` wrote into `.env`; the host signs every request it forwards with it (never logged, never in a URL) |
1309
1343
  | `SB_SITE_ID` | a deployed `sb site next` app | the site the host signs for (written beside the secret) |
1310
1344
  | `SB_TRUST_PROXY` | a `sb site next` app | `N` = the number of proxies you control in front of the host: the visitor is the Nth hop from the right of `x-forwarded-for` (on Vercel the first hop is used and this is not needed) |
1345
+ | `NO_COLOR` / `FORCE_COLOR` | every command | colour and the logo are drawn only on a terminal; `NO_COLOR` (any value) turns them off, `FORCE_COLOR=1` turns them on in a pipe or CI log, `FORCE_COLOR=0` off. Off a terminal the output is the plain text, byte for byte |
1346
+ | `SB_NO_UPDATE_CHECK` / `NO_UPDATE_NOTIFIER` | every command | set: never look for a newer sb. Otherwise, on a terminal and not in CI or `--json`, sb reads the public `latest` tag from the npm registry at most once a day (an anonymous GET, 1.5 s at most, cached in `~/.config/sb/update-check.json`) and prints a one-box notice after the command when a newer version exists |
1311
1347
 
1312
1348
  `SB_TOKEN` **overrides** the stored `sb login` credential when set. For `sb app dev`
1313
1349
  and `sb app deploy` it is a token for the **organization that owns the app** — the
package/README.vi.md CHANGED
@@ -721,8 +721,11 @@ sb site pull # lấy những gì đã sửa trong editor
721
721
  sb site push # lưu file trang đã sửa thành BẢN NHÁP
722
722
  sb site push --prune --yes # xoá cả các trang đã mất file (--yes khi không ở terminal)
723
723
  sb site push --theme # gửi cả design/theme.json (lưu theme có hiệu lực ngay)
724
+ sb site push --settings # gửi cả design/settings.json (thông tin cửa hàng, tiền tệ: hiệu lực ngay)
725
+ sb site push --functions # gửi cả functions/*.ts (backend function: hiệu lực ngay)
726
+ sb site media [--json] # từng file trong media/ và địa chỉ của nó (push upload file mới)
724
727
  sb site status # điều khác với lần đồng bộ gần nhất; bản dịch lỗi thời
725
- sb site dev # theo dõi design/ và code/, mỗi lần lưu là một BẢN NHÁP
728
+ sb site dev # theo dõi design/, code/, functions/, media/; mỗi lần lưu là BẢN NHÁP
726
729
  sb site publish --all # xuất bản trang (hoặc chỉ định file)
727
730
  sb site preview design/pages/index.page.tsx # liên kết tới BẢN NHÁP của trang, đã render (--open mở nó, --html in HTML); không xuất bản gì
728
731
  sb site next # phục vụ các trang từ một app Next.js (npm run dev)
@@ -1036,6 +1039,9 @@ Repo do `sb site init` tạo còn chứa, bên cạnh `design/pages/`:
1036
1039
  | Section dùng chung (header, footer, tuỳ chỉnh) | `design/globals/<tên>.page.tsx` | `export const global = { id, name, kind }` |
1037
1040
  | Overlay (giỏ hàng, pop-up, xem nhanh) | `design/overlays/<tên>.page.tsx` | `export const overlay = { id, name, kind, allPages, pages }`: `allPages` là "hiện trên mọi trang", `pages` là các id trang được gắn — hai thông tin riêng (pop-up hiện mọi trang vẫn giữ danh sách trang); giỏ hàng và xem nhanh có `allPages: false, pages: []` |
1038
1041
  | Theme | `design/theme.json` | tài liệu theme, khoá đã sắp xếp |
1042
+ | Cài đặt site (thông tin cửa hàng, tiền tệ, thị trường, liên hệ, mạng xã hội) | `design/settings.json` | tài liệu cài đặt, khoá đã sắp xếp |
1043
+ | Backend function | `functions/<slug>.ts` (hoặc `.js`), chạy ở `/_wb/fn/<slug>`; `_<slug>` là module để các function khác import | chính đoạn code — file không chứa gì khác |
1044
+ | Media (ảnh, video, font) | `media/<tên>.<png, jpg, webp, svg, mp4, woff2…>` | nội dung file — `sb site media` in địa chỉ mà mỗi file đã được upload |
1039
1045
  | Bản dịch | `design/translations/<locale>.json` | lồng nhau `{ "<entityType>": { "<entityId>": { "<field>": { value, source, sourceHash } } } }` (id hay field có thể chứa `/`) |
1040
1046
 
1041
1047
  Các loại này cần API key của repo (đăng nhập phiên sẽ bỏ qua và nói rõ). Mỗi loại theo đúng
@@ -1051,13 +1057,29 @@ ngoài terminal) xoá section dùng chung hoặc overlay đã mất file, hoặc
1051
1057
  bỏ, sau khi liệt kê chúng. Section còn đang hiển thị trên trang sẽ trả về `in_use` kèm số trang
1052
1058
  và được giữ lại: CLI không bao giờ ép xoá.
1053
1059
 
1054
- **Theme có hiệu lực ngay khi lưu** (không có bước xuất bản), nên `sb site push` chỉ gửi
1055
- `design/theme.json` khi có `--theme`; không có thì file được nêu là bị giữ lại và không gửi gì.
1060
+ **Theme, cài đặt và function có hiệu lực ngay khi lưu** (không có bước xuất bản), nên
1061
+ `sb site push` chỉ gửi `design/theme.json` khi có `--theme`, `design/settings.json` khi có
1062
+ `--settings` và `functions/` khi có `--functions`; thiếu cờ thì file đã đổi được nêu là bị giữ lại
1063
+ và không gửi gì. Mỗi loại được canh bằng `updatedAt` của nền tảng: một lần lưu trong editor từ sau
1064
+ lần pull của bạn sẽ làm bản của bạn bị từ chối, có nêu tên. Function không biên dịch được vẫn được
1065
+ lưu nhưng bị báo là lỗi (mã thoát 1) kèm dòng đầu của lỗi — bản build tốt gần nhất vẫn tiếp tục
1066
+ chạy. Function và cài đặt không bao giờ bị xoá từ đây; muốn xoá function thì xoá trong editor.
1067
+ Secret ở lại trên nền tảng (function đọc chúng qua `ctx.env.KEY`). Push
1068
+ **cài đặt** cần một key có `site.update` — key mà `sb site init` tạo cố ý không có quyền này (nó còn
1069
+ đổi được tên miền, thanh toán và thuế): sửa cài đặt trong editor, hoặc đặt một key như vậy vào
1070
+ `SB_TOKEN` cho riêng lần push đó. Pull cài đặt thì key của repo vẫn làm được.
1071
+
1072
+ **Media chỉ được upload, không bao giờ bị thay thế.** `sb site push` upload mỗi file trong `media/`
1073
+ còn mới hoặc đã đổi nội dung (tối đa 25 MB; cửa hàng hết dung lượng thì bị từ chối kèm con số đã
1074
+ dùng) và ghi địa chỉ vào `.sb-site.json`. Nội dung đổi thì có địa chỉ MỚI — trang vẫn dùng địa chỉ
1075
+ cũ cho tới khi bạn trỏ sang URL mới, nên một lần upload không tự đổi trang đang chạy — và không gì
1076
+ bị xoá từ đây, vì trang đã xuất bản có thể còn dùng file đó. `sb site media` (`--json` cho script
1077
+ hay agent) liệt kê từng file và địa chỉ của nó.
1056
1078
  Bản dịch bạn thêm mà không ghi `source` được gửi là `machine`; `sourceHash` là dấu vân tay của
1057
1079
  editor cho văn bản gốc, và `sb site status` cùng `sb site pull` nêu tên mọi bản dịch có văn bản
1058
1080
  gốc đã đổi từ lúc dịch là STALE.
1059
1081
 
1060
- `sb site dev` theo dõi `design/` và `code/` và đẩy mỗi file đã lưu thành BẢN NHÁP sau 300 ms
1082
+ `sb site dev` theo dõi `design/`, `code/`, `functions/` và `media/` và đẩy mỗi file đã lưu thành BẢN NHÁP sau 300 ms
1061
1083
  yên lặng. Nó là `sb site push` cho từng file: lỗi cú pháp được in dạng `file:line:col` và không
1062
1084
  gửi gì, file bị 409 (editor đã đổi nó) bị dừng và nêu tên, và nó không bao giờ xuất bản hay
1063
1085
  `--prune`, và không nhận `--force` (nó sẽ ghi đè editor ở mỗi lần lưu). Trang mà repo không có bản ghi của lần đồng bộ gần nhất (manifest từ CLI cũ) sẽ nêu tên thông tin file ghi khác nền tảng thay vì gửi nó: `sb site pull` sẽ ghi lại chúng.
@@ -1143,6 +1165,17 @@ trong trình duyệt — component nào cũng kèm JavaScript của nó.
1143
1165
  không có `export const schema` không phải component và bị bỏ qua có nêu tên — `components/` cũng
1144
1166
  là thư mục app Next.js dùng cho component riêng của nó.
1145
1167
 
1168
+ ## Tự hoàn thành bằng Tab
1169
+
1170
+ ```bash
1171
+ eval "$(sb completion zsh)" # thêm vào ~/.zshrc (bash: sb completion bash trong ~/.bashrc)
1172
+ sb completion fish > ~/.config/fish/completions/sb.fish
1173
+ ```
1174
+
1175
+ Lệnh, lệnh con và cờ của từng lệnh đều tự hoàn thành bằng Tab. Script hỏi chính `sb` để lấy gợi ý,
1176
+ nên bản mới tự hoàn thành được lệnh mới mà không cần cài lại script; chỗ nào không có lệnh hay cờ
1177
+ phù hợp (file trang cho `sb site publish`) thì shell gợi ý tên file.
1178
+
1146
1179
  ## `sb doctor` — kiểm tra cài đặt
1147
1180
 
1148
1181
  ```
@@ -1293,6 +1326,8 @@ Ba biến do chính CLI đọc:
1293
1326
  | `SB_HOST_SECRET` | app `sb site next` đã deploy | host secret mà `sb site next --link` ghi vào `.env`; host ký mọi request nó chuyển tiếp bằng nó (không bao giờ ghi log, không nằm trong URL) |
1294
1327
  | `SB_SITE_ID` | app `sb site next` đã deploy | site mà host ký cho (được ghi cạnh secret) |
1295
1328
  | `SB_TRUST_PROXY` | app `sb site next` | `N` = số proxy do bạn kiểm soát đứng trước host: khách là hop thứ N tính từ bên phải của `x-forwarded-for` (trên Vercel dùng hop đầu, không cần) |
1329
+ | `NO_COLOR` / `FORCE_COLOR` | mọi lệnh | màu và logo chỉ vẽ khi chạy trên terminal; `NO_COLOR` (giá trị bất kỳ) tắt chúng, `FORCE_COLOR=1` bật cả khi pipe hay trong log CI, `FORCE_COLOR=0` tắt. Ngoài terminal, output là văn bản thuần, giữ nguyên từng byte |
1330
+ | `SB_NO_UPDATE_CHECK` / `NO_UPDATE_NOTIFIER` | mọi lệnh | có đặt: không bao giờ tìm bản sb mới hơn. Nếu không, khi chạy trên terminal và không ở CI hay `--json`, sb đọc tag `latest` công khai trên npm tối đa mỗi ngày một lần (một GET ẩn danh, tối đa 1,5 giây, lưu tạm ở `~/.config/sb/update-check.json`) và in một khung thông báo sau lệnh khi có bản mới |
1296
1331
 
1297
1332
  `SB_TOKEN`, khi được đặt, **ghi đè** credential đã lưu của `sb login`. Với
1298
1333
  `sb app dev` và `sb app deploy`, nó là token của **tổ chức sở hữu app** — đúng cái user
package/dist/bin/sb.js CHANGED
@@ -7,9 +7,9 @@
7
7
  * and an exit code.
8
8
  */
9
9
  import { lstat } from 'node:fs/promises';
10
- import { existsSync, realpathSync } from 'node:fs';
10
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
11
11
  import { homedir, userInfo } from 'node:os';
12
- import { join, resolve } from 'node:path';
12
+ import { dirname, join, resolve } from 'node:path';
13
13
  import { init, nextSteps, normalizeName, InitError } from '../src/init.js';
14
14
  import { readConfig, watchAndUpload, DevError } from '../src/dev.js';
15
15
  import { deploy, submit, DeployStopped } from '../src/deploy.js';
@@ -20,7 +20,7 @@ import { agent } from '../src/agent.js';
20
20
  import { servicePlan, install, uninstall, status } from '../src/service.js';
21
21
  import { newSite, openBrowser } from '../src/new.js';
22
22
  import { preview as sitePreview } from '../src/preview.js';
23
- import { pull as sitePull, push as sitePush, publish as sitePublish, blocks as siteBlocks, } from '../src/site.js';
23
+ import { pull as sitePull, push as sitePush, publish as sitePublish, blocks as siteBlocks, readManifest, } from '../src/site.js';
24
24
  import { doctor, lines as doctorLines } from '../src/doctor.js';
25
25
  import { componentsInit, deleteRemote as componentsDelete, listRemote as componentsList, preview as componentsPreview, upgrade as componentsUpgrade, } from '../src/components.js';
26
26
  import { linkHost } from '../src/hostlink.js';
@@ -34,9 +34,14 @@ import { initNextStarter } from '../src/starter.js';
34
34
  import { findTemplate, listTemplates, templateLines, useTemplate } from '../src/templates.js';
35
35
  import { deployVercel } from '../src/vercel.js';
36
36
  import { deployDocker } from '../src/selfhost.js';
37
+ import { mediaTable } from '../src/sitemedia.js';
38
+ import { newerVersion, shouldCheck, updateNotice } from '../src/update.js';
39
+ import { complete, script } from '../src/completion.js';
37
40
  import { route, SUBCOMMANDS } from '../src/route.js';
38
41
  import { createApp, createdSteps } from '../src/appcreate.js';
39
42
  import { VERSION } from '../src/login.js';
43
+ import { banner, colorOn, failure, installPainter, paint, paintHelp, question, spinner, } from '../src/ui.js';
44
+ import { credentialsPath } from '../src/auth.js';
40
45
  import { spawnSync } from 'node:child_process';
41
46
  import { createInterface } from 'node:readline/promises';
42
47
  const USAGE = `sb — the Store Builder command line
@@ -57,6 +62,8 @@ Account
57
62
  problem names its fix; exit 1 on any failure.
58
63
  --build also bundles components/, which RUNS this
59
64
  repo's own esbuild (code from its node_modules)
65
+ sb completion bash|zsh|fish
66
+ print the Tab-completion script — eval "$(sb completion zsh)"
60
67
  sb whoami which account (and platform) this CLI acts as
61
68
 
62
69
  Sites
@@ -81,16 +88,22 @@ Sites
81
88
  ways. --github also creates the private repo (gh).
82
89
  sb site pull [--site <id>] [--force] [--dry-run]
83
90
  take pages edited in the editor into design/pages
84
- sb site push [--force] [--dry-run] [--prune] [--yes] [--theme]
91
+ sb site push [--force] [--dry-run] [--prune] [--yes] [--theme] [--settings] [--functions]
85
92
  save edited page files as DRAFTS (never publishes);
86
93
  refuses a page edited in the editor since your pull.
87
94
  "export const page" in a file creates or renames the
88
95
  page; --prune deletes what a gone file stood for
89
- (--yes too, off a terminal); --theme also sends
90
- design/theme.json — a theme save is LIVE at once
96
+ (--yes too, off a terminal); uploads new files in
97
+ media/; --theme also sends design/theme.json,
98
+ --settings design/settings.json and --functions
99
+ functions/*.ts — those three are LIVE at once
100
+ sb site media [--json] each file in media/ and the address it was uploaded as
101
+ (sb site push uploads new and changed ones; never deletes)
91
102
  sb site status what differs from the last sync, and translations
92
103
  whose source text changed (offline)
93
- sb site dev [--theme] watch design/ and code/ and push each save as a DRAFT
104
+ sb site dev [--theme] [--settings] [--functions]
105
+ watch design/, code/, functions/ and media/ and push each
106
+ save as a DRAFT (theme, settings, functions: their flag)
94
107
  sb site publish <file>… | --all
95
108
  make pages LIVE — named files, or every page
96
109
  sb site preview <file> [--open] [--html]
@@ -235,6 +248,12 @@ function parse(argv) {
235
248
  else if (a === '--theme') {
236
249
  args.theme = true;
237
250
  }
251
+ else if (a === '--functions') {
252
+ args.functions = true;
253
+ }
254
+ else if (a === '--settings') {
255
+ args.settings = true;
256
+ }
238
257
  else if (a === '--prune') {
239
258
  args.prune = true;
240
259
  }
@@ -285,10 +304,22 @@ async function credential(api) {
285
304
  return token;
286
305
  return (await readPair(api)) ? storedAuth(api) : undefined;
287
306
  }
288
- async function ask(question) {
307
+ async function ask(q) {
289
308
  const rl = createInterface({ input: process.stdin, output: process.stdout });
309
+ // Ctrl+C or Ctrl+D at a question is "never mind": say so and leave, never a stack trace.
310
+ const cancel = () => {
311
+ process.stdout.write('\n');
312
+ console.error('Cancelled.');
313
+ process.exit(130);
314
+ };
315
+ rl.on('SIGINT', cancel);
290
316
  try {
291
- return (await rl.question(question)).trim();
317
+ return (await rl.question(question(paint(colorOn(process.stdout)), q))).trim();
318
+ }
319
+ catch (err) {
320
+ if (err.code === 'ABORT_ERR')
321
+ cancel();
322
+ throw err;
292
323
  }
293
324
  finally {
294
325
  rl.close();
@@ -331,7 +362,7 @@ async function startSiteRepo(o) {
331
362
  const api = apiBase();
332
363
  let token = await credential(api);
333
364
  if (!token) {
334
- await login({ api });
365
+ await login({ api, spin: true });
335
366
  token = await credential(api);
336
367
  }
337
368
  const dir = resolve(o.dir);
@@ -342,14 +373,21 @@ async function startSiteRepo(o) {
342
373
  // No token: initSite refuses below with the sign-in sentence, before anything is created.
343
374
  if (o.template && token) {
344
375
  // (The folder was checked above: a copy made for a folder init then refuses would be left behind.)
345
- site = await useTemplate({
346
- api,
347
- token,
348
- template: o.template,
349
- name,
350
- dir: o.dir,
351
- log: (l) => console.log(l),
352
- });
376
+ const sp = spinner(`Copying "${o.template.name}"…`);
377
+ try {
378
+ site = await useTemplate({
379
+ api,
380
+ token,
381
+ template: o.template,
382
+ name,
383
+ dir: o.dir,
384
+ log: (l) => console.log(l),
385
+ status: sp?.update,
386
+ });
387
+ }
388
+ finally {
389
+ sp?.stop();
390
+ }
353
391
  console.log(`Created ${name} from the ${o.template.name} template.`);
354
392
  }
355
393
  const copied = o.template ? site : undefined;
@@ -468,7 +506,7 @@ async function siteNewEditor(prompt) {
468
506
  return 1;
469
507
  }
470
508
  if (!(await credential(api)))
471
- await login({ api });
509
+ await login({ api, spin: true });
472
510
  const token = await credential(api);
473
511
  if (!token) {
474
512
  console.error(NOT_SIGNED_IN);
@@ -490,7 +528,7 @@ async function appCreate(o) {
490
528
  const api = apiBase();
491
529
  let token = await credential(api);
492
530
  if (!token) {
493
- await login({ api });
531
+ await login({ api, spin: true });
494
532
  token = await credential(api);
495
533
  }
496
534
  if (!token) {
@@ -546,13 +584,21 @@ async function appInit(o) {
546
584
  }
547
585
  /** The menu: `sb init` with no arguments on a terminal. */
548
586
  async function menu(args) {
549
- const choice = await ask('What do you want to start?\n' +
550
- ' 1) A new website, built by AI — describe it, an AI agent builds it\n' +
551
- ' 2) A new website from a template — pick a design, then change it with AI\n' +
552
- ' 3) A repo for one of your sites — edit it with AI, synced with GitHub\n' +
553
- " 4) An app — runs inside a merchant's admin\n" +
554
- ' 5) A Next.js storefront — one of your sites as a Next.js app, with the SDK and an example route\n' +
555
- 'Choose 1-5 [1]: ');
587
+ const p = paint(colorOn(process.stdout));
588
+ console.log(banner({ version: VERSION, columns: process.stdout.columns, paint: p, big: true }));
589
+ console.log(`${p.cyan('?')} ${p.bold('What do you want to start?')}`);
590
+ const choices = [
591
+ ['A new website, built by AI', 'describe it, an AI agent builds it'],
592
+ ['A new website from a template', 'pick a design, then change it with AI'],
593
+ ['A repo for one of your sites', 'edit it with AI, synced with GitHub'],
594
+ ['An app', "runs inside a merchant's admin"],
595
+ [
596
+ 'A Next.js storefront',
597
+ 'one of your sites as a Next.js app, with the SDK and an example route',
598
+ ],
599
+ ];
600
+ choices.forEach(([what, why], i) => console.log(` ${p.cyan(p.bold(`${i + 1})`))} ${p.bold(what)} ${p.dim('— ' + why)}`));
601
+ const choice = await ask('Choose 1-5 [1]: ');
556
602
  if (choice === '' || choice === '1') {
557
603
  let description = '';
558
604
  while (!description)
@@ -795,7 +841,7 @@ async function siteCommand(args) {
795
841
  if (sub === 'types')
796
842
  return siteTypes({ dir: resolve(args.dir ?? '.'), quiet: args.quiet });
797
843
  if (!sub || !SUBCOMMANDS.site.includes(sub)) {
798
- console.error('usage: sb site new|init|templates|pull|push|publish|preview|next|deploy|blocks|agents|types|code|components|mcp|status|dev [--site <id>] [--dir <path>] [--force] [--dry-run] [--all]');
844
+ console.error('usage: sb site new|init|templates|pull|push|publish|preview|next|deploy|blocks|agents|types|code|components|mcp|media|status|dev [--site <id>] [--dir <path>] [--force] [--dry-run] [--all]');
799
845
  return 1;
800
846
  }
801
847
  if (sub === 'init') {
@@ -805,6 +851,23 @@ async function siteCommand(args) {
805
851
  github: args.github,
806
852
  });
807
853
  }
854
+ if (sub === 'media') {
855
+ // media/ → the address each file was uploaded as (sb site push uploads new and changed ones).
856
+ const dir = resolve(args.dir ?? '.');
857
+ const rows = await mediaTable(dir, (await readManifest(dir)).media);
858
+ if (args.json) {
859
+ console.log(JSON.stringify({ media: rows }, null, 2));
860
+ return 0;
861
+ }
862
+ if (!rows.length) {
863
+ console.log('No media yet: put images, videos or fonts in media/ and run sb site push — each gets an address to use in a page.');
864
+ return 0;
865
+ }
866
+ const w = Math.max(...rows.map((r) => r.file.length));
867
+ for (const r of rows)
868
+ console.log(` ${r.file.padEnd(w)} ${r.url ?? ''}${r.state === 'new' ? '(not uploaded yet — sb site push)' : r.state === 'changed' ? ' ! changed since the upload — sb site push gives it a new address' : ''}`);
869
+ return 0;
870
+ }
808
871
  if (sub === 'status')
809
872
  return siteStatus({ dir: resolve(args.dir ?? '.'), log: (l) => console.log(l) });
810
873
  if (sub === 'deploy') {
@@ -879,6 +942,8 @@ async function siteCommand(args) {
879
942
  prune: args.prune,
880
943
  yes: args.yes,
881
944
  theme: args.theme,
945
+ functions: args.functions,
946
+ settings: args.settings,
882
947
  // Asked only on a terminal; off one, `--yes` is the only way past --prune's question.
883
948
  confirm: process.stdin.isTTY ? async (q) => /^y/i.test(await ask(q)) : undefined,
884
949
  log: (l) => console.log(l),
@@ -1001,10 +1066,24 @@ async function main(rawArgv) {
1001
1066
  console.error(note);
1002
1067
  const args = parse(argv);
1003
1068
  const cmd = args._[0];
1069
+ const out = paint(colorOn(process.stdout));
1004
1070
  if (args.help || !cmd) {
1005
- console.log(USAGE);
1071
+ // Bare `sb` greets with the big logo; `--help` keeps it short.
1072
+ if (out.on)
1073
+ console.log(banner({ version: VERSION, columns: process.stdout.columns, paint: out, big: !cmd }));
1074
+ console.log(paintHelp(out, USAGE));
1075
+ if (out.on && process.stdout.isTTY)
1076
+ seen();
1077
+ return 0;
1078
+ }
1079
+ // Completion answers a shell, not a person: nothing but the candidates.
1080
+ if (cmd === '__complete') {
1081
+ for (const c of complete(USAGE, rawArgv.slice(1)))
1082
+ console.log(c);
1006
1083
  return 0;
1007
1084
  }
1085
+ if (cmd !== 'init' && cmd !== 'completion')
1086
+ welcome(out);
1008
1087
  try {
1009
1088
  switch (cmd) {
1010
1089
  case 'site':
@@ -1015,20 +1094,31 @@ async function main(rawArgv) {
1015
1094
  return await agentCommand(args);
1016
1095
  case 'whoami':
1017
1096
  return await whoami();
1097
+ case 'completion': {
1098
+ const text = script(args._[1] ?? '');
1099
+ if (!text) {
1100
+ console.error('usage: sb completion bash|zsh|fish (then follow the line it prints first)');
1101
+ return 1;
1102
+ }
1103
+ process.stdout.write(text);
1104
+ return 0;
1105
+ }
1018
1106
  case 'doctor':
1019
1107
  return await doctorCommand(args);
1020
1108
  case 'login':
1021
1109
  case 'logout': {
1022
1110
  const api = apiBase();
1023
- await (cmd === 'login' ? login({ api }) : logout({ api }));
1111
+ await (cmd === 'login' ? login({ api, spin: true }) : logout({ api }));
1024
1112
  return 0;
1025
1113
  }
1026
1114
  case 'export':
1027
1115
  console.error("`sb export next` was removed in 0.9 — use `sb site next` (a Next.js app rendered by the platform's own renderer).");
1028
1116
  return 1;
1029
1117
  case 'init':
1030
- if (args._.length === 1 && process.stdin.isTTY && process.stdout.isTTY)
1118
+ if (args._.length === 1 && process.stdin.isTTY && process.stdout.isTTY) {
1119
+ seen();
1031
1120
  return await menu(args);
1121
+ }
1032
1122
  // A bare `sb init` off a terminal is what it always was: the app scaffold, `my-app`.
1033
1123
  return await appInit({ port: args.port, withBlock: args.withBlock });
1034
1124
  default:
@@ -1039,11 +1129,62 @@ async function main(rawArgv) {
1039
1129
  }
1040
1130
  catch (err) {
1041
1131
  if (err instanceof DevError || err instanceof DeployStopped) {
1042
- console.error(err.message);
1132
+ console.error(failure(paint(colorOn(process.stderr)), err.message));
1043
1133
  return 1;
1044
1134
  }
1045
1135
  throw err;
1046
1136
  }
1047
1137
  }
1138
+ /** Where sb remembers the last version that greeted you (beside the credentials). */
1139
+ const seenPath = () => join(dirname(credentialsPath()), 'seen-version');
1140
+ function seen() {
1141
+ try {
1142
+ mkdirSync(dirname(seenPath()), { recursive: true });
1143
+ writeFileSync(seenPath(), VERSION + '\n');
1144
+ }
1145
+ catch {
1146
+ // A read-only home is no reason to fail a command.
1147
+ }
1148
+ }
1149
+ /**
1150
+ * The first command after an install or an upgrade says hello once — the banner and where to
1151
+ * start. npm hides what an install script prints (and many installs skip scripts), so the first
1152
+ * run is the moment that is actually seen. Never off a terminal, never in CI.
1153
+ */
1154
+ function welcome(p) {
1155
+ if (!p.on || !process.stdout.isTTY || process.env.CI)
1156
+ return;
1157
+ let last = '';
1158
+ try {
1159
+ last = readFileSync(seenPath(), 'utf8').trim();
1160
+ }
1161
+ catch {
1162
+ // never greeted
1163
+ }
1164
+ if (last === VERSION)
1165
+ return;
1166
+ console.log(banner({ version: VERSION, columns: process.stdout.columns, paint: p, big: true }));
1167
+ console.log(last
1168
+ ? ` ${p.green('✓')} Updated from v${last}. ${p.dim('What changed:')} https://www.npmjs.com/package/@sbuilder/cli`
1169
+ : ` ${p.green('✓')} Installed. Start with \`sb init\` · every command: \`sb --help\``);
1170
+ console.log('');
1171
+ seen();
1172
+ }
1173
+ if (!process.argv.includes('--json'))
1174
+ installPainter();
1175
+ // Started before the command and read after it, so a slow registry costs at most its 1.5 s cap.
1176
+ const update = shouldCheck({
1177
+ env: process.env,
1178
+ tty: !!process.stderr.isTTY && !!process.stdout.isTTY,
1179
+ argv: process.argv,
1180
+ }) && !process.argv.includes('__complete')
1181
+ ? newerVersion({
1182
+ version: VERSION,
1183
+ cachePath: join(dirname(credentialsPath()), 'update-check.json'),
1184
+ })
1185
+ : undefined;
1048
1186
  process.exitCode = await main(process.argv.slice(2));
1187
+ const latest = update && (await update);
1188
+ if (latest)
1189
+ console.error(updateNotice(VERSION, latest));
1049
1190
  //# sourceMappingURL=sb.js.map