auto-save 2026-04-22 16:46 (~6)

This commit is contained in:
2026-04-22 16:46:51 +08:00
parent 89dacb708f
commit 47dcdabc35
6 changed files with 1099 additions and 292 deletions

View File

@@ -35,61 +35,62 @@ def main():
sys.exit(1)
figma_files = json.loads(figma_files_path.read_text()) # list of {key, name, ...}
# Match each template (fig preferred, else sketch) against cloud files
# Match each template source file to ALL matching cloud files (supports multi-variant)
matches = []
used_keys = set()
for t in manifest['templates']:
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'])
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])
if score > best_overall[0]:
best_overall = (score, cand)
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'], 'kind': kind, 'source_stem': stem,
'matched': cand['name'], 'key': cand['key'], 'score': round(score, 3)
})
else:
matches.append({
'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
})
variants = []
for src in source_files:
stem = Path(src).stem
# Match this specific source stem to best unused cloud file
score, cand = best_match(stem, [f for f in figma_files if f['key'] not in used_keys])
if cand and score >= 0.6:
used_keys.add(cand['key'])
variants.append({
'source_stem': stem,
'matched': cand['name'],
'key': cand['key'],
'score': round(score, 3)
})
matches.append({
'W': t['id'], 'name': t['name'], 'kind': kind,
'source_count': len(source_files),
'variants': variants,
})
# Update web/data.json
data_path = ROOT/'web'/'data.json'
data = json.loads(data_path.read_text())
by_W = {m['W']: m for m in matches if m.get('key')}
by_W = {m['W']: m for m in matches}
for t in data['templates']:
m = by_W.get(t['id'])
if m:
t['figma_key'] = m['key']
t['figma_url'] = f"https://www.figma.com/file/{m['key']}"
if m and m['variants']:
first = m['variants'][0]
t['figma_key'] = first['key']
t['figma_url'] = f"https://www.figma.com/file/{first['key']}"
t['figma_variants'] = [
{'name': v['source_stem'], 'matched': v['matched'], 'key': v['key'],
'url': f"https://www.figma.com/file/{v['key']}"}
for v in m['variants']
]
else:
t['figma_key'] = None
t['figma_url'] = None
t['figma_variants'] = []
# update banner with imported count
# update banner with imported count + variant total
imported = sum(1 for t in data['templates'] if t['figma_key'])
total_variants = sum(len(t.get('figma_variants', [])) for t in data['templates'])
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}/56 套</b>已云端就位在 "
f"✅ <b>{imported}/56 套</b>(共 {total_variants} 个文件)已云端就位在 "
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 实时投射。"
f"{fig_cnt} .fig + {sketch_only_cnt} .sketch 转换)。"
f"点卡片 → modal → 多变体 tab 切换 + iframe 实时投射。"
)
data_path.write_text(json.dumps(data, ensure_ascii=False, indent=2))
@@ -97,13 +98,14 @@ def main():
report = ROOT/'figma-match-report.json'
report.write_text(json.dumps(matches, ensure_ascii=False, indent=2))
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)")
multi_variant = sum(1 for m in matches if len(m['variants']) > 1)
print(f"Matched {imported}/{total_matchable} templates, {total_variants} total file keys, {multi_variant} with multi variants")
print(f"Report: {report.relative_to(ROOT)}")
unmatched = [m for m in matches if not m.get('key')]
unmatched = [m for m in matches if not m['variants']]
if unmatched:
print(f"\n⚠️ {len(unmatched)} unmatched:")
for m in unmatched:
print(f" {m['W']:4s} {m['name'][:50]:50s} best='{m.get('best_candidate','')[:40]}' score={m.get('best_score',0)}")
print(f" {m['W']:4s} {m['name'][:50]:50s}")
if __name__ == '__main__':
main()