fragments-cloud-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFragments Cloud Setup
Fragments Cloud 配置流程
Set up design governance with Fragments Cloud -- from zero to running checks with optional CI.
在项目中通过Fragments Cloud设置设计治理——从零基础到运行检查,还可选择配置CI。
1. Detect project environment
1. 检测项目环境
- Confirm the project has a . If not, ask if the user wants to initialize one.
package.json - Detect the package manager from lock files:
- or
bun.lockb-> bunbun.lock - -> pnpm
pnpm-lock.yaml - -> yarn
yarn.lock - Otherwise -> npm
- Detect the framework (React, Next.js, Vue, Nuxt, Svelte, SvelteKit, Astro) from dependencies.
- Check if is already installed -- if so, note it and configure governance to work alongside it.
@fragments-sdk/ui
- 确认项目中存在。如果不存在,询问用户是否需要初始化一个。
package.json - 根据锁文件检测包管理器:
- 或
bun.lockb-> bunbun.lock - -> pnpm
pnpm-lock.yaml - -> yarn
yarn.lock - 其他情况 -> npm
- 根据依赖项检测所使用的框架(React、Next.js、Vue、Nuxt、Svelte、SvelteKit、Astro)。
- 检查是否已安装——如果已安装,记录该情况并配置治理工具以与其兼容。
@fragments-sdk/ui
2. Install the governance SDK and CLI
2. 安装治理SDK与CLI
First check if these are already available:
- In a monorepo with workspace dependencies (look for or
"workspace:*"in"workspace:^"), the packages may already be linked. Check ifpackage.jsonand@fragments-sdk/governappear in@fragments-sdk/cliordependencies. If they're workspace deps, skip the install step.devDependencies - Also check if a or
pnpm-workspace.yamlfield exists in a parent directory -- if so, you're in a monorepo.workspaces
If not already installed:
bash
<package-manager> add @fragments-sdk/govern @fragments-sdk/cliThe package provides the governance engine. The package provides the binary used to run checks.
governclifragments首先检查这些工具是否已可用:
- 在包含工作区依赖的monorepo项目中(查看中的
package.json或"workspace:*"),相关包可能已被链接。检查"workspace:^"和@fragments-sdk/govern是否出现在@fragments-sdk/cli或dependencies中。如果它们是工作区依赖,跳过安装步骤。devDependencies - 同时检查父目录中是否存在或
pnpm-workspace.yaml字段——如果存在,则当前项目为monorepo。workspaces
如果尚未安装:
bash
<package-manager> add @fragments-sdk/govern @fragments-sdk/cligovernclifragments3. Configure the API key
3. 配置API密钥
IMPORTANT: Never ask the user to paste their API key into the chat or accept it as an argument. Never write secrets directly.
Instead, guide the user to set it themselves:
-
Tell the user to add their API key to(or
.env) manually:.env.localFRAGMENTS_API_KEY=fc_your_key_hereSay: "Add your Fragments Cloud API key to. You can find it in the onboarding dashboard or Settings > API Keys.".env -
Ensureand
.envare in.env.local. Create.gitignoreif needed..gitignore -
Addto
.agents/if not already present (this is where installed skills live)..gitignore -
After the user confirms the key is set, verify it exists by checking thatcontains a
.envline (do NOT read or output the actual value).FRAGMENTS_API_KEY
重要提示:切勿要求用户将其API密钥粘贴到聊天框中或作为参数提供。切勿直接写入机密信息。
相反,引导用户自行设置:
-
告知用户手动将其API密钥添加到(或
.env)文件中:.env.localFRAGMENTS_API_KEY=fc_your_key_here说明:"将你的Fragments Cloud API密钥添加到文件中。你可以在入门仪表板或设置>API密钥页面找到它。".env -
确保和
.env已添加到.env.local中。如果需要,创建.gitignore文件。.gitignore -
如果尚未在
.agents/中,将其添加进去(这是已安装技能的存储目录)。.gitignore -
在用户确认密钥已设置后,通过检查文件中是否包含
.env行来验证其存在(切勿读取或输出实际密钥值)。FRAGMENTS_API_KEY
4. Create governance config
4. 创建治理配置文件
Create in the project root. Adapt the glob to the detected framework:
fragments.config.tsinputts
import { defineConfig } from '@fragments-sdk/govern';
export default defineConfig({
cloud: true,
checks: ['accessibility', 'consistency', 'responsive'],
input: './src/**/*.{tsx,jsx}',
});Framework-specific patterns:
input- Next.js App Router:
['./app/**/*.{tsx,jsx}', './components/**/*.{tsx,jsx}'] - Next.js Pages:
['./pages/**/*.{tsx,jsx}', './components/**/*.{tsx,jsx}'] - Vue / Nuxt:
['./**/*.vue'] - Svelte / SvelteKit:
['./src/**/*.svelte'] - Astro:
['./src/**/*.{astro,tsx,jsx}']
在项目根目录创建文件。根据检测到的框架调整通配符:
fragments.config.tsinputts
import { defineConfig } from '@fragments-sdk/govern';
export default defineConfig({
cloud: true,
checks: ['accessibility', 'consistency', 'responsive'],
input: './src/**/*.{tsx,jsx}',
});各框架对应的模式:
input- Next.js App Router:
['./app/**/*.{tsx,jsx}', './components/**/*.{tsx,jsx}'] - Next.js Pages:
['./pages/**/*.{tsx,jsx}', './components/**/*.{tsx,jsx}'] - Vue / Nuxt:
['./**/*.vue'] - Svelte / SvelteKit:
['./src/**/*.svelte'] - Astro:
['./src/**/*.{astro,tsx,jsx}']
5. Run the first check
5. 运行首次检查
bash
npx fragments govern check --cloudShow the output. If there are violations, briefly explain what they mean and how to fix them.
bash
npx fragments govern check --cloud展示检查结果。如果存在违规项,简要说明其含义及修复方法。
6. Offer CI/CD setup
6. 提供CI/CD配置选项
Ask: "Want to add Fragments checks to your CI pipeline? (GitHub Actions / GitLab CI / skip)"
询问:"是否要将Fragments检查添加到你的CI流水线中?(GitHub Actions / GitLab CI / 跳过)"
GitHub Actions
GitHub Actions
Create :
.github/workflows/fragments-check.ymlyaml
name: Fragments Design Check
on:
pull_request:
branches: [main, master]
permissions:
contents: read
pull-requests: write
jobs:
design-check:
name: Design Governance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- name: Run Fragments checks
run: npx fragments govern check --cloud --format github
env:
FRAGMENTS_API_KEY: ${{ secrets.FRAGMENTS_API_KEY }}创建文件:
.github/workflows/fragments-check.ymlyaml
name: Fragments Design Check
on:
pull_request:
branches: [main, master]
permissions:
contents: read
pull-requests: write
jobs:
design-check:
name: Design Governance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- name: Run Fragments checks
run: npx fragments govern check --cloud --format github
env:
FRAGMENTS_API_KEY: ${{ secrets.FRAGMENTS_API_KEY }}GitLab CI
GitLab CI
Add a job to :
fragments-check.gitlab-ci.ymlyaml
fragments-check:
stage: test
image: node:20
script:
- npm ci
- npx fragments govern check --cloud
variables:
FRAGMENTS_API_KEY: $FRAGMENTS_API_KEY
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"After creating the CI config, remind the user to add as a secret in their CI provider settings.
FRAGMENTS_API_KEY在中添加任务:
.gitlab-ci.ymlfragments-checkyaml
fragments-check:
stage: test
image: node:20
script:
- npm ci
- npx fragments govern check --cloud
variables:
FRAGMENTS_API_KEY: $FRAGMENTS_API_KEY
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"创建CI配置后,提醒用户在其CI提供商的设置中添加作为机密信息。
FRAGMENTS_API_KEY7. Confirm completion
7. 确认配置完成
Summarize what was done:
- and
@fragments-sdk/governinstalled@fragments-sdk/cli - API key configured in (remind them not to commit it)
.env - Governance config created at
fragments.config.ts - First check ran -- results visible in Fragments Cloud dashboard
- CI workflow created (if chosen)
Mention related skills:
- to run checks, review staged changes, and fix violations
/fragments-govern - to create custom design rules
/fragments-policy - If is not installed, mention
@fragments-sdk/uito add the component library/fragments-ui-setup
总结已完成的操作:
- 已安装和
@fragments-sdk/govern@fragments-sdk/cli - 已在中配置API密钥(提醒用户不要提交该文件)
.env - 已在创建治理配置
fragments.config.ts - 已运行首次检查——结果可在Fragments Cloud仪表板查看
- 已创建CI工作流(如果用户选择了该选项)
提及相关技能:
- :运行检查、查看暂存变更并修复违规项
/fragments-govern - :创建自定义设计规则
/fragments-policy - 如果尚未安装,提及
@fragments-sdk/ui以添加组件库/fragments-ui-setup