turbo-add
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdding a New Theme to Turbo-Themes
向Turbo-Themes添加新主题
Turbo-themes uses a token-based theming system: theme definitions in
define color tokens, collects them, the
build generates CSS from tokens, the theme-selector package provides UI components,
and the site plus example projects consume the themes.
src/themes/packs/src/themes/registry.tsTurbo-themes 采用基于Token的主题系统: 中的主题定义用于定义颜色Token, 收集这些Token,构建过程从Token生成CSS,theme-selector包提供UI组件,网站及示例项目则使用这些主题。
src/themes/packs/src/themes/registry.tsRelated Skills
相关技能
- : TypeScript coding standards
stand-ts - : semantic commit format when committing changes
commit - : use after implementation to verify completeness
turbo-verify
- : TypeScript编码规范
stand-ts - : 提交更改时使用语义化提交格式
commit - : 实现完成后用于验证完整性
turbo-verify
How to Implement: Copy a Reference, Discover the Touchpoints
实现方法:参考现有主题,梳理所有关联点
Do NOT write theme packs from a template or trust a memorized file list. Instead:
-
Pick a reference theme and mirror its files:
- Synced theme with npm package: +
src/themes/packs/catppuccin.synced.tsscripts/sync-catppuccin.mjs - Synced theme:
src/themes/packs/rose-pine.synced.ts - Manual theme with license/source metadata:
src/themes/packs/nord.ts - Manual theme: ,
src/themes/packs/bulma.tssrc/themes/packs/dracula.ts
- Synced theme with npm package:
-
Discover every touchpoint by grepping for an existing theme's variant id (pick one from, e.g. a rose-pine or catppuccin variant):
src/themes/registry.tsbash# Every file that mentions an existing variant — the new theme needs the # same touchpoints (packs, token JSON, icons, site data, examples, tests) rg -l 'rose-pine-moon' --hidden -g '!node_modules' -g '!dist' # Family-level touchpoints (type unions, family maps, vendor metadata) rg -l 'rose-pine' src/ packages/ apps/ scripts/ -
Also check root-level registrations the greps can miss because they do not mention variant ids: thescript wiring in
theme:syncand size limits inpackage.json.test/integration/bundle-size.test.ts -
Verify with the current repo, not this skill: if a file in the grep output is generated (check for a "generated" header or a/
buildscript that writes it), update the source and rebuild instead of hand-editing.theme:sync
请勿从模板编写主题包或依赖记忆的文件列表。请按以下步骤操作:
-
选择一个参考主题并复制其文件结构:
- 与npm包同步的主题:+
src/themes/packs/catppuccin.synced.tsscripts/sync-catppuccin.mjs - 同步主题:
src/themes/packs/rose-pine.synced.ts - 带许可证/源元数据的手动主题:
src/themes/packs/nord.ts - 手动主题:、
src/themes/packs/bulma.tssrc/themes/packs/dracula.ts
- 与npm包同步的主题:
-
通过搜索现有主题的变体ID梳理所有关联点(从中选择一个,例如rose-pine或catppuccin的变体):
src/themes/registry.tsbash# 所有提及现有变体的文件——新主题需要相同的关联点(包、Token JSON、图标、站点数据、示例、测试) rg -l 'rose-pine-moon' --hidden -g '!node_modules' -g '!dist' # 主题系列级别的关联点(类型联合、系列映射、供应商元数据) rg -l 'rose-pine' src/ packages/ apps/ scripts/ -
同时检查根目录下的注册项,这些可能无法通过搜索找到,因为它们没有提及变体ID:中的
package.json脚本配置,以及theme:sync中的大小限制。test/integration/bundle-size.test.ts -
请以当前仓库为准,而非本技能文档:如果搜索结果中的文件是生成的(检查是否有“generated”标头或写入该文件的/
build脚本),请更新源文件并重新构建,而非手动编辑。theme:sync
Files to Create
需要创建的文件
text
scripts/sync-<theme>.mjs # Optional: sync from npm package
src/themes/packs/<theme>.synced.ts # Theme definitions (or <theme>.ts for manual)
schema/tokens/themes/<theme-id>.tokens.json # W3C Design Token file, one per variant
assets/img/<theme-id>.png # Theme icon, one per variant- Theme pack: copy the structure of the reference pack — ,
id,name,homepage(spdx/url/copyright),license(package/version/repository for synced themes), andsourcewith complete token groups (flavors,background,text,brand,state,border,accent,typography). Do NOT addcontentto flavors — icons resolve viaiconUrlin theme-mapper.ts.VENDOR_ICON_MAP - W3C token files: mirror an existing file in —
schema/tokens/themes//$valueformat,$typepointing to$schema.../../turbo-themes.schema.json#/$defs/ThemeFile - Icons: PNG per variant (typically 24x24), visually distinct for light/dark.
text
scripts/sync-<theme>.mjs # 可选:从npm包同步
src/themes/packs/<theme>.synced.ts # 主题定义(手动主题则用<theme>.ts)
schema/tokens/themes/<theme-id>.tokens.json # W3C设计Token文件,每个变体对应一个
assets/img/<theme-id>.png # 主题图标,每个变体对应一个- 主题包:复制参考包的结构——、
id、name、homepage(spdx/url/copyright)、license(同步主题的包/版本/仓库),以及包含完整Token组(source、background、text、brand、state、border、accent、typography)的content。请勿向flavors添加flavors——图标通过theme-mapper.ts中的iconUrl解析。VENDOR_ICON_MAP - W3C Token文件:复制中的现有文件格式——
schema/tokens/themes//$value格式,$type指向$schema。../../turbo-themes.schema.json#/$defs/ThemeFile - 图标:每个变体对应一张PNG图片(通常为24x24),亮色/暗色主题需视觉区分。
Sync Script Best Practices (if the theme has an npm palette package)
同步脚本最佳实践(若主题有npm调色板包)
Copy and adapt. Key rules:
scripts/sync-catppuccin.mjs- Output path must be — the registry imports from there, NOT
src/themes/packs/.packages/core/src/themes/packs/ - Read the version from and populate
node_modules/<pkg>/package.jsonfor traceability.source.version - Normalize hex colors — source packages include inconsistently.
# - Deterministic ordering — sort variant keys for reproducible builds.
- Add the script to in package.json — the build pipeline must generate the file before TypeScript compilation.
theme:sync
复制并调整。关键规则:
scripts/sync-catppuccin.mjs- 输出路径必须为——注册表从此处导入,而非
src/themes/packs/。packages/core/src/themes/packs/ - 从读取版本并填充
node_modules/<pkg>/package.json以保证可追溯性。source.version - 标准化十六进制颜色——源包中的使用不一致。
# - 确定排序——对变体键排序以保证构建可复现。
- 将脚本添加到package.json的中——构建管道必须在TypeScript编译前生成该文件。
theme:sync
Files to Update
需要更新的文件
Enumerate with the discovery greps above; the recurring touchpoints are:
- — import the pack and spread its flavors into
src/themes/registry.tsallFlavors - — add to the
packages/theme-selector/src/types.tstype unionThemeFamily - — add to
packages/theme-selector/src/constants.ts(name + description)THEME_FAMILIES - — add to
packages/theme-selector/src/theme-mapper.ts,VENDOR_FAMILY_MAP(string, orVENDOR_ICON_MAPAppearanceIcons object when the family has both appearances), and{light, dark}per variantFLAVOR_DESCRIPTIONS - — single source of truth for the site: add to
apps/site/src/data/theme-meta.ts,themeGroups(short dropdown labels), andthemeNames.themeIconsis derived automatically;validThemeIdsandBaseLayout.astroare data-driven from this file — no direct edits there.ThemeDropdown.astro - — sidebar family section + JS
apps/site/src/pages/themes.astrothemeNames - — hero preview strip buttons
apps/site/src/pages/index.astro - — add to
scripts/prepare-style-dictionary.mjs(name + homepage)vendorMeta - — increase budget only if needed
test/integration/bundle-size.test.ts - — append sync script to
package.json(if using one)theme:sync
通过上述搜索命令列出所有文件;常见的关联点包括:
- ——导入主题包并将其
src/themes/registry.ts展开到flavors中allFlavors - ——添加到
packages/theme-selector/src/types.ts类型联合中ThemeFamily - ——添加到
packages/theme-selector/src/constants.ts(名称+描述)THEME_FAMILIES - ——添加到
packages/theme-selector/src/theme-mapper.ts、VENDOR_FAMILY_MAP(字符串,或当主题系列包含两种外观时使用VENDOR_ICON_MAPAppearanceIcons对象),以及每个变体对应的{light, dark}FLAVOR_DESCRIPTIONS - ——站点的唯一数据源:添加到
apps/site/src/data/theme-meta.ts、themeGroups(下拉菜单短标签)和themeNames。themeIcons会自动推导;validThemeIds和BaseLayout.astro从此文件获取数据——请勿直接编辑这些文件。ThemeDropdown.astro - ——侧边栏主题系列章节+JS
apps/site/src/pages/themes.astrothemeNames - ——首页预览条按钮
apps/site/src/pages/index.astro - ——添加到
scripts/prepare-style-dictionary.mjs(名称+主页)vendorMeta - ——仅在必要时增加预算
test/integration/bundle-size.test.ts - ——将同步脚本追加到
package.json(若使用同步脚本)theme:sync
Example projects
示例项目
Example files hardcode theme lists; discover the current set instead of assuming:
bash
undefined示例文件中硬编码了主题列表;请通过搜索确定当前集合,而非假设:
bash
undefinedWeb examples with hardcoded theme arrays / dropdowns
包含硬编码主题数组/下拉菜单的Web示例
rg -l 'VALID_THEMES|LIGHT_THEMES|lightThemes' examples/
rg -l 'THEMES' examples/stackblitz/react examples/stackblitz/vue
rg -l 'VALID_THEMES|LIGHT_THEMES|lightThemes' examples/
rg -l 'THEMES' examples/stackblitz/react examples/stackblitz/vue
Swift example touchpoints
Swift示例关联点
rg -l 'ThemeId|ThemeDefinition' examples/swift-swiftui/
In each hit, add the new variants everywhere an existing variant appears:
`<select>` options, `VALID_THEMES`/`LIGHT_THEMES`/`THEMES` arrays, Swift
`ThemeId.swift` enum cases, `ThemeRegistry.swift` `ThemeDefinition` palettes, and
`ThemeRegistryTests.swift` counts/labels. Files that import from
`@lgtm-hq/turbo-themes-core/tokens` (React hooks, Vue composables, Bootstrap
main.ts) auto-update — skip any file where the grep hit is an import, not a
hardcoded list.rg -l 'ThemeId|ThemeDefinition' examples/swift-swiftui/
在每个搜索结果中,在现有变体出现的所有位置添加新变体:`<select>`选项、`VALID_THEMES`/`LIGHT_THEMES`/`THEMES`数组、Swift`ThemeId.swift`枚举案例、`ThemeRegistry.swift`中的`ThemeDefinition`调色板,以及`ThemeRegistryTests.swift`中的计数/标签。从`@lgtm-hq/turbo-themes-core/tokens`导入的文件(React hooks、Vue组合式函数、Bootstrap main.ts)会自动更新——跳过任何搜索结果为导入语句而非硬编码列表的文件。Naming Conventions
命名规范
- Theme ID: lowercase with hyphens (e.g., )
rose-pine-moon - Variant label (token field): full display name including family (e.g., "Gruvbox Dark Hard") — match existing
labelfiles.tokens.json - Short label (in theme-meta.ts): condensed dropdown label (e.g., "Dark Hard", "Moon")
themeNames - Vendor / family: the theme family identifier (e.g., )
rose-pine
- 主题ID:小写并使用连字符(例如:)
rose-pine-moon - 变体标签(Token的字段):包含主题系列的完整显示名称(例如:"Gruvbox Dark Hard")——与现有
label文件保持一致.tokens.json - 短标签(theme-meta.ts中的):精简的下拉菜单标签(例如:"Dark Hard"、"Moon")
themeNames - 供应商/系列:主题系列标识符(例如:)
rose-pine
Build and Test
构建与测试
bash
uv run lintro chk # Lint
bun run build # Core build
bun run examples:build # Example projects
bun run test # Unit tests
bun run examples:test # Example E2E tests
cd apps/site && bun run build # Site build
cd apps/site && bun run dev # Visual checkTip: the skill runs the full pipeline automatically.
turbo-testbash
uv run lintro chk # 代码检查
bun run build # 核心构建
bun run examples:build # 示例项目构建
bun run test # 单元测试
bun run examples:test # 示例端到端测试
cd apps/site && bun run build # 站点构建
cd apps/site && bun run dev # 视觉检查提示: 技能会自动运行完整流程。
turbo-testCommon Gotchas
常见陷阱
- Theme reverts on navigation / wrong label / missing icon: variants missing
from /
themeGroups/themeNamesinthemeIcons(the site is data-driven from this file — do not edit BaseLayout.astro for these)apps/site/src/data/theme-meta.ts - Theme not in dropdown / wrong group: missing or wrong
VENDOR_FAMILY_MAP - Tests fail on theme order: use attribute lookups, not array indices
data-theme-id - Bundle size test fails: increase the budget in bundle-size.test.ts
- CI : sync script missing from
Cannot find module './packs/<theme>.synced.js'in package.jsontheme:sync - tokens.json shows wrong name/homepage: missing from in prepare-style-dictionary.mjs
vendorMeta - Generated assets outdated: run and commit the generated files (theme-selector bundles, tokens.json in core/python/swift)
bun run build - Type changes: if adding interfaces, update BOTH AND
src/themes/types.ts— separate files kept in syncpackages/core/src/themes/types.ts - Visual regression fails after hero changes: snapshots are generated on
Linux CI — run the workflow
maintenance-generate-snapshots.yml - Missing from examples: re-run the example discovery greps and diff the new theme's hits against an existing theme's hits
- 导航时主题还原/标签错误/图标缺失:变体未添加到中的
apps/site/src/data/theme-meta.ts/themeGroups/themeNames(站点从此文件获取数据——请勿为这些内容编辑BaseLayout.astro)themeIcons - 主题不在下拉菜单中/分组错误:缺失或错误
VENDOR_FAMILY_MAP - 主题顺序导致测试失败:使用属性查找,而非数组索引
data-theme-id - 包大小测试失败:在bundle-size.test.ts中增加预算
- CI报错:package.json的
Cannot find module './packs/<theme>.synced.js'中缺少同步脚本theme:sync - tokens.json显示错误的名称/主页:prepare-style-dictionary.mjs中的缺失
vendorMeta - 生成的资源过期:运行并提交生成的文件(theme-selector包、core/python/swift中的tokens.json)
bun run build - 类型变更:若添加接口,请同时更新和
src/themes/types.ts——这两个文件需保持同步packages/core/src/themes/types.ts - 首页修改后视觉回归测试失败:快照在Linux CI上生成——运行工作流
maintenance-generate-snapshots.yml - 未添加到示例中:重新运行示例搜索命令,并将新主题的搜索结果与现有主题的结果对比