feat: 12 套 Sketch 也上 Figma,47/47 模板全部投射就位

- 16 个 .sketch 经 Playwright Import 上传(Figma 自动转 fig)
- 匹配脚本扩展:fig 优先,sketch 次之
- 47/47 匹配(35 fig + 12 sketch-only)
- banner 文案更新

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
kang
2026-04-22 15:58:06 +08:00
parent be6d4f7b48
commit 3237ef8271
3 changed files with 219 additions and 72 deletions

View File

@@ -35,18 +35,17 @@ def main():
sys.exit(1)
figma_files = json.loads(figma_files_path.read_text()) # list of {key, name, ...}
# for each W template that has fig, find matching figma file
# Match each template (fig preferred, else sketch) against cloud files
matches = []
used_keys = set()
for t in manifest['templates']:
if not t['fig']: continue
# use the .fig file's stem as match target (closer than archive name)
targets = [Path(f).stem for f in t['fig']]
# add archive stem as backup
source_files = t['fig'] if t['fig'] else t['sketch']
if not source_files: continue
kind = 'fig' if t['fig'] else 'sketch'
targets = [Path(f).stem for f in source_files]
if t.get('archive'):
targets.append(Path(t['archive']).stem)
targets.append(t['name'])
# try each target
best_overall = (0, None)
for tgt in targets:
score, cand = best_match(tgt, [f for f in figma_files if f['key'] not in used_keys])
@@ -55,15 +54,16 @@ def main():
if score > 0.95:
break
score, cand = best_overall
stem = Path(source_files[0]).stem
if cand and score >= 0.6:
used_keys.add(cand['key'])
matches.append({
'W': t['id'], 'name': t['name'], 'fig_stem': Path(t['fig'][0]).stem if t['fig'] else None,
'W': t['id'], 'name': t['name'], 'kind': kind, 'source_stem': stem,
'matched': cand['name'], 'key': cand['key'], 'score': round(score, 3)
})
else:
matches.append({
'W': t['id'], 'name': t['name'], 'fig_stem': Path(t['fig'][0]).stem if t['fig'] else None,
'W': t['id'], 'name': t['name'], 'kind': kind, 'source_stem': stem,
'matched': None, 'best_score': round(best_overall[0], 3) if cand else 0,
'best_candidate': cand['name'] if cand else None
})
@@ -83,17 +83,21 @@ def main():
# update banner with imported count
imported = sum(1 for t in data['templates'] if t['figma_key'])
fig_cnt = sum(1 for t in manifest['templates'] if t['fig'])
sketch_only_cnt = sum(1 for t in manifest['templates'] if not t['fig'] and t['sketch'])
data['imported_summary'] = (
f"✅ <b>{imported} 个 Figma 原生文件</b>已云端就位在你的 "
f"<a href='https://www.figma.com/files/team/1304178887825899477/drafts' target='_blank'>Figma Drafts</a>"
f"点卡片打开 modal 查看 iframe 实时投射 + 跳 Figma 编辑"
f"✅ <b>{imported}/56 套</b>已云端就位在 "
f"<a href='https://www.figma.com/files/team/1304178887825899477/drafts' target='_blank'>Figma Drafts</a>"
f"{fig_cnt} 个 .fig 原生 + {sketch_only_cnt} 个 .sketch 经 Figma 转换)"
f"点卡片 → modal → iframe 实时投射。"
)
data_path.write_text(json.dumps(data, ensure_ascii=False, indent=2))
# write match report
report = ROOT/'figma-match-report.json'
report.write_text(json.dumps(matches, ensure_ascii=False, indent=2))
print(f"Matched {imported}/{sum(1 for t in manifest['templates'] if t['fig'])} fig templates")
total_matchable = sum(1 for t in manifest['templates'] if t['fig'] or t['sketch'])
print(f"Matched {imported}/{total_matchable} templates ({fig_cnt} fig + {sketch_only_cnt} sketch-only)")
print(f"Report: {report.relative_to(ROOT)}")
unmatched = [m for m in matches if not m.get('key')]
if unmatched: