|
1 | 1 | import { GROUPS } from '@/rewrite/config' |
2 | | -import { analyze } from '@/rewrite/shared' |
| 2 | +import { applyGroups, groupMatches } from '@/rewrite/shared' |
3 | 3 | import { chromium } from 'playwright-chromium' |
4 | 4 | import rules from '../public/rules/figma.json' |
5 | 5 |
|
@@ -56,36 +56,43 @@ async function runCheck() { |
56 | 56 | await page.goto(`https://www.figma.com/design/${process.env.FIGMA_FILE_KEY}`) |
57 | 57 | console.log(`Page loaded at <${page.url()}>.`) |
58 | 58 |
|
59 | | - let matched: string | null = null |
60 | | - let rewritable = false |
| 59 | + let matchedCount = 0 |
| 60 | + let rewrittenCount = 0 |
| 61 | + const notRewritten: string[] = [] |
61 | 62 |
|
62 | 63 | for (const { url, content } of scripts) { |
63 | | - const { matched: m, rewritable: r } = analyze(content, GROUPS) |
64 | | - if (!m) { |
| 64 | + const matched = GROUPS.some((group) => groupMatches(content, group)) |
| 65 | + if (!matched) { |
65 | 66 | continue |
66 | 67 | } |
67 | | - matched = url |
| 68 | + |
| 69 | + matchedCount++ |
68 | 70 | console.log(`Matched script: <${url}>.`) |
69 | | - if (r) { |
70 | | - rewritable = true |
71 | | - console.log(`Rewritable script: <${url}>.`) |
72 | | - break |
| 71 | + |
| 72 | + const { changed } = applyGroups(content, GROUPS) |
| 73 | + if (changed) { |
| 74 | + rewrittenCount++ |
| 75 | + console.log(`Rewritable (would change): <${url}>.`) |
| 76 | + } else { |
| 77 | + notRewritten.push(url) |
| 78 | + console.log(`Not rewritable (no change produced): <${url}>.`) |
73 | 79 | } |
74 | 80 | } |
75 | 81 |
|
76 | | - if (!matched) { |
| 82 | + if (matchedCount === 0) { |
77 | 83 | console.log('❌ No matched script found.') |
78 | 84 | return false |
79 | 85 | } |
80 | 86 |
|
81 | | - console.log(`✅ Matched script: <${matched}>.`) |
| 87 | + console.log(`✅ Matched ${matchedCount} script(s).`) |
82 | 88 |
|
83 | | - if (!rewritable) { |
84 | | - console.log('❌ Rewrite pattern not found.') |
| 89 | + if (rewrittenCount !== matchedCount) { |
| 90 | + console.log('❌ Some matched scripts would not be rewritten by rules:') |
| 91 | + notRewritten.forEach((url) => console.log(` - <${url}>`)) |
85 | 92 | return false |
86 | 93 | } |
87 | 94 |
|
88 | | - console.log('✅ Rewrite pattern found.') |
| 95 | + console.log('✅ All matched scripts would be rewritten by rules.') |
89 | 96 | return true |
90 | 97 | } finally { |
91 | 98 | await browser.close() |
|
0 commit comments