Items 工程能力
将 SSP UI Registry 的工程模板与工具引入项目
Items 是什么?
Items 提供可落地的工程模板、配置或工具函数,例如网络请求封装、状态管理脚手架、Biome 配置等。通过下载对应的 JSON 文件即可在项目中生成标准化的代码与配置。
基础流程
- 在文档站点找到目标能力,例如
make-api-request。 - 点击下载按钮或复制
RegistryDownload链接。 - 根据生成文件内的
target路径,将代码整合进项目结构。 - 安装
index.json中声明的 npm 依赖。
示例:make-api-request
- 打开文档
make-api-request查看能力说明。 - 下载能力:
npx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/make-api-request.jsonyarn dlx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/make-api-request.jsonpnpx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/make-api-request.jsonbunx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/make-api-request.json- 生成的文件会包含:
services/base.ts:核心请求封装services/example/index.template.ts:接口模板services/example/index.schema.ts:Zod 校验services/example/index.ts:示例 API 函数
- 安装依赖:
bun add zod- 在实际业务中使用:
import { makeApiRequest } from "@/services/base"
import { ProductApi } from "@/services/example/index.template"
export async function fetchProducts() {
const template = ProductApi.getProducts
return makeApiRequest(template, {
query: { page: 1, pageSize: 10 }
})
}示例:Biome 配置
- 访问
/docs/ssp/(item)/biome。 - 下载配置文件:
npx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/biome-rules.jsonyarn dlx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/biome-rules.jsonpnpx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/biome-rules.jsonbunx shadcn@latest add https://ssp-ui-registry-staging.sh3.agoralab.co/r/biome-rules.json- 将文件放在项目根目录,命名为
biome.json并按需调整。 - 在
package.json中添加脚本:
{
"scripts": {
"lint": "biome check --write",
"format": "biome format --write"
}
}验证与更新
- Items 的文件路径和目标路径记录在
index.json内,导入后请确认路径符合项目结构。 - 可使用
bun run registry:sync与bun run registry:build验证所有能力是否一致。 - 若进行本地修改,请保留注释和类型,便于后续与 Registry 同步。
下一步
- 结合 Hook 与 Items 建立完整的数据流,如
make-api-request+use-cancelable-swr。 - 若构建了新的工程模板或工具,可参考 贡献指南 提交回 Registry。