@sbuilder/cli 0.16.0 → 0.18.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 +79 -5
- package/README.vi.md +77 -4
- package/dist/bin/sb.js +127 -20
- package/dist/bin/sb.js.map +1 -1
- package/dist/src/adopt.js +184 -0
- package/dist/src/adopt.js.map +1 -0
- package/dist/src/agentdocs.js +18 -0
- package/dist/src/agentdocs.js.map +1 -1
- package/dist/src/completion.js +80 -0
- package/dist/src/completion.js.map +1 -0
- package/dist/src/components.js +9 -1
- package/dist/src/components.js.map +1 -1
- package/dist/src/envtypes.gen.js +9 -5
- package/dist/src/envtypes.gen.js.map +1 -1
- package/dist/src/login.js +52 -44
- package/dist/src/login.js.map +1 -1
- package/dist/src/nextshims.js +180 -0
- package/dist/src/nextshims.js.map +1 -0
- package/dist/src/preview.js +12 -3
- package/dist/src/preview.js.map +1 -1
- package/dist/src/route.js +2 -0
- package/dist/src/route.js.map +1 -1
- package/dist/src/site.js +6 -0
- package/dist/src/site.js.map +1 -1
- package/dist/src/sitedev.js +11 -2
- package/dist/src/sitedev.js.map +1 -1
- package/dist/src/sitefunctions.js +206 -0
- package/dist/src/sitefunctions.js.map +1 -0
- package/dist/src/sitekinds.js +149 -51
- package/dist/src/sitekinds.js.map +1 -1
- package/dist/src/sitemedia.js +115 -0
- package/dist/src/sitemedia.js.map +1 -0
- package/dist/src/sitepaths.js +5 -0
- package/dist/src/sitepaths.js.map +1 -1
- package/dist/src/sitestatus.js +15 -0
- package/dist/src/sitestatus.js.map +1 -1
- package/dist/src/templates.js +5 -1
- package/dist/src/templates.js.map +1 -1
- package/dist/src/ui.js +35 -0
- package/dist/src/ui.js.map +1 -1
- package/dist/src/update.js +79 -0
- package/dist/src/update.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -720,8 +720,12 @@ 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 adopt app/pricing # a hand-written Next.js page onto the store (an app/api route: a function)
|
|
726
|
+
sb site media [--json] # each file in media/ and its address (push uploads new ones)
|
|
723
727
|
sb site status # what differs from the last sync; stale translations
|
|
724
|
-
sb site dev # watch design
|
|
728
|
+
sb site dev # watch design/, code/, functions/, media/ and push each save
|
|
725
729
|
sb site publish --all # make pages live (or name files)
|
|
726
730
|
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
731
|
sb site next # serve the pages from a Next.js app (npm run dev)
|
|
@@ -984,6 +988,44 @@ writes its own without it. The Next app `sb site next` writes runs `sb site type
|
|
|
984
988
|
non-array `exclude` or a symlink, `sb site types` says what to add and exits 1, so `prebuild`
|
|
985
989
|
stops there instead of failing later inside `next build`.
|
|
986
990
|
|
|
991
|
+
### Bringing a hand-written route back: `sb site adopt`
|
|
992
|
+
|
|
993
|
+
```bash
|
|
994
|
+
sb site adopt app/pricing # a page → components/Pricing.tsx + design/pages/pricing.page.tsx (a DRAFT)
|
|
995
|
+
sb site adopt app/api/hello # an API route → functions/hello.ts (sent with push --functions)
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
A page you wrote by hand under `app/` lives only on the Next.js host — until you adopt it. `adopt`
|
|
999
|
+
writes `components/<Name>.tsx`, which **re-exports** that page (the React stays where it is: edit
|
|
1000
|
+
`app/pricing/page.tsx`, push, and the store has the new version), builds it here first (a page
|
|
1001
|
+
that cannot become a component is said before anything is written), uploads it, and creates
|
|
1002
|
+
`design/pages/<route>.page.tsx` holding it pinned to that version — pushed as a DRAFT, so
|
|
1003
|
+
`sb site preview` shows it and `sb site publish` makes it live. An API route under `app/api/`
|
|
1004
|
+
becomes ONE function file: the route's `GET`/`POST`/… behind the platform's single handler (any
|
|
1005
|
+
other method answers 405), with `NextResponse` mapped to the web `Response`; it is written, not
|
|
1006
|
+
sent — a function save is live, so that is `sb site push --functions`.
|
|
1007
|
+
|
|
1008
|
+
Refused by name, with nothing written: a dynamic segment (`[slug]` — a product, collection or
|
|
1009
|
+
article page is a page TYPE, not one page), an async page (a Server Component — the platform
|
|
1010
|
+
renders a component when the page is saved, with no request to await data in), a `"use server"`
|
|
1011
|
+
module, a route already adopted, and an API route that imports files of its own (a function is
|
|
1012
|
+
one file on the platform; shared code goes in a `functions/_name.ts` module).
|
|
1013
|
+
|
|
1014
|
+
### Components written for Next.js
|
|
1015
|
+
|
|
1016
|
+
A code component may import `next/link`, `next/image`, `next/navigation`, `next/router`,
|
|
1017
|
+
`next/dynamic` and `next/font/*` as it would in a Next.js app: the build answers each with a small
|
|
1018
|
+
shim of our own, so nothing of Next.js is installed. `Link` is an `<a>` (an object `href` becomes
|
|
1019
|
+
a URL; `prefetch`, `replace`, `scroll` are dropped), `Image` an `<img>` (`priority` loads eagerly,
|
|
1020
|
+
`fill` covers the parent; the platform's own pipeline sizes store media), the routers navigate
|
|
1021
|
+
with `location`, `dynamic()` loads on the client and renders its `loading` on the server, and a
|
|
1022
|
+
font loader returns its family as a `style`. Two things cannot have a meaning in a component and
|
|
1023
|
+
**render nothing — and the build says so**: `next/head` (a page's `<head>` is its SEO) and
|
|
1024
|
+
`next/script` (site-wide scripts are custom code). Server-only Next.js (`next/headers`,
|
|
1025
|
+
`next/server`, `next/cache`…) fails the build with that sentence. The platform renders a component
|
|
1026
|
+
in a bare sandbox when the page is saved: there is no request, so `usePathname()` is `""` and
|
|
1027
|
+
`useSearchParams()` is empty there, and the shims never touch a browser global during that render.
|
|
1028
|
+
|
|
987
1029
|
### Next.js compatibility
|
|
988
1030
|
|
|
989
1031
|
The host is plain `Request → Response` code (`@sbuilder/cli/host`) that **never imports `next`**
|
|
@@ -1049,6 +1091,9 @@ A repo made by `sb site init` also holds, next to `design/pages/`:
|
|
|
1049
1091
|
| Shared sections (header, footer, custom) | `design/globals/<name>.page.tsx` | `export const global = { id, name, kind }` |
|
|
1050
1092
|
| 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
1093
|
| The theme | `design/theme.json` | the theme document, keys sorted |
|
|
1094
|
+
| The site settings (store details, currency, markets, contact, social) | `design/settings.json` | the settings document, keys sorted |
|
|
1095
|
+
| 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 |
|
|
1096
|
+
| 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
1097
|
| Translations | `design/translations/<locale>.json` | nested `{ "<entityType>": { "<entityId>": { "<field>": { value, source, sourceHash } } } }` (an id or field may contain a `/`) |
|
|
1053
1098
|
|
|
1054
1099
|
These need the repo's API key (a session login skips them and says so). Every one follows the
|
|
@@ -1064,13 +1109,30 @@ off a terminal) deletes a shared section or overlay whose file is gone, or trans
|
|
|
1064
1109
|
the file dropped, after listing them. A section still shown on pages comes back as `in_use`
|
|
1065
1110
|
with the page count and is kept: the CLI never forces it.
|
|
1066
1111
|
|
|
1067
|
-
**The theme
|
|
1068
|
-
`design/theme.json` only with `--theme
|
|
1069
|
-
|
|
1112
|
+
**The theme, the settings and a function are live the moment they are saved** (there is no
|
|
1113
|
+
publish step), so `sb site push` sends `design/theme.json` only with `--theme`,
|
|
1114
|
+
`design/settings.json` only with `--settings` and `functions/` only with `--functions`; without the
|
|
1115
|
+
flag a changed file is named as withheld and nothing is sent. Each is guarded by the platform's
|
|
1116
|
+
`updatedAt`: a save made in the editor since your pull refuses yours by name. A function that does
|
|
1117
|
+
not compile is saved but reported as a failure (exit 1) with the first line of the error — the last
|
|
1118
|
+
good build keeps serving. Functions and settings are never deleted from here; delete a function in
|
|
1119
|
+
the editor. Secrets stay on the platform (a function reads them as `ctx.env.KEY`). Pushing
|
|
1120
|
+
**settings** needs a key that holds `site.update`, which the key `sb site init` makes leaves out on
|
|
1121
|
+
purpose (it also changes domains, payment and tax): change them in the editor, or put such a key in
|
|
1122
|
+
`SB_TOKEN` for that one push. Pulling them works with the repo's own key.
|
|
1123
|
+
|
|
1124
|
+
**Media is uploaded, never replaced.** `sb site push` uploads each file in `media/` that is new or
|
|
1125
|
+
whose bytes changed (25 MB at most; a full store is refused with how full it is) and records the
|
|
1126
|
+
address in `.sb-site.json`. Changed bytes get a NEW address — pages keep the old one until you point
|
|
1127
|
+
them at the new URL, so an upload never changes a live page by itself — and nothing is ever deleted
|
|
1128
|
+
from here, since a published page may still use it. `sb site media` (`--json` for a script or an
|
|
1129
|
+
agent) lists each file and its address.
|
|
1130
|
+
|
|
1131
|
+
Translations you add without a `source` are sent as `machine`; `sourceHash` is the editor's
|
|
1070
1132
|
fingerprint of the source text, and `sb site status` and `sb site pull` name every translation
|
|
1071
1133
|
whose source text has changed since it was translated as STALE.
|
|
1072
1134
|
|
|
1073
|
-
`sb site dev` watches `design/` and `
|
|
1135
|
+
`sb site dev` watches `design/`, `code/`, `functions/` and `media/` and pushes each saved file as a DRAFT after 300 ms of
|
|
1074
1136
|
quiet. It is `sb site push` per file: a parse error is printed as `file:line:col` and sends
|
|
1075
1137
|
nothing, a file that got a 409 (the editor changed it) is stopped and named, and it never
|
|
1076
1138
|
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 +1218,17 @@ component, so the published page hydrates it in the browser — every code compo
|
|
|
1156
1218
|
`export const schema` is not a component and is skipped by name — `components/` is also the folder
|
|
1157
1219
|
a Next.js app keeps its own components in.
|
|
1158
1220
|
|
|
1221
|
+
## Tab completion
|
|
1222
|
+
|
|
1223
|
+
```bash
|
|
1224
|
+
eval "$(sb completion zsh)" # in ~/.zshrc (bash: sb completion bash in ~/.bashrc)
|
|
1225
|
+
sb completion fish > ~/.config/fish/completions/sb.fish
|
|
1226
|
+
```
|
|
1227
|
+
|
|
1228
|
+
Commands, subcommands and each command's flags complete with Tab. The script asks `sb` itself for
|
|
1229
|
+
the candidates, so a new version completes its new commands without reinstalling the script; where
|
|
1230
|
+
no command or flag fits (a page file for `sb site publish`), the shell completes file names.
|
|
1231
|
+
|
|
1159
1232
|
## `sb doctor` — check the setup
|
|
1160
1233
|
|
|
1161
1234
|
```
|
|
@@ -1309,6 +1382,7 @@ Three are read by the CLI itself:
|
|
|
1309
1382
|
| `SB_SITE_ID` | a deployed `sb site next` app | the site the host signs for (written beside the secret) |
|
|
1310
1383
|
| `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) |
|
|
1311
1384
|
| `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 |
|
|
1385
|
+
| `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 |
|
|
1312
1386
|
|
|
1313
1387
|
`SB_TOKEN` **overrides** the stored `sb login` credential when set. For `sb app dev`
|
|
1314
1388
|
and `sb app deploy` it is a token for the **organization that owns the app** — the
|
package/README.vi.md
CHANGED
|
@@ -721,8 +721,12 @@ 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 adopt app/pricing # đưa trang Next.js viết tay lên cửa hàng (route app/api: thành function)
|
|
727
|
+
sb site media [--json] # từng file trong media/ và địa chỉ của nó (push upload file mới)
|
|
724
728
|
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
|
|
729
|
+
sb site dev # theo dõi design/, code/, functions/, media/; mỗi lần lưu là BẢN NHÁP
|
|
726
730
|
sb site publish --all # xuất bản trang (hoặc chỉ định file)
|
|
727
731
|
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
732
|
sb site next # phục vụ các trang từ một app Next.js (npm run dev)
|
|
@@ -972,6 +976,44 @@ kiểm tra (`next:tsconfig`). Một `tsconfig.json` gốc mà `sb` không sửa
|
|
|
972
976
|
nêu `design`), `exclude` không phải mảng, hoặc là symlink, `sb site types` nói cần thêm gì và thoát
|
|
973
977
|
mã 1, nên `prebuild` dừng ở đó thay vì hỏng muộn trong `next build`.
|
|
974
978
|
|
|
979
|
+
### Đưa một route viết tay trở lại: `sb site adopt`
|
|
980
|
+
|
|
981
|
+
```bash
|
|
982
|
+
sb site adopt app/pricing # một trang → components/Pricing.tsx + design/pages/pricing.page.tsx (BẢN NHÁP)
|
|
983
|
+
sb site adopt app/api/hello # một API route → functions/hello.ts (gửi bằng push --functions)
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
Trang bạn tự viết trong `app/` chỉ sống trên host Next.js — cho tới khi bạn adopt nó. `adopt` ghi
|
|
987
|
+
`components/<Tên>.tsx`, file này **re-export** trang đó (code React vẫn nằm nguyên chỗ cũ: sửa
|
|
988
|
+
`app/pricing/page.tsx`, push, là cửa hàng có bản mới), build thử ở máy trước (trang nào không thể
|
|
989
|
+
thành component thì được nói ngay, trước khi ghi bất cứ gì), upload, rồi tạo
|
|
990
|
+
`design/pages/<route>.page.tsx` chứa component đó ghim vào đúng phiên bản — push thành BẢN NHÁP,
|
|
991
|
+
nên `sb site preview` xem được và `sb site publish` mới đưa lên thật. API route trong `app/api/`
|
|
992
|
+
thành MỘT file function: `GET`/`POST`/… của route đứng sau handler duy nhất của nền tảng (phương
|
|
993
|
+
thức khác trả 405), `NextResponse` được ánh xạ sang `Response` của web; file được ghi chứ chưa gửi
|
|
994
|
+
— function lưu là chạy thật, nên bước đó là `sb site push --functions`.
|
|
995
|
+
|
|
996
|
+
Bị từ chối, có nêu lý do, và không ghi gì: segment động (`[slug]` — trang sản phẩm, collection hay
|
|
997
|
+
bài viết là một LOẠI trang, không phải một trang), trang async (Server Component — nền tảng render
|
|
998
|
+
component lúc lưu trang, không có request nào để chờ dữ liệu), module `"use server"`, route đã
|
|
999
|
+
adopt rồi, và API route import file riêng của nó (function trên nền tảng là một file; code dùng
|
|
1000
|
+
chung đặt trong module `functions/_tên.ts`).
|
|
1001
|
+
|
|
1002
|
+
### Component viết cho Next.js
|
|
1003
|
+
|
|
1004
|
+
Code component được import `next/link`, `next/image`, `next/navigation`, `next/router`,
|
|
1005
|
+
`next/dynamic` và `next/font/*` như trong app Next.js: bước build trả lời mỗi import bằng một shim
|
|
1006
|
+
nhỏ của chính CLI, nên không cài gì của Next.js. `Link` là `<a>` (`href` dạng object thành URL;
|
|
1007
|
+
`prefetch`, `replace`, `scroll` bị bỏ), `Image` là `<img>` (`priority` tải ngay, `fill` phủ kín phần
|
|
1008
|
+
tử cha; ảnh của cửa hàng do pipeline của nền tảng định cỡ), router điều hướng bằng `location`,
|
|
1009
|
+
`dynamic()` tải ở trình duyệt và render `loading` ở server, còn hàm nạp font trả họ font dưới dạng
|
|
1010
|
+
`style`. Hai thứ không thể có ý nghĩa trong một component nên **không render gì — và bước build nói
|
|
1011
|
+
rõ**: `next/head` (`<head>` của trang là phần SEO) và `next/script` (script toàn site là custom
|
|
1012
|
+
code). Next.js chỉ chạy ở server (`next/headers`, `next/server`, `next/cache`…) làm build thất bại
|
|
1013
|
+
kèm câu giải thích. Nền tảng render component trong một sandbox trống lúc lưu trang: không có
|
|
1014
|
+
request, nên ở đó `usePathname()` là `""` và `useSearchParams()` rỗng, và các shim không đụng tới
|
|
1015
|
+
biến toàn cục nào của trình duyệt trong lúc render đó.
|
|
1016
|
+
|
|
975
1017
|
### Tương thích Next.js
|
|
976
1018
|
|
|
977
1019
|
Host là code `Request → Response` thuần (`@sbuilder/cli/host`) và **không bao giờ import `next`**
|
|
@@ -1036,6 +1078,9 @@ Repo do `sb site init` tạo còn chứa, bên cạnh `design/pages/`:
|
|
|
1036
1078
|
| Section dùng chung (header, footer, tuỳ chỉnh) | `design/globals/<tên>.page.tsx` | `export const global = { id, name, kind }` |
|
|
1037
1079
|
| 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
1080
|
| Theme | `design/theme.json` | tài liệu theme, khoá đã sắp xếp |
|
|
1081
|
+
| 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 |
|
|
1082
|
+
| 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 |
|
|
1083
|
+
| 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
1084
|
| 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
1085
|
|
|
1041
1086
|
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 +1096,29 @@ ngoài terminal) xoá section dùng chung hoặc overlay đã mất file, hoặc
|
|
|
1051
1096
|
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
1097
|
và được giữ lại: CLI không bao giờ ép xoá.
|
|
1053
1098
|
|
|
1054
|
-
**Theme có hiệu lực ngay khi lưu** (không có bước xuất bản), nên
|
|
1055
|
-
`design/theme.json` khi có `--theme
|
|
1099
|
+
**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
|
|
1100
|
+
`sb site push` chỉ gửi `design/theme.json` khi có `--theme`, `design/settings.json` khi có
|
|
1101
|
+
`--settings` và `functions/` khi có `--functions`; thiếu cờ thì file đã đổi được nêu là bị giữ lại
|
|
1102
|
+
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
|
|
1103
|
+
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
|
|
1104
|
+
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
|
|
1105
|
+
chạy. Function và cài đặt không bao giờ bị xoá từ đây; muốn xoá function thì xoá trong editor.
|
|
1106
|
+
Secret ở lại trên nền tảng (function đọc chúng qua `ctx.env.KEY`). Push
|
|
1107
|
+
**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
|
|
1108
|
+
đổ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
|
|
1109
|
+
`SB_TOKEN` cho riêng lần push đó. Pull cài đặt thì key của repo vẫn làm được.
|
|
1110
|
+
|
|
1111
|
+
**Media chỉ được upload, không bao giờ bị thay thế.** `sb site push` upload mỗi file trong `media/`
|
|
1112
|
+
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ố đã
|
|
1113
|
+
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ỉ
|
|
1114
|
+
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ì
|
|
1115
|
+
bị xoá từ đây, vì trang đã xuất bản có thể còn dùng file đó. `sb site media` (`--json` cho script
|
|
1116
|
+
hay agent) liệt kê từng file và địa chỉ của nó.
|
|
1056
1117
|
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
1118
|
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
1119
|
gốc đã đổi từ lúc dịch là STALE.
|
|
1059
1120
|
|
|
1060
|
-
`sb site dev` theo dõi `design/` và `
|
|
1121
|
+
`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
1122
|
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
1123
|
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
1124
|
`--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 +1204,17 @@ trong trình duyệt — component nào cũng kèm JavaScript của nó.
|
|
|
1143
1204
|
không có `export const schema` không phải component và bị bỏ qua có nêu tên — `components/` cũng
|
|
1144
1205
|
là thư mục app Next.js dùng cho component riêng của nó.
|
|
1145
1206
|
|
|
1207
|
+
## Tự hoàn thành bằng Tab
|
|
1208
|
+
|
|
1209
|
+
```bash
|
|
1210
|
+
eval "$(sb completion zsh)" # thêm vào ~/.zshrc (bash: sb completion bash trong ~/.bashrc)
|
|
1211
|
+
sb completion fish > ~/.config/fish/completions/sb.fish
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
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 ý,
|
|
1215
|
+
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ờ
|
|
1216
|
+
phù hợp (file trang cho `sb site publish`) thì shell gợi ý tên file.
|
|
1217
|
+
|
|
1146
1218
|
## `sb doctor` — kiểm tra cài đặt
|
|
1147
1219
|
|
|
1148
1220
|
```
|
|
@@ -1294,6 +1366,7 @@ Ba biến do chính CLI đọc:
|
|
|
1294
1366
|
| `SB_SITE_ID` | app `sb site next` đã deploy | site mà host ký cho (được ghi cạnh secret) |
|
|
1295
1367
|
| `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) |
|
|
1296
1368
|
| `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 |
|
|
1369
|
+
| `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 |
|
|
1297
1370
|
|
|
1298
1371
|
`SB_TOKEN`, khi được đặt, **ghi đè** credential đã lưu của `sb login`. Với
|
|
1299
1372
|
`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
|
@@ -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,10 +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 { adopt, AdoptRefused } from '../src/adopt.js';
|
|
39
|
+
import { newerVersion, shouldCheck, updateNotice } from '../src/update.js';
|
|
40
|
+
import { complete, script } from '../src/completion.js';
|
|
37
41
|
import { route, SUBCOMMANDS } from '../src/route.js';
|
|
38
42
|
import { createApp, createdSteps } from '../src/appcreate.js';
|
|
39
43
|
import { VERSION } from '../src/login.js';
|
|
40
|
-
import { banner, colorOn, failure, installPainter, paint, paintHelp, question } from '../src/ui.js';
|
|
44
|
+
import { banner, colorOn, failure, installPainter, paint, paintHelp, question, spinner, } from '../src/ui.js';
|
|
41
45
|
import { credentialsPath } from '../src/auth.js';
|
|
42
46
|
import { spawnSync } from 'node:child_process';
|
|
43
47
|
import { createInterface } from 'node:readline/promises';
|
|
@@ -59,6 +63,8 @@ Account
|
|
|
59
63
|
problem names its fix; exit 1 on any failure.
|
|
60
64
|
--build also bundles components/, which RUNS this
|
|
61
65
|
repo's own esbuild (code from its node_modules)
|
|
66
|
+
sb completion bash|zsh|fish
|
|
67
|
+
print the Tab-completion script — eval "$(sb completion zsh)"
|
|
62
68
|
sb whoami which account (and platform) this CLI acts as
|
|
63
69
|
|
|
64
70
|
Sites
|
|
@@ -83,16 +89,26 @@ Sites
|
|
|
83
89
|
ways. --github also creates the private repo (gh).
|
|
84
90
|
sb site pull [--site <id>] [--force] [--dry-run]
|
|
85
91
|
take pages edited in the editor into design/pages
|
|
86
|
-
sb site push [--force] [--dry-run] [--prune] [--yes] [--theme]
|
|
92
|
+
sb site push [--force] [--dry-run] [--prune] [--yes] [--theme] [--settings] [--functions]
|
|
87
93
|
save edited page files as DRAFTS (never publishes);
|
|
88
94
|
refuses a page edited in the editor since your pull.
|
|
89
95
|
"export const page" in a file creates or renames the
|
|
90
96
|
page; --prune deletes what a gone file stood for
|
|
91
|
-
(--yes too, off a terminal);
|
|
92
|
-
design/theme.json
|
|
97
|
+
(--yes too, off a terminal); uploads new files in
|
|
98
|
+
media/; --theme also sends design/theme.json,
|
|
99
|
+
--settings design/settings.json and --functions
|
|
100
|
+
functions/*.ts — those three are LIVE at once
|
|
101
|
+
sb site adopt app/<route> [--dry-run]
|
|
102
|
+
a page written by hand in a Next.js repo onto the store:
|
|
103
|
+
it becomes a code component on a DRAFT page (next/link,
|
|
104
|
+
next/image… work); an app/api route becomes functions/<name>
|
|
105
|
+
sb site media [--json] each file in media/ and the address it was uploaded as
|
|
106
|
+
(sb site push uploads new and changed ones; never deletes)
|
|
93
107
|
sb site status what differs from the last sync, and translations
|
|
94
108
|
whose source text changed (offline)
|
|
95
|
-
sb site dev [--theme]
|
|
109
|
+
sb site dev [--theme] [--settings] [--functions]
|
|
110
|
+
watch design/, code/, functions/ and media/ and push each
|
|
111
|
+
save as a DRAFT (theme, settings, functions: their flag)
|
|
96
112
|
sb site publish <file>… | --all
|
|
97
113
|
make pages LIVE — named files, or every page
|
|
98
114
|
sb site preview <file> [--open] [--html]
|
|
@@ -237,6 +253,12 @@ function parse(argv) {
|
|
|
237
253
|
else if (a === '--theme') {
|
|
238
254
|
args.theme = true;
|
|
239
255
|
}
|
|
256
|
+
else if (a === '--functions') {
|
|
257
|
+
args.functions = true;
|
|
258
|
+
}
|
|
259
|
+
else if (a === '--settings') {
|
|
260
|
+
args.settings = true;
|
|
261
|
+
}
|
|
240
262
|
else if (a === '--prune') {
|
|
241
263
|
args.prune = true;
|
|
242
264
|
}
|
|
@@ -345,7 +367,7 @@ async function startSiteRepo(o) {
|
|
|
345
367
|
const api = apiBase();
|
|
346
368
|
let token = await credential(api);
|
|
347
369
|
if (!token) {
|
|
348
|
-
await login({ api });
|
|
370
|
+
await login({ api, spin: true });
|
|
349
371
|
token = await credential(api);
|
|
350
372
|
}
|
|
351
373
|
const dir = resolve(o.dir);
|
|
@@ -356,14 +378,21 @@ async function startSiteRepo(o) {
|
|
|
356
378
|
// No token: initSite refuses below with the sign-in sentence, before anything is created.
|
|
357
379
|
if (o.template && token) {
|
|
358
380
|
// (The folder was checked above: a copy made for a folder init then refuses would be left behind.)
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
381
|
+
const sp = spinner(`Copying "${o.template.name}"…`);
|
|
382
|
+
try {
|
|
383
|
+
site = await useTemplate({
|
|
384
|
+
api,
|
|
385
|
+
token,
|
|
386
|
+
template: o.template,
|
|
387
|
+
name,
|
|
388
|
+
dir: o.dir,
|
|
389
|
+
log: (l) => console.log(l),
|
|
390
|
+
status: sp?.update,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
finally {
|
|
394
|
+
sp?.stop();
|
|
395
|
+
}
|
|
367
396
|
console.log(`Created ${name} from the ${o.template.name} template.`);
|
|
368
397
|
}
|
|
369
398
|
const copied = o.template ? site : undefined;
|
|
@@ -482,7 +511,7 @@ async function siteNewEditor(prompt) {
|
|
|
482
511
|
return 1;
|
|
483
512
|
}
|
|
484
513
|
if (!(await credential(api)))
|
|
485
|
-
await login({ api });
|
|
514
|
+
await login({ api, spin: true });
|
|
486
515
|
const token = await credential(api);
|
|
487
516
|
if (!token) {
|
|
488
517
|
console.error(NOT_SIGNED_IN);
|
|
@@ -504,7 +533,7 @@ async function appCreate(o) {
|
|
|
504
533
|
const api = apiBase();
|
|
505
534
|
let token = await credential(api);
|
|
506
535
|
if (!token) {
|
|
507
|
-
await login({ api });
|
|
536
|
+
await login({ api, spin: true });
|
|
508
537
|
token = await credential(api);
|
|
509
538
|
}
|
|
510
539
|
if (!token) {
|
|
@@ -817,7 +846,7 @@ async function siteCommand(args) {
|
|
|
817
846
|
if (sub === 'types')
|
|
818
847
|
return siteTypes({ dir: resolve(args.dir ?? '.'), quiet: args.quiet });
|
|
819
848
|
if (!sub || !SUBCOMMANDS.site.includes(sub)) {
|
|
820
|
-
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]');
|
|
849
|
+
console.error('usage: sb site new|init|templates|pull|push|publish|preview|next|deploy|adopt|blocks|agents|types|code|components|mcp|media|status|dev [--site <id>] [--dir <path>] [--force] [--dry-run] [--all]');
|
|
821
850
|
return 1;
|
|
822
851
|
}
|
|
823
852
|
if (sub === 'init') {
|
|
@@ -827,6 +856,53 @@ async function siteCommand(args) {
|
|
|
827
856
|
github: args.github,
|
|
828
857
|
});
|
|
829
858
|
}
|
|
859
|
+
if (sub === 'adopt') {
|
|
860
|
+
// A hand-written Next.js route onto the store: a page becomes a code component placed on a
|
|
861
|
+
// draft page; an API route becomes a function file (sent with push --functions).
|
|
862
|
+
const route = args._[2];
|
|
863
|
+
if (!route) {
|
|
864
|
+
console.error('usage: sb site adopt app/<route> [--dry-run] (a page: app/pricing — an API route: app/api/hello)');
|
|
865
|
+
return 1;
|
|
866
|
+
}
|
|
867
|
+
const dir = resolve(args.dir ?? '.');
|
|
868
|
+
const env = siteEnv(dir);
|
|
869
|
+
const api = env.SB_API || apiBase();
|
|
870
|
+
try {
|
|
871
|
+
return await adopt({
|
|
872
|
+
api,
|
|
873
|
+
token: env.SB_TOKEN || (await credential(api)),
|
|
874
|
+
dir,
|
|
875
|
+
route,
|
|
876
|
+
dryRun: args.dryRun,
|
|
877
|
+
log: (l) => console.log(l),
|
|
878
|
+
warn: (l) => console.error(l),
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
catch (err) {
|
|
882
|
+
if (err instanceof AdoptRefused) {
|
|
883
|
+
console.error(failure(paint(colorOn(process.stderr)), err.message));
|
|
884
|
+
return 1;
|
|
885
|
+
}
|
|
886
|
+
throw err;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
if (sub === 'media') {
|
|
890
|
+
// media/ → the address each file was uploaded as (sb site push uploads new and changed ones).
|
|
891
|
+
const dir = resolve(args.dir ?? '.');
|
|
892
|
+
const rows = await mediaTable(dir, (await readManifest(dir)).media);
|
|
893
|
+
if (args.json) {
|
|
894
|
+
console.log(JSON.stringify({ media: rows }, null, 2));
|
|
895
|
+
return 0;
|
|
896
|
+
}
|
|
897
|
+
if (!rows.length) {
|
|
898
|
+
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.');
|
|
899
|
+
return 0;
|
|
900
|
+
}
|
|
901
|
+
const w = Math.max(...rows.map((r) => r.file.length));
|
|
902
|
+
for (const r of rows)
|
|
903
|
+
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' : ''}`);
|
|
904
|
+
return 0;
|
|
905
|
+
}
|
|
830
906
|
if (sub === 'status')
|
|
831
907
|
return siteStatus({ dir: resolve(args.dir ?? '.'), log: (l) => console.log(l) });
|
|
832
908
|
if (sub === 'deploy') {
|
|
@@ -901,6 +977,8 @@ async function siteCommand(args) {
|
|
|
901
977
|
prune: args.prune,
|
|
902
978
|
yes: args.yes,
|
|
903
979
|
theme: args.theme,
|
|
980
|
+
functions: args.functions,
|
|
981
|
+
settings: args.settings,
|
|
904
982
|
// Asked only on a terminal; off one, `--yes` is the only way past --prune's question.
|
|
905
983
|
confirm: process.stdin.isTTY ? async (q) => /^y/i.test(await ask(q)) : undefined,
|
|
906
984
|
log: (l) => console.log(l),
|
|
@@ -1033,7 +1111,13 @@ async function main(rawArgv) {
|
|
|
1033
1111
|
seen();
|
|
1034
1112
|
return 0;
|
|
1035
1113
|
}
|
|
1036
|
-
|
|
1114
|
+
// Completion answers a shell, not a person: nothing but the candidates.
|
|
1115
|
+
if (cmd === '__complete') {
|
|
1116
|
+
for (const c of complete(USAGE, rawArgv.slice(1)))
|
|
1117
|
+
console.log(c);
|
|
1118
|
+
return 0;
|
|
1119
|
+
}
|
|
1120
|
+
if (cmd !== 'init' && cmd !== 'completion')
|
|
1037
1121
|
welcome(out);
|
|
1038
1122
|
try {
|
|
1039
1123
|
switch (cmd) {
|
|
@@ -1045,12 +1129,21 @@ async function main(rawArgv) {
|
|
|
1045
1129
|
return await agentCommand(args);
|
|
1046
1130
|
case 'whoami':
|
|
1047
1131
|
return await whoami();
|
|
1132
|
+
case 'completion': {
|
|
1133
|
+
const text = script(args._[1] ?? '');
|
|
1134
|
+
if (!text) {
|
|
1135
|
+
console.error('usage: sb completion bash|zsh|fish (then follow the line it prints first)');
|
|
1136
|
+
return 1;
|
|
1137
|
+
}
|
|
1138
|
+
process.stdout.write(text);
|
|
1139
|
+
return 0;
|
|
1140
|
+
}
|
|
1048
1141
|
case 'doctor':
|
|
1049
1142
|
return await doctorCommand(args);
|
|
1050
1143
|
case 'login':
|
|
1051
1144
|
case 'logout': {
|
|
1052
1145
|
const api = apiBase();
|
|
1053
|
-
await (cmd === 'login' ? login({ api }) : logout({ api }));
|
|
1146
|
+
await (cmd === 'login' ? login({ api, spin: true }) : logout({ api }));
|
|
1054
1147
|
return 0;
|
|
1055
1148
|
}
|
|
1056
1149
|
case 'export':
|
|
@@ -1114,5 +1207,19 @@ function welcome(p) {
|
|
|
1114
1207
|
}
|
|
1115
1208
|
if (!process.argv.includes('--json'))
|
|
1116
1209
|
installPainter();
|
|
1210
|
+
// Started before the command and read after it, so a slow registry costs at most its 1.5 s cap.
|
|
1211
|
+
const update = shouldCheck({
|
|
1212
|
+
env: process.env,
|
|
1213
|
+
tty: !!process.stderr.isTTY && !!process.stdout.isTTY,
|
|
1214
|
+
argv: process.argv,
|
|
1215
|
+
}) && !process.argv.includes('__complete')
|
|
1216
|
+
? newerVersion({
|
|
1217
|
+
version: VERSION,
|
|
1218
|
+
cachePath: join(dirname(credentialsPath()), 'update-check.json'),
|
|
1219
|
+
})
|
|
1220
|
+
: undefined;
|
|
1117
1221
|
process.exitCode = await main(process.argv.slice(2));
|
|
1222
|
+
const latest = update && (await update);
|
|
1223
|
+
if (latest)
|
|
1224
|
+
console.error(updateNotice(VERSION, latest));
|
|
1118
1225
|
//# sourceMappingURL=sb.js.map
|