-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathaudit.mjs
More file actions
279 lines (224 loc) · 9.46 KB
/
Copy pathaudit.mjs
File metadata and controls
279 lines (224 loc) · 9.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env node
// Design System Audit Script
// Generates AUDIT.md with coverage report for packages/propel and packages/ui
import { readFileSync, readdirSync, existsSync, writeFileSync } from "fs";
import { join, resolve } from "path";
const ROOT = resolve(process.cwd(), "../..");
const PROPEL_SRC = resolve(process.cwd(), "src");
const UI_SRC = resolve(ROOT, "packages/ui/src");
function getComponentDirs(srcPath) {
if (!existsSync(srcPath)) return [];
return readdirSync(srcPath, { withFileTypes: true })
.filter((d) => d.isDirectory())
.map((d) => d.name)
.filter((d) => !["styles", "utils", "assets", "icons", "charts", "spinners", "design-system"].includes(d));
}
function analyzeComponent(srcPath, name) {
const dir = join(srcPath, name);
const files = existsSync(dir) ? readdirSync(dir) : [];
const hasComponent = files.some(
(f) => f.endsWith(".tsx") && !f.includes("stories") && !f.includes("helper") && !f.includes("index")
);
const hasHelper = files.includes("helper.tsx");
const hasIndex = files.includes("index.ts") || files.includes("index.tsx");
const storyFile = files.find((f) => f.includes(".stories."));
const hasStory = !!storyFile;
let storyQuality = "❌ sin story";
let figmaLink = false;
let propDocs = false;
let variantCount = 0;
let hardcodedValues = false;
if (hasStory) {
const storyContent = readFileSync(join(dir, storyFile), "utf-8");
const storyLines = storyContent.split("\n").length;
// Check for Figma link
figmaLink = storyContent.includes("addon-designs") || storyContent.includes("figma.com");
// Check for prop documentation (argTypes descriptions)
propDocs = storyContent.includes("description:") || storyContent.includes("argTypes");
// Count story exports (rough proxy for coverage)
const storyCount = (storyContent.match(/^export const /gm) || []).length;
if (storyLines < 30) storyQuality = "⚠️ story mínima";
else if (storyCount >= 3) storyQuality = "✅ story completa";
else storyQuality = "⚠️ story básica";
}
// Check helper for CVA variants
if (hasHelper) {
const helperContent = readFileSync(join(dir, "helper.tsx"), "utf-8");
const cvaMatches = helperContent.match(/variants:\s*{([^}]+)}/s);
if (cvaMatches) {
variantCount = (cvaMatches[1].match(/\w+:/g) || []).length;
}
// Check for hardcoded hex values
hardcodedValues = /#[0-9a-fA-F]{3,6}/.test(helperContent) || /\d+px/.test(helperContent);
}
// Also check main component file for hardcoded values
const componentFile = files.find(
(f) => f.endsWith(".tsx") && !f.includes("stories") && !f.includes("helper") && !f.includes("index")
);
if (componentFile) {
const componentContent = readFileSync(join(dir, componentFile), "utf-8");
if (!hardcodedValues) {
hardcodedValues = /#[0-9a-fA-F]{3,6}/.test(componentContent);
}
}
return {
name,
hasComponent,
hasHelper,
hasIndex,
hasStory,
storyQuality,
figmaLink,
propDocs,
variantCount,
hardcodedValues,
};
}
function analyzeSpecialDirs(srcPath) {
const results = [];
const specialDirs = ["charts", "spinners", "icons"];
for (const dir of specialDirs) {
const fullPath = join(srcPath, dir);
if (!existsSync(fullPath)) continue;
const files = readdirSync(fullPath, { withFileTypes: true });
const subdirs = files.filter((f) => f.isDirectory()).map((f) => f.name);
const storyFile = readdirSync(fullPath).find((f) => f.includes(".stories."));
results.push({
name: dir,
hasComponent: subdirs.length > 0,
hasHelper: existsSync(join(fullPath, "helper.tsx")),
hasIndex: existsSync(join(fullPath, "index.ts")),
hasStory: !!storyFile,
storyQuality: storyFile ? "⚠️ story de grupo" : "❌ sin story",
figmaLink: false,
propDocs: false,
variantCount: subdirs.length,
hardcodedValues: false,
isGroup: true,
subComponents: subdirs,
});
}
return results;
}
// --- Run audit ---
const propelDirs = getComponentDirs(PROPEL_SRC);
const uiDirs = getComponentDirs(UI_SRC);
const propelResults = [
...propelDirs.map((name) => analyzeComponent(PROPEL_SRC, name)),
...analyzeSpecialDirs(PROPEL_SRC),
];
const uiResults = uiDirs.map((name) => analyzeComponent(UI_SRC, name));
// Find UI components without propel equivalent
const propelNames = new Set(propelResults.map((r) => r.name.toLowerCase()));
const uiWithoutPropel = uiResults.filter((r) => !propelNames.has(r.name.toLowerCase()));
// Stats
const propelWithStory = propelResults.filter((r) => r.hasStory).length;
const propelWithFigma = propelResults.filter((r) => r.figmaLink).length;
const propelWithDocs = propelResults.filter((r) => r.propDocs).length;
const propelComplete = propelResults.filter((r) => r.storyQuality.includes("✅")).length;
const propelHardcoded = propelResults.filter((r) => r.hardcodedValues).length;
// --- Generate Markdown ---
const now = new Date().toLocaleDateString("es-ES", { year: "numeric", month: "long", day: "numeric" });
let md = `# Auditoría del Design System de Plane
*Generado el ${now}*
---
## Resumen Ejecutivo
| Métrica | Propel | UI (legacy) |
|---------|--------|-------------|
| Total componentes | ${propelResults.length} | ${uiResults.length} |
| Con story | ${propelWithStory}/${propelResults.length} (${Math.round((propelWithStory / propelResults.length) * 100)}%) | — |
| Stories completas | ${propelComplete}/${propelResults.length} (${Math.round((propelComplete / propelResults.length) * 100)}%) | — |
| Con Figma link | ${propelWithFigma}/${propelResults.length} (${Math.round((propelWithFigma / propelResults.length) * 100)}%) | — |
| Con prop docs | ${propelWithDocs}/${propelResults.length} (${Math.round((propelWithDocs / propelResults.length) * 100)}%) | — |
| Valores hardcodeados | ${propelHardcoded} componentes ⚠️ | — |
| Sin equivalente en propel | — | ${uiWithoutPropel.length} componentes |
---
## packages/propel — Estado por componente
| Componente | Story | Calidad | Figma | Prop docs | Variants CVA | Hardcoded |
|-----------|-------|---------|-------|-----------|-------------|-----------|
`;
for (const r of propelResults.toSorted((a, b) => a.name.localeCompare(b.name))) {
const story = r.hasStory ? "✅" : "❌";
const figma = r.figmaLink ? "✅" : "—";
const docs = r.propDocs ? "✅" : "—";
const hardcoded = r.hardcodedValues ? "⚠️" : "✅";
const variants = r.variantCount > 0 ? `${r.variantCount}` : "—";
md += `| \`${r.name}\` | ${story} | ${r.storyQuality} | ${figma} | ${docs} | ${variants} | ${hardcoded} |\n`;
}
md += `
---
## packages/ui (legacy) — Componentes sin equivalente en propel
Estos ${uiWithoutPropel.length} componentes de \`packages/ui\` no tienen equivalente en \`packages/propel\` y son **candidatos a migrar o crear**:
| Componente | Tiene story | Tiene helper CVA |
|-----------|-------------|-----------------|
`;
for (const r of uiWithoutPropel.toSorted((a, b) => a.name.localeCompare(b.name))) {
const story = r.hasStory ? "✅" : "❌";
const helper = r.hasHelper ? "✅" : "❌";
md += `| \`${r.name}\` | ${story} | ${helper} |\n`;
}
md += `
---
## Prioridades de acción
### 🔴 Crítico — Stories faltantes en propel
`;
const noStory = propelResults.filter((r) => !r.hasStory);
if (noStory.length === 0) {
md += `✅ Todos los componentes tienen al menos una story.\n`;
} else {
for (const r of noStory) {
md += `- [ ] \`${r.name}\` — crear story completa\n`;
}
}
md += `
### 🟡 Mejorar — Stories básicas o mínimas
`;
const basicStory = propelResults.filter((r) => r.hasStory && !r.storyQuality.includes("✅"));
for (const r of basicStory) {
md += `- [ ] \`${r.name}\` (${r.storyQuality}) — ampliar con más variants y prop docs\n`;
}
md += `
### 🟠 Figma links faltantes
`;
const noFigma = propelResults.filter((r) => !r.figmaLink);
for (const r of noFigma) {
md += `- [ ] \`${r.name}\` — añadir Figma link via \`@storybook/addon-designs\`\n`;
}
md += `
### 🟡 Valores hardcodeados detectados
`;
const hardcoded = propelResults.filter((r) => r.hardcodedValues);
if (hardcoded.length === 0) {
md += `✅ No se detectaron valores hardcodeados. Todos usan tokens semánticos.\n`;
} else {
for (const r of hardcoded) {
md += `- [ ] \`${r.name}\` — revisar y reemplazar con tokens de \`tailwind-config\`\n`;
}
}
md += `
### 🔵 Migración de ui → propel
`;
for (const r of uiWithoutPropel) {
md += `- [ ] Crear \`${r.name}\` en propel basado en la implementación de ui\n`;
}
md += `
---
## Próximos pasos
1. **Completar stories** de los ${noStory.length} componentes sin cobertura
2. **Añadir Figma links** a todos los componentes en Storybook
3. **Construir MCP server** en \`packages/design-system-mcp/\` para acceso agéntico
4. **Añadir AI components**: \`AIInput\`, \`AICommandPalette\`, \`StreamingText\`
5. **Migrar** los ${uiWithoutPropel.length} componentes de ui sin equivalente en propel
---
*Script: \`packages/propel/scripts/audit.mjs\`*
`;
const outputPath = resolve(process.cwd(), "AUDIT.md");
writeFileSync(outputPath, md);
console.log(`✅ Auditoría completada → ${outputPath}`);
console.log(`\nResumen:`);
console.log(
` propel: ${propelResults.length} componentes, ${propelWithStory} con story (${Math.round((propelWithStory / propelResults.length) * 100)}%)`
);
console.log(` Stories completas: ${propelComplete}/${propelResults.length}`);
console.log(` Sin Figma link: ${noFigma.length}`);
console.log(` ui sin equivalente en propel: ${uiWithoutPropel.length}`);