feat(S6-P21): 组件族参数化(13族/44成员/导航族15文件同源/79→48概念组件)
【本次核心 · S6-P21】 - 族层数据:families.json + 44 份契约注入 family/familyRole/familyParams; data.json / data.js / site/details 同步。13 族 / 44 成员 / 35 独立 → 概念组件 79→48。 - 79 个 slug 全保留、集合逐一不变(铁律 5 对外承诺未破);frameworks 仍 395 文件、薄壳仍 79。 - 归族判据为契约中可核对字段(semanticTypeCandidates 重叠 / anatomy 为同一骨架子集 / 变体维度同构 / doNotInvent 显式从属声明),每族 mergeBasis 写明依据,不按名字猜。 - 实现层合并(导航族端到端切片):tools/gen-family-impl.mjs 从 5 端模板生成 TopMenu / SideMenu / MixedNavigation 共 15 文件,参数 direction=top|side|mixed; 三份 CSS md5 完全相同 = 一份样式表服务三个组件。 - 新增 tools/gen-families.mjs、tools/gen-family-impl.mjs、tools/verify-families.mjs、 tools/lib/family-model.mjs、tools/lib/family-impl/nav-menu/*.tpl。 【同时清掉此前已完成但未提交的批次】 生成物(data.json / data.js / site/sources / site/components 薄壳 / sitemap.xml / tests 报告) 跨阶段交织,无法拆成互相自洽的多个提交,故按既有批量风格合并提交: - Package:三端可 import(S5-P18)+ 发布到私有 npm 源 - Docs site:导航语言改下拉(S5-P19)、详情页代码块默认展开、中英切换完整性 - Security:生产部署链审计修复(2026-09-19)+ 线上部署 - Theme modes 日间/夜间/自动;S1-P4 data.js 瘦身;S2-P5 暗色;S2-P6 跨端一致性; S2-P7 行为断言;S2-P9 FAQ;S3-P8 RTL;S3-P9 契约缺口解释层;S4-P12 发布流程 - 补入 tools/pack-deploy.mjs、run-site-smoke.mjs、verify-*.mjs,.dockerignore、 安全审计修复与待决策项.md 【验收】 - node tools/verify-families.mjs → OK: 族层端到端一致(13 族 / 44 成员 / 79 组件不变 / 395 文件不变) - node tools/verify-cross-platform.mjs → 79/79 identical(HEAD 基线 high 44) - node tools/run-regression.mjs → 100%(79/79 页,1017/1017 断言,N/A 34),连跑 8 次一致,0 超时 - 逐页实测:topmenu / sidemenu / mixednavigation 各 13/13,帧内 direction 参数正确,0 JS 错误 - 零运行时依赖 OK;build-site.ps1 ASCII-only OK 【未纳入】site/components/<slug>/ 平台薄壳 316 个 —— 历史从未跟踪且属构建产物,保持现状。
This commit is contained in:
+131
-11
@@ -27,6 +27,51 @@ $catMap['system'] = @('themeswitcher','layoutswitcher','densityswitcher','sho
|
||||
$slugCat = @{}
|
||||
foreach ($ck in $catMap.Keys) { foreach ($s in $catMap[$ck]) { $slugCat[$s] = $ck } }
|
||||
|
||||
# ---------------- component families (variant parameterization) ----------------
|
||||
# families.json is generated by tools/gen-families.mjs from tools/lib/family-model.mjs.
|
||||
# A family expresses several same-origin components as ONE base component plus
|
||||
# parameter values. Component identity (slug) never changes: data.json still lists
|
||||
# all 79 components; the family layer is additive metadata on top of them.
|
||||
#
|
||||
# PS 5.1 notes (both are real traps, do not "simplify"):
|
||||
# 1. ConvertFrom-Json yields PSCustomObject, which Json-Value below does NOT
|
||||
# understand -- it would fall through to Json-Escape and emit "@{...}".
|
||||
# 2. An empty array returned from a function gets unrolled to $null. So arrays are
|
||||
# built and assigned to hashtable slots INSIDE the helper, never returned.
|
||||
$famDoc = $null
|
||||
$famRaw = ''
|
||||
$famOf = @{}
|
||||
$famPath = "$lib/families.json"
|
||||
if (Test-Path $famPath) {
|
||||
$famRaw = (Get-Content $famPath -Raw -Encoding UTF8).Trim()
|
||||
$famDoc = $famRaw | ConvertFrom-Json
|
||||
foreach ($f in $famDoc.families) {
|
||||
foreach ($m in $f.members) {
|
||||
$pv = [ordered]@{}
|
||||
if ($m.params) {
|
||||
foreach ($p in $m.params.PSObject.Properties) {
|
||||
$val = $p.Value
|
||||
if ($null -eq $val) { $pv[$p.Name] = $null }
|
||||
elseif ($val -is [System.Object[]] -or $val -is [System.Collections.ArrayList]) {
|
||||
$arr = @()
|
||||
foreach ($x in $val) { $arr += $x }
|
||||
$pv[$p.Name] = $arr
|
||||
}
|
||||
else { $pv[$p.Name] = $val }
|
||||
}
|
||||
}
|
||||
$famOf[[string]$m.slug] = [ordered]@{
|
||||
family = [string]$f.id
|
||||
role = [string]$m.role
|
||||
params = $pv
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Output ("families: {0} families, {1} member components" -f $famDoc.totalFamilies, $famDoc.totalMembers)
|
||||
} else {
|
||||
Write-Warning "families.json not found; the family layer will be omitted from data.json"
|
||||
}
|
||||
|
||||
# ---------------- spec section extraction ----------------
|
||||
function Extract-SpecSection([string]$specPath, [string]$enToken) {
|
||||
if (-not (Test-Path $specPath)) { return $null }
|
||||
@@ -65,6 +110,17 @@ function Parse-Contract([string]$path) {
|
||||
$usage = @(); foreach ($u in $c.usageHints) { $usage += [string]$u }
|
||||
$doNot = @(); if ($c.doNotInvent) { foreach ($x in $c.doNotInvent) { $doNot += [string]$x } }
|
||||
$unknowns = @(); if ($c.unknowns) { foreach ($x in $c.unknowns) { $unknowns += [string]$x } }
|
||||
$notes = @(); if ($c.clarificationNotes) {
|
||||
foreach ($n in $c.clarificationNotes) {
|
||||
$notes += [ordered]@{
|
||||
item = [string]$n.item
|
||||
kind = [string]$n.kind
|
||||
meaning = [string]$n.meaning
|
||||
why = [string]$n.why
|
||||
decision = [string]$n.decision
|
||||
}
|
||||
}
|
||||
}
|
||||
function PsObjToMap($obj) {
|
||||
$m = [ordered]@{}
|
||||
if ($obj) { foreach ($p in $obj.PSObject.Properties) { $m[$p.Name] = [string]$p.Value } }
|
||||
@@ -78,6 +134,7 @@ function Parse-Contract([string]$path) {
|
||||
anatomy = PsObjToMap $c.anatomy
|
||||
doNot = $doNot
|
||||
unknowns = $unknowns
|
||||
clarificationNotes = $notes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +191,9 @@ foreach ($c in $idx.components) {
|
||||
specFile = $c.specFile
|
||||
contractRef = $c.contract
|
||||
category = $cat
|
||||
family = $(if ($famOf.ContainsKey([string]$c.slug)) { $famOf[[string]$c.slug].family } else { $null })
|
||||
familyRole = $(if ($famOf.ContainsKey([string]$c.slug)) { $famOf[[string]$c.slug].role } else { $null })
|
||||
familyParams= $(if ($famOf.ContainsKey([string]$c.slug)) { $famOf[[string]$c.slug].params } else { $null })
|
||||
specLines = $(if ($spec) { @($spec.lines) } else { @() })
|
||||
specSummary = $(if ($spec) { $spec.summary } else { '' })
|
||||
contract = $contract
|
||||
@@ -180,13 +240,16 @@ $meta = [ordered]@{
|
||||
extension = ($out.Count - $coreCount)
|
||||
brand = "#2F54EB"
|
||||
version = $siteVersion
|
||||
note = "generated by build-site.ps1 from components/index.json + frameworks/ + specs + contracts + tokens"
|
||||
families = $(if ($famDoc) { [int]$famDoc.totalFamilies } else { 0 })
|
||||
familyMembers = $(if ($famDoc) { [int]$famDoc.totalMembers } else { 0 })
|
||||
note = "generated by build-site.ps1 from components/index.json + frameworks/ + specs + contracts + tokens + families"
|
||||
}
|
||||
|
||||
$data = [ordered]@{
|
||||
meta = $meta
|
||||
categories = $catList
|
||||
tokens = $tokens
|
||||
families = '__AA_FAMILIES_RAW__'
|
||||
changelog = $changelog
|
||||
components = $out
|
||||
}
|
||||
@@ -235,6 +298,13 @@ function Json-Value($v) {
|
||||
}
|
||||
|
||||
$json = Json-Value $data
|
||||
# Splice the family layer in as raw JSON: families.json is already valid JSON, and
|
||||
# round-tripping it through PS objects would risk both of the traps noted above.
|
||||
if ($famRaw) {
|
||||
$json = $json.Replace('"__AA_FAMILIES_RAW__"', $famRaw)
|
||||
} else {
|
||||
$json = $json.Replace('"__AA_FAMILIES_RAW__"', 'null')
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path site | Out-Null
|
||||
$js = "/* AUTO-GENERATED by build-site.ps1 - do not edit by hand */`r`nwindow.AA_DATA = $json;`r`n"
|
||||
# UTF-8 WITHOUT BOM: BOM breaks strict JSON parsers (node require, agent toolchains)
|
||||
@@ -303,7 +373,7 @@ $figmaDoc = [ordered]@{
|
||||
}
|
||||
[System.IO.File]::WriteAllText((Join-Path (Get-Location) "site/tokens/figma.json"), (Json-Value $figmaDoc), $utf8NoBom)
|
||||
|
||||
# Plain CSS custom properties — drop-in for any project that just wants the variables.
|
||||
# Plain CSS custom properties - drop-in for any project that just wants the variables.
|
||||
$cssLines = New-Object System.Text.StringBuilder
|
||||
[void]$cssLines.AppendLine('/* Aurora Admin design tokens - generated by build-site.ps1 */')
|
||||
[void]$cssLines.AppendLine(':root {')
|
||||
@@ -316,18 +386,33 @@ foreach ($t in $tokens) {
|
||||
Write-Output ("token export: site/tokens/ (dtcg.json + figma.json + tokens.css), {0} tokens" -f $tokens.Count)
|
||||
|
||||
# ---------------- static thin shells + sitemap (SEO / crawler entry points) ----------------
|
||||
# UPDATE $SiteUrlBase after repository deployment (GitHub Pages URL), then rebuild once.
|
||||
$SiteUrlBase = "https://YOUR-ACCOUNT.github.io/aurora-admin/"
|
||||
# Set SITE_URL_BASE in the environment for deployed absolute URLs.
|
||||
$defaultSiteUrlBase = "https://YOUR-ACCOUNT.github.io/aurora-admin/"
|
||||
if ([string]::IsNullOrWhiteSpace($env:SITE_URL_BASE)) {
|
||||
Write-Warning "SITE_URL_BASE is not set; using placeholder URL $defaultSiteUrlBase"
|
||||
$SiteUrlBase = $defaultSiteUrlBase
|
||||
} else {
|
||||
$SiteUrlBase = $env:SITE_URL_BASE.Trim()
|
||||
}
|
||||
$shellDir = "site/components"
|
||||
$siteBase = $SiteUrlBase.TrimEnd('/')
|
||||
$platforms = @('h5', 'react', 'vue2', 'vue3')
|
||||
$platformLabels = @{ h5 = 'H5'; react = 'React'; vue2 = 'Vue 2'; vue3 = 'Vue 3' }
|
||||
New-Item -ItemType Directory -Force -Path $shellDir | Out-Null
|
||||
function Html-Escape([string]$s) {
|
||||
if ($null -eq $s) { return '' }
|
||||
return $s.Replace('&','&').Replace('<','<').Replace('>','>').Replace('"','"')
|
||||
}
|
||||
$siteBaseHtml = Html-Escape $siteBase
|
||||
foreach ($c in $out) {
|
||||
$title = Html-Escape ([string]$c.name)
|
||||
$desc = Html-Escape ([string]$c.specSummary)
|
||||
$slug = [string]$c.slug
|
||||
if ($slug -notmatch '^[a-z0-9]+(?:-[a-z0-9]+)*$') {
|
||||
throw "Invalid component slug '$slug'; expected lowercase letters, digits, and single hyphens only."
|
||||
}
|
||||
$target = "../index.html#/component/$slug"
|
||||
$targetJson = Json-Escape $target
|
||||
$shell = @"
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
@@ -335,31 +420,66 @@ foreach ($c in $out) {
|
||||
<meta charset="UTF-8">
|
||||
<title>$title - Aurora Admin</title>
|
||||
<meta name="description" content="$desc">
|
||||
<link rel="canonical" href="$SiteUrlBase"site/components/$slug.html">
|
||||
<meta http-equiv="refresh" content="0;url=../index.html#/component/$slug">
|
||||
<link rel="canonical" href="$siteBaseHtml/site/components/$slug.html">
|
||||
<meta http-equiv="refresh" content="0;url=$target">
|
||||
</head>
|
||||
<body>
|
||||
<script>location.replace('../index.html#/component/$slug');</script>
|
||||
<noscript><p><a href="../index.html#/component/$slug">Open $title</a></p></noscript>
|
||||
<script>location.replace($targetJson);</script>
|
||||
<noscript><p><a href="$target">Open $title</a></p></noscript>
|
||||
</body>
|
||||
</html>
|
||||
"@
|
||||
[System.IO.File]::WriteAllText((Join-Path (Get-Location) "$shellDir/$slug.html"), $shell, $utf8NoBom)
|
||||
|
||||
foreach ($platform in $platforms) {
|
||||
$platformLabel = $platformLabels[$platform]
|
||||
$platformDir = Join-Path (Get-Location) "$shellDir/$slug"
|
||||
New-Item -ItemType Directory -Force -Path $platformDir | Out-Null
|
||||
$target = "../../index.html#/component/$slug/$platform"
|
||||
$targetJson = Json-Escape $target
|
||||
$platformShell = @"
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>$title - $platformLabel - Aurora Admin</title>
|
||||
<meta name="description" content="$desc">
|
||||
<link rel="canonical" href="$siteBaseHtml/site/components/$slug/$platform.html">
|
||||
<meta http-equiv="refresh" content="0;url=$target">
|
||||
</head>
|
||||
<body>
|
||||
<script>location.replace($targetJson);</script>
|
||||
<noscript><p><a href="$target">Open $title - $platformLabel</a></p></noscript>
|
||||
</body>
|
||||
</html>
|
||||
"@
|
||||
[System.IO.File]::WriteAllText((Join-Path $platformDir "$platform.html"), $platformShell, $utf8NoBom)
|
||||
}
|
||||
}
|
||||
|
||||
$sb = New-Object System.Text.StringBuilder
|
||||
[void]$sb.AppendLine('<?xml version="1.0" encoding="UTF-8"?>')
|
||||
[void]$sb.AppendLine('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
|
||||
$urls = @("site/index.html") + ($out | ForEach-Object { "site/components/$($_.slug).html" })
|
||||
$urls = @($siteBase + "/site/index.html")
|
||||
foreach ($c in $out) {
|
||||
$urls += $siteBase + "/site/components/$($c.slug).html"
|
||||
foreach ($platform in $platforms) {
|
||||
$urls += $siteBase + "/site/components/$($c.slug)/$platform.html"
|
||||
}
|
||||
}
|
||||
foreach ($u in $urls) {
|
||||
[void]$sb.AppendLine(' <url><loc>' + $SiteUrlBase + $u + '</loc></url>')
|
||||
[void]$sb.AppendLine(' <url><loc>' + $u + '</loc></url>')
|
||||
}
|
||||
[void]$sb.AppendLine('</urlset>')
|
||||
[System.IO.File]::WriteAllText((Join-Path (Get-Location) "sitemap.xml"), $sb.ToString(), $utf8NoBom)
|
||||
Write-Output ("thin shells: {0}, sitemap.xml: {1} urls" -f $out.Count, $urls.Count)
|
||||
Write-Output ("thin shells: {0}, platform shells: {1}, sitemap.xml: {2} urls" -f $out.Count, ($out.Count * $platforms.Count), $urls.Count)
|
||||
|
||||
$sizeKb = (Get-Item site/data.js).Length / 1KB
|
||||
Write-Output ("site/data.js written: {0:N0} KB, {1} components, {2} tokens" -f $sizeKb, $out.Count, $tokens.Count)
|
||||
if ($famDoc) {
|
||||
$famCount = @($out | Where-Object { $_.family }).Count
|
||||
Write-Output ("family layer: {0} families, {1}/{2} components carry family metadata" -f $famDoc.totalFamilies, $famCount, $out.Count)
|
||||
}
|
||||
if ($missing.Count -gt 0) { Write-Warning ("missing framework files: " + ($missing -join ', ')) }
|
||||
if ($noCat.Count -gt 0) { Write-Warning ("components without category: " + ($noCat -join ', ')) }
|
||||
if ($missing.Count -eq 0 -and $noCat.Count -eq 0) { Write-Output "all components complete (5-form files + category)" }
|
||||
|
||||
Reference in New Issue
Block a user