@anyday/sanity-workspace-manager

中文文档
0.8.0发布于 2026/11/09UNLICENSEDES Module近 30 天下载 1728

Generates and checks a site repo's workspace-manager.json for the Anyday workspace manager

原始使用文档
文档目录14 节
  1. Requirements
  2. Quick start
  3. The two files
  4. generate
  5. What it reads
  6. Without access to the live project
  7. Starter pages
  8. Moving from a hand-made manifest
  9. check
  10. register
  11. Signing in
  12. Troubleshooting
  13. How it fits together
  14. Developing and publishing

@anyday/sanity-workspace-manager

The command-line tool for Anyday's Sanity workspace manager. The workspace manager creates a new Sanity workspace for a site in a few clicks: the project, its dataset, starter or copied content, the brand, the central Studio entry and the Vercel site. It holds no code for any one project. Each kind of site (a project type) is described instead by a workspace-manager.json manifest that lives in that site's repo.

This tool makes and saves that manifest, the way sanity typegen generate makes types:

  • generate writes workspace-manager.json from the repo's schema, the live Sanity project and workspace-manager.config.json, which holds your answers. Change the schema, run it again.
  • check fails when the manifest is out of date with the schema or was edited by hand.
  • register saves the manifest to the workspace manager, which then offers the project type in the Workspaces app.

Requirements

  • Node.js 20 or later.
  • A Sanity login for generate and register: run npx sanity login once, or set SANITY_AUTH_TOKEN. check needs none.
  • For register, the Administrator role in the manifest's Sanity organisation.

Quick start

From the root of the site repo:

# 1. Export the Studio's schema (writes sanity.schema.json)
cd studio && npx sanity schema extract && cd ..

# 2. Answer a few questions and pick starter pages; writes the config and the manifest
npx @anyday/sanity-workspace-manager generate

# 3. Review workspace-manager.config.json, commit both files next to the schema

# 4. Save it to the workspace manager
npx @anyday/sanity-workspace-manager register --api https://anyday-workspace-manager-sanity-api.vercel.app

After a schema change: extract the schema, run generate, commit, register.

The two files

FileHoldsEdited by
workspace-manager.config.jsonYour answers: ids, copy sections, colour role descriptions, starter pages, ...You
workspace-manager.jsonEverything else: field mappings, theme defaults, starter page contentgenerate

Never edit workspace-manager.json: its $generated line holds a hash, and check fails after a hand edit. Change the config and run generate instead. The config has a JSON Schema, so your editor completes and checks it once the package is installed.

Add this line to the site repo's .gitattributes, so GitHub marks the manifest as generated and collapses its diff in PRs; generate reminds you until it's there:

workspace-manager.json linguist-generated=true
Config fieldHolds
idPermanent: jobs store it and it prefixes each site's Vercel project
titleThe name shown in the Workspaces app
organizationIdThe Sanity organisation new workspaces are created in
vercelTeamIdThe client's own Vercel team; left out for Anyday's
siteThe GitHub repo and branch each new site deploys from
studioOriginsThe Studios that open new workspaces, incl. a site's /studio; picked from the live project on first run
sectionsEach content type with its label in the Copy picker, or false to leave it out
colorRolesEach theme colour with a short description of where it's used, shown to whoever sets up a brand
themeFilesTheme fields with uploaded files (fonts) to copy into new sites; fonts are often licensed per brand
starterWhat Start fresh writes: picked live pages, or [] for one empty home page (see below)
sharedFor a client whose sites share one project: its projectId, siteIdField, slugPrefix, and the sampleSiteId whose theme and pages generate reads
siteEnvEnv var names the site reads when .env.example doesn't name them, siteId for a shared type, fixed templated values, and linkShared team-shared variables to link
site.rootDirectory, site.vercelProjectNameThe site's folder in the repo, and a template for its Vercel project name (e.g. {{siteId}})
...singletons, homePage, settingsFields: guessed from the schema on the first run, asked when they break

generate

npx @anyday/sanity-workspace-manager generate [dir] [options]

dir is the site repo, and defaults to the current folder. The first run asks who the project type is for, each with a suggestion you accept with Enter, then lists the live site's pages to pick starter pages from. Answers go in the config. Later runs reuse them and ask only about what changed in the schema:

generalSettings.logo is gone. Which field is the logo? [brandLogo/favicon/none] (none):
Copy section mediaMention is gone from the schema. Was it renamed? [pressMention/no] (no):
New content type event: offer it as a copy section? [y/n] (y):

A renamed field reads as one removed and one added, so generate asks rather than guesses.

OptionDoes
--yesTakes the suggested answers without asking, and lists them
--offlineDoesn't read the live project: keeps the live values already in the manifest
--diffShows what would change in both files, and writes nothing
--ask-againAsks the saved questions again, e.g. to change copy sections or pick starter pages
--project <id>The Sanity project new workspaces copy their schema from
--org <id>The Sanity organisation new workspaces are created in
--vercel-team <id>The client's own Vercel team for the sites
--studio <origin>The Studio that opens new workspaces, e.g. https://acme.sanity.studio
--dataset <name>The dataset live values are read from (default production)
--starter <pages>Starter pages without the list: home, slugs or ids, comma-separated

What it reads

SourceUsed for
git remote and default branchsite, the suggested id and name
.env.example, names onlysiteEnv, the variables each new site needs (*_WORKSPACES_API_URL if the site has one)
sanity.schema.jsoncopy sections, singletons, home page, language documents, settings fields, colours and fonts
the live projectorganisation, Studios and CORS origins to pick from, theme colours and defaults, fonts named in themeFiles, starter pages

sanity.schema.json is looked for in the repo root, frontend, web, site, studio, apps and each folder in apps.

Without access to the live project

generate says first why it can't read the live project, and what to do:

SituationWhat it printsFix
Not signed inNot signed in to Sanity: run npx sanity login to read live valuesRun npx sanity login
Expired or bad sessionYour Sanity session is missing or expired: run npx sanity login …Run npx sanity login; if SANITY_AUTH_TOKEN is set, it wins over the login, so fix or unset it
No accessYour Sanity account can't read project <id>: ask one of its Administrators …Ask an Administrator of that project to add you (Viewer is enough)
Anything elseCouldn't read the live project <id>: <reason>Follow the reason, e.g. a wrong --project or --dataset

It then offers to continue from the schema only. Values only the live project holds (colours, fonts, starter pages) are kept from the existing manifest, and the last line says so. On a first run they start as placeholders: black colours, system fonts and one empty home page, and register asks before saving them. Sign in and run generate again to read the live values.

Starter pages

Starter pages are what a new workspace starts with when it doesn't copy another workspace. They always come from the live site, so you update them in the Studio, never by hand in a file. The first run lists the live pages in the home page's language, home first:

Pages of the live site:
  1. Home (/home)  ← home
  2. About us (/about-us)
  3. Contact (/contact)
Starter pages, by number (e.g. 1,3; Enter for one empty home page):

The config saves only your pick, e.g. "starter": ["home", "about-us"], and every run reads those pages again. home means whichever page the settings mark as the home page; anything else is a slug or document id. [] means one empty home page.

To change the starter pages later, run generate --ask-again and pick again from the list, or edit the config's starter and run generate.

A new workspace has only its starter pages, so generate removes each link to another document (a doctor card, a button to another page) and lists what it removed. Fields the schema no longer has are dropped too. Starter pages get {{siteName}} and {{language}} where the source site's name and language were.

Moving from a hand-made manifest

Run generate in a repo that has a workspace-manager.json and no config: it moves every choice the manifest holds, including copy section labels, colour descriptions and fonts, into the config. It then lists the live pages to pick starter pages from; until you pick, it keeps the manifest's existing starter pages.

check

npx @anyday/sanity-workspace-manager check [dir]

Read-only. Fails, naming each difference, when:

  • the schema changed in a way the manifest uses (a renamed or removed field, a new content type),
  • workspace-manager.json was edited by hand, or
  • the starter pages have fields the schema no longer has.

Only changes to fields the manifest uses matter: the logo, site name, theme colours and fonts, home page, language fields, content types, and the fields on starter pages. check reads only the repo, so it can run in CI without signing in.

register

npx @anyday/sanity-workspace-manager register [dir] --api <url>

Checks workspace-manager.json in dir (default: the current folder) and saves it to the workspace manager. The live API is https://anyday-workspace-manager-sanity-api.vercel.app; set WORKSPACE_MANAGER_API_URL to skip --api.

  • You must be an Administrator of the manifest's organizationId.
  • Registering again replaces the saved copy for that id, so a changed manifest needs no delete first.
  • It asks before saving placeholder colours or fonts; --yes skips the question.
  • --dry-run checks the manifest without saving it.
  • It warns when the manifest names a Vercel team the API has no token for yet. A client's own team needs its token on the API as VERCEL_TOKEN_<team id> (a secret, added on Vercel by Anyday).

Signing in

All commands use SANITY_AUTH_TOKEN when it is set, and otherwise the token npx sanity login saved. Use your own login: the workspace manager refuses robot tokens for register, so that every project type traces back to a person. If a robot token is exported in your shell (for example for a Studio deploy), unset SANITY_AUTH_TOKEN before registering.

Troubleshooting

MessageFix
No sanity.schema.jsonRun npx sanity schema extract in the Studio folder
workspace-manager.json is out of dateRun generate and commit both files
was edited by handPut the change in the config, then run generate
No page with the slug or id "…"Fix the config's starter, or run generate --ask-again to pick again
No GitHub remote foundAdd an origin remote, or set site.repo in the config
Not signed in to SanityRun npx sanity login
Your Sanity session is missing or expiredRun npx sanity login, or fix or unset SANITY_AUTH_TOKEN
Your Sanity account can't read project …Ask an Administrator of that project to add you (Viewer is enough)
Couldn't read the live project …Follow the reason, e.g. a wrong --project or --dataset
Pass --api <url> or set WORKSPACE_MANAGER_API_URLAdd --api https://anyday-workspace-manager-sanity-api.vercel.app
Use your own Sanity login, not a robot tokenunset SANITY_AUTH_TOKEN and use npx sanity login
Register only as an Administrator of organisation …Ask an Administrator of that organisation to run register

How it fits together

The full design, including every manifest field, is in docs/project-config.md, and how generate works in docs/manifest-generate.md (Anyday's GitHub organisation only).

Developing and publishing

From a clone of the workspace manager repo, run the CLI without npm: npm run cli -- generate ../my-site. npm run build bundles src/cli.ts, with the manifest code it borrows from the API, into dist/cli.mjs; only @sanity/client and ajv stay dependencies.

Publish from main: bump version, then run npm publish --workspace=@anyday/sanity-workspace-manager --access public --auth-type=web from the repo root. It builds and tests first; the web sign-in covers npm's two-factor check, and the release then waits for approval on npmjs.com.

版本与发布记录

@anyday/sanity-workspace-manager 共发布 10 个版本,首次发布于 2026/10/20;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.8.0latest2026/11/09今天
0.7.12026/10/2417 天前
0.7.02026/10/2417 天前
0.6.02026/10/2218 天前
0.5.02026/10/2020 天前
0.4.02026/10/2020 天前

关于 @anyday/sanity-workspace-manager 的常见问题

@anyday/sanity-workspace-manager 是什么?

Generates and checks a site repo's workspace-manager.json for the Anyday workspace manager

如何安装 @anyday/sanity-workspace-manager?

在项目目录运行 npm install @anyday/sanity-workspace-manager,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 sanity-workspace-manager,可以用 npx sanity-workspace-manager 直接运行。

@anyday/sanity-workspace-manager 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/anyday__sanity-workspace-manager 是否存在。

@anyday/sanity-workspace-manager 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@anyday/sanity-workspace-manager 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anyday/sanity-workspace-manager 可以商用吗?

@anyday/sanity-workspace-manager 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@anyday/sanity-workspace-manager 的下载量有多少?

根据 npm 官方下载统计,@anyday/sanity-workspace-manager 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,728 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anyday/sanity-workspace-manager 还在维护吗?

最新版本 0.8.0 发布于 2026/11/09(今天);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/10/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。