@storytype/cli 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-WOGXOJML.js +555 -0
- package/dist/cli.js +44 -20
- package/dist/index.js +1 -1
- package/package.json +15 -14
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
// src/analyzer.ts
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import ora from "ora";
|
|
6
|
+
var ATOMIC_LEVELS = ["atoms", "molecules", "organisms", "templates", "pages"];
|
|
7
|
+
var COMPONENT_EXTENSIONS = [".vue", ".tsx", ".ts"];
|
|
8
|
+
var STORY_PATTERNS = [".stories.ts", ".stories.tsx", ".story.ts", ".story.tsx"];
|
|
9
|
+
var TEST_PATTERNS = [".spec.ts", ".spec.tsx", ".test.ts", ".test.tsx"];
|
|
10
|
+
var AUXILIARY_PATTERNS = [
|
|
11
|
+
".types.ts",
|
|
12
|
+
".types.tsx",
|
|
13
|
+
".mock.ts",
|
|
14
|
+
".mock.tsx",
|
|
15
|
+
".mocks.ts",
|
|
16
|
+
".mocks.tsx"
|
|
17
|
+
];
|
|
18
|
+
var BARREL_FILES = ["index.ts", "index.tsx", "index.js", "index.jsx"];
|
|
19
|
+
async function analyzeProject(projectPath = process.cwd()) {
|
|
20
|
+
const spinner = ora("Analisando projeto...").start();
|
|
21
|
+
try {
|
|
22
|
+
const categories = [];
|
|
23
|
+
categories.push(await analyzeStructure(projectPath, spinner));
|
|
24
|
+
categories.push(await analyzeTypeScript(projectPath, spinner));
|
|
25
|
+
categories.push(await analyzeTestsAndStories(projectPath, spinner));
|
|
26
|
+
categories.push(await analyzeNaming(projectPath, spinner));
|
|
27
|
+
categories.push(await analyzeDocumentation(projectPath, spinner));
|
|
28
|
+
const totalScore = categories.reduce((sum, cat) => sum + cat.score, 0);
|
|
29
|
+
const maxScore = categories.reduce((sum, cat) => sum + cat.maxScore, 0);
|
|
30
|
+
const percentage = maxScore > 0 ? Math.round(totalScore / maxScore * 100) : 0;
|
|
31
|
+
spinner.succeed("An\xE1lise completa!");
|
|
32
|
+
return {
|
|
33
|
+
score: totalScore,
|
|
34
|
+
maxScore,
|
|
35
|
+
percentage,
|
|
36
|
+
categories,
|
|
37
|
+
summary: generateSummary(percentage)
|
|
38
|
+
};
|
|
39
|
+
} catch (error) {
|
|
40
|
+
spinner.fail("Erro ao analisar projeto");
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function analyzeStructure(projectPath, spinner) {
|
|
45
|
+
spinner.text = "Analisando estrutura Atomic Design...";
|
|
46
|
+
const items = [];
|
|
47
|
+
const componentsPath = findComponentsDirectory(projectPath);
|
|
48
|
+
if (!componentsPath) {
|
|
49
|
+
items.push({
|
|
50
|
+
name: "Diret\xF3rio de componentes",
|
|
51
|
+
passed: false,
|
|
52
|
+
points: 0,
|
|
53
|
+
maxPoints: 10,
|
|
54
|
+
message: "Nenhum diret\xF3rio de componentes encontrado (src/components, components, etc.)"
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
name: "Estrutura Atomic Design",
|
|
58
|
+
score: 0,
|
|
59
|
+
maxScore: 50,
|
|
60
|
+
percentage: 0,
|
|
61
|
+
items
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const foundLevels = ATOMIC_LEVELS.filter(
|
|
65
|
+
(level) => fs.existsSync(path.join(componentsPath, level))
|
|
66
|
+
);
|
|
67
|
+
items.push({
|
|
68
|
+
name: "Diret\xF3rio de componentes",
|
|
69
|
+
passed: true,
|
|
70
|
+
points: 10,
|
|
71
|
+
maxPoints: 10,
|
|
72
|
+
message: `Encontrado em: ${path.relative(projectPath, componentsPath)}`
|
|
73
|
+
});
|
|
74
|
+
items.push({
|
|
75
|
+
name: "N\xEDveis Atomic Design",
|
|
76
|
+
passed: foundLevels.length >= 3,
|
|
77
|
+
points: foundLevels.length * 5,
|
|
78
|
+
maxPoints: 25,
|
|
79
|
+
message: `Encontrados: ${foundLevels.join(", ") || "nenhum"} (${foundLevels.length}/5)`
|
|
80
|
+
});
|
|
81
|
+
const totalComponents = countComponents(componentsPath);
|
|
82
|
+
const wellOrganized = foundLevels.length >= 3 && totalComponents >= 3;
|
|
83
|
+
items.push({
|
|
84
|
+
name: "Organiza\xE7\xE3o de componentes",
|
|
85
|
+
passed: wellOrganized,
|
|
86
|
+
points: wellOrganized ? 15 : Math.min(totalComponents * 3, 15),
|
|
87
|
+
maxPoints: 15,
|
|
88
|
+
message: `${totalComponents} componentes encontrados`
|
|
89
|
+
});
|
|
90
|
+
const score = items.reduce((sum, item) => sum + item.points, 0);
|
|
91
|
+
const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
|
|
92
|
+
return {
|
|
93
|
+
name: "Estrutura Atomic Design",
|
|
94
|
+
score,
|
|
95
|
+
maxScore,
|
|
96
|
+
percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
|
|
97
|
+
items
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function analyzeTypeScript(projectPath, spinner) {
|
|
101
|
+
spinner.text = "Analisando uso de TypeScript...";
|
|
102
|
+
const items = [];
|
|
103
|
+
const hasTsConfig = fs.existsSync(path.join(projectPath, "tsconfig.json"));
|
|
104
|
+
items.push({
|
|
105
|
+
name: "Configura\xE7\xE3o TypeScript",
|
|
106
|
+
passed: hasTsConfig,
|
|
107
|
+
points: hasTsConfig ? 10 : 0,
|
|
108
|
+
maxPoints: 10,
|
|
109
|
+
message: hasTsConfig ? "tsconfig.json encontrado" : "tsconfig.json n\xE3o encontrado"
|
|
110
|
+
});
|
|
111
|
+
const componentsPath = findComponentsDirectory(projectPath);
|
|
112
|
+
if (componentsPath) {
|
|
113
|
+
const allComponents = findAllComponents(componentsPath);
|
|
114
|
+
const tsComponents = allComponents.filter((f) => isFileUsingTypeScript(f));
|
|
115
|
+
const nonTsComponents = allComponents.filter((f) => !isFileUsingTypeScript(f));
|
|
116
|
+
const total = allComponents.length;
|
|
117
|
+
const typescript = tsComponents.length;
|
|
118
|
+
const tsPercentage = total > 0 ? typescript / total * 100 : 0;
|
|
119
|
+
items.push({
|
|
120
|
+
name: "Componentes TypeScript",
|
|
121
|
+
passed: tsPercentage >= 80,
|
|
122
|
+
points: Math.round(tsPercentage / 100 * 15),
|
|
123
|
+
maxPoints: 15,
|
|
124
|
+
message: `${typescript}/${total} componentes (${Math.round(tsPercentage)}%)`,
|
|
125
|
+
fileIssues: nonTsComponents.map((f) => ({
|
|
126
|
+
file: f,
|
|
127
|
+
issue: f.endsWith(".vue") ? `Arquivo .vue n\xE3o usa TypeScript: "${path.basename(f)}"` : `Arquivo n\xE3o usa TypeScript: "${path.basename(f)}"`,
|
|
128
|
+
fix: f.endsWith(".vue") ? `Adicione lang="ts" ao script: <script setup lang="ts">` : `Renomeie para "${path.basename(f, path.extname(f))}.ts" e adicione tipagem`
|
|
129
|
+
}))
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
items.push({
|
|
133
|
+
name: "Componentes TypeScript",
|
|
134
|
+
passed: false,
|
|
135
|
+
points: 0,
|
|
136
|
+
maxPoints: 15,
|
|
137
|
+
message: "Diret\xF3rio de componentes n\xE3o encontrado"
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const hasTypesDir = componentsPath && fs.existsSync(path.join(componentsPath, "types"));
|
|
141
|
+
const hasTypesFiles = componentsPath && hasFilesWithPattern(componentsPath, /types\.ts$/i);
|
|
142
|
+
items.push({
|
|
143
|
+
name: "Arquivos de tipos",
|
|
144
|
+
passed: Boolean(hasTypesDir || hasTypesFiles),
|
|
145
|
+
points: hasTypesDir || hasTypesFiles ? 5 : 0,
|
|
146
|
+
maxPoints: 5,
|
|
147
|
+
message: hasTypesDir ? "Diret\xF3rio types/ encontrado" : hasTypesFiles ? "Arquivos types.ts encontrados" : "Nenhum arquivo de tipos dedicado"
|
|
148
|
+
});
|
|
149
|
+
const score = items.reduce((sum, item) => sum + item.points, 0);
|
|
150
|
+
const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
|
|
151
|
+
return {
|
|
152
|
+
name: "TypeScript",
|
|
153
|
+
score,
|
|
154
|
+
maxScore,
|
|
155
|
+
percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
|
|
156
|
+
items
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async function analyzeTestsAndStories(projectPath, spinner) {
|
|
160
|
+
spinner.text = "Analisando testes e stories...";
|
|
161
|
+
const items = [];
|
|
162
|
+
const componentsPath = findComponentsDirectory(projectPath);
|
|
163
|
+
if (!componentsPath) {
|
|
164
|
+
return {
|
|
165
|
+
name: "Testes e Stories",
|
|
166
|
+
score: 0,
|
|
167
|
+
maxScore: 30,
|
|
168
|
+
percentage: 0,
|
|
169
|
+
items: [
|
|
170
|
+
{
|
|
171
|
+
name: "Cobertura de testes",
|
|
172
|
+
passed: false,
|
|
173
|
+
points: 0,
|
|
174
|
+
maxPoints: 15,
|
|
175
|
+
message: "Diret\xF3rio de componentes n\xE3o encontrado"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "Cobertura de stories",
|
|
179
|
+
passed: false,
|
|
180
|
+
points: 0,
|
|
181
|
+
maxPoints: 15,
|
|
182
|
+
message: "Diret\xF3rio de componentes n\xE3o encontrado"
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const componentFiles = findAllComponents(componentsPath);
|
|
188
|
+
const testFiles = findFilesByPattern(componentsPath, TEST_PATTERNS);
|
|
189
|
+
const storyFiles = findFilesByPattern(componentsPath, STORY_PATTERNS);
|
|
190
|
+
const testFileBases = new Set(testFiles.map((f) => stripTestSuffix(f, TEST_PATTERNS)));
|
|
191
|
+
const storyFileBases = new Set(storyFiles.map((f) => stripTestSuffix(f, STORY_PATTERNS)));
|
|
192
|
+
const componentsMissingTests = componentFiles.filter((f) => !testFileBases.has(stripExt(f)));
|
|
193
|
+
const componentsMissingStories = componentFiles.filter((f) => !storyFileBases.has(stripExt(f)));
|
|
194
|
+
const testCoverage = componentFiles.length > 0 ? testFiles.length / componentFiles.length * 100 : 0;
|
|
195
|
+
const storyCoverage = componentFiles.length > 0 ? storyFiles.length / componentFiles.length * 100 : 0;
|
|
196
|
+
items.push({
|
|
197
|
+
name: "Cobertura de testes",
|
|
198
|
+
passed: testCoverage >= 70,
|
|
199
|
+
points: Math.round(Math.min(testCoverage, 100) / 100 * 15),
|
|
200
|
+
maxPoints: 15,
|
|
201
|
+
message: `${testFiles.length}/${componentFiles.length} componentes (${Math.round(testCoverage)}%)`,
|
|
202
|
+
fileIssues: componentsMissingTests.map((f) => ({
|
|
203
|
+
file: f,
|
|
204
|
+
issue: "Sem arquivo de teste",
|
|
205
|
+
fix: `Crie ${path.join(path.dirname(f), path.basename(f, path.extname(f)) + ".spec.ts")}`
|
|
206
|
+
}))
|
|
207
|
+
});
|
|
208
|
+
items.push({
|
|
209
|
+
name: "Cobertura de stories",
|
|
210
|
+
passed: storyCoverage >= 70,
|
|
211
|
+
points: Math.round(Math.min(storyCoverage, 100) / 100 * 15),
|
|
212
|
+
maxPoints: 15,
|
|
213
|
+
message: `${storyFiles.length}/${componentFiles.length} componentes (${Math.round(storyCoverage)}%)`,
|
|
214
|
+
fileIssues: componentsMissingStories.map((f) => ({
|
|
215
|
+
file: f,
|
|
216
|
+
issue: "Sem arquivo de story",
|
|
217
|
+
fix: `Crie ${path.join(path.dirname(f), path.basename(f, path.extname(f)) + ".stories.ts")}`
|
|
218
|
+
}))
|
|
219
|
+
});
|
|
220
|
+
const score = items.reduce((sum, item) => sum + item.points, 0);
|
|
221
|
+
const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
|
|
222
|
+
return {
|
|
223
|
+
name: "Testes e Stories",
|
|
224
|
+
score,
|
|
225
|
+
maxScore,
|
|
226
|
+
percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
|
|
227
|
+
items
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
async function analyzeNaming(projectPath, spinner) {
|
|
231
|
+
spinner.text = "Analisando nomenclatura...";
|
|
232
|
+
const items = [];
|
|
233
|
+
const componentsPath = findComponentsDirectory(projectPath);
|
|
234
|
+
if (!componentsPath) {
|
|
235
|
+
return {
|
|
236
|
+
name: "Nomenclatura",
|
|
237
|
+
score: 0,
|
|
238
|
+
maxScore: 15,
|
|
239
|
+
percentage: 0,
|
|
240
|
+
items: [
|
|
241
|
+
{
|
|
242
|
+
name: "Conven\xE7\xE3o PascalCase",
|
|
243
|
+
passed: false,
|
|
244
|
+
points: 0,
|
|
245
|
+
maxPoints: 10,
|
|
246
|
+
message: "Diret\xF3rio de componentes n\xE3o encontrado"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "Organiza\xE7\xE3o por pastas",
|
|
250
|
+
passed: false,
|
|
251
|
+
points: 0,
|
|
252
|
+
maxPoints: 5,
|
|
253
|
+
message: "Diret\xF3rio de componentes n\xE3o encontrado"
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const componentFiles = findAllComponents(componentsPath);
|
|
259
|
+
const getComponentBaseName = (file) => {
|
|
260
|
+
const fileName = path.basename(file);
|
|
261
|
+
return fileName.replace(/\.(types|stories|story|spec|test)\.(ts|tsx|js|jsx)$/, "").replace(/\.(ts|tsx|js|jsx|vue)$/, "");
|
|
262
|
+
};
|
|
263
|
+
const pascalCaseFiles = componentFiles.filter((file) => {
|
|
264
|
+
const baseName = getComponentBaseName(file);
|
|
265
|
+
if (baseName === "index") return true;
|
|
266
|
+
return /^[A-Z][a-zA-Z0-9]*$/.test(baseName);
|
|
267
|
+
});
|
|
268
|
+
const nonPascalFiles = componentFiles.filter((file) => {
|
|
269
|
+
const baseName = getComponentBaseName(file);
|
|
270
|
+
if (baseName === "index") return false;
|
|
271
|
+
return !/^[A-Z][a-zA-Z0-9]*$/.test(baseName);
|
|
272
|
+
});
|
|
273
|
+
const pascalCasePercentage = componentFiles.length > 0 ? pascalCaseFiles.length / componentFiles.length * 100 : 0;
|
|
274
|
+
items.push({
|
|
275
|
+
name: "Conven\xE7\xE3o PascalCase",
|
|
276
|
+
passed: pascalCasePercentage >= 90,
|
|
277
|
+
points: Math.round(pascalCasePercentage / 100 * 10),
|
|
278
|
+
maxPoints: 10,
|
|
279
|
+
message: `${pascalCaseFiles.length}/${componentFiles.length} componentes (${Math.round(pascalCasePercentage)}%)`,
|
|
280
|
+
fileIssues: nonPascalFiles.map((f) => {
|
|
281
|
+
const oldName = path.basename(f);
|
|
282
|
+
const baseName = getComponentBaseName(f);
|
|
283
|
+
const pascalName = baseName.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase());
|
|
284
|
+
const suffix = oldName.replace(
|
|
285
|
+
new RegExp(`^${baseName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`),
|
|
286
|
+
""
|
|
287
|
+
);
|
|
288
|
+
const newName = `${pascalName}${suffix}`;
|
|
289
|
+
return {
|
|
290
|
+
file: f,
|
|
291
|
+
oldName,
|
|
292
|
+
newName
|
|
293
|
+
};
|
|
294
|
+
}).filter(({ oldName, newName }) => oldName !== newName).map(({ file, oldName, newName }) => ({
|
|
295
|
+
file,
|
|
296
|
+
issue: `Nome em formato incorreto: "${oldName}"`,
|
|
297
|
+
fix: `Renomeie para "${newName}"`
|
|
298
|
+
}))
|
|
299
|
+
});
|
|
300
|
+
const folderedComponents = componentFiles.filter((file) => {
|
|
301
|
+
const dir = path.dirname(file);
|
|
302
|
+
const fileName = path.basename(file, path.extname(file));
|
|
303
|
+
const parentFolder = path.basename(dir);
|
|
304
|
+
return fileName === parentFolder || fileName === "index";
|
|
305
|
+
});
|
|
306
|
+
const folderOrganization = componentFiles.length > 0 ? folderedComponents.length / componentFiles.length * 100 : 0;
|
|
307
|
+
items.push({
|
|
308
|
+
name: "Organiza\xE7\xE3o por pastas",
|
|
309
|
+
passed: folderOrganization >= 60,
|
|
310
|
+
points: Math.round(folderOrganization / 100 * 5),
|
|
311
|
+
maxPoints: 5,
|
|
312
|
+
message: `${folderedComponents.length}/${componentFiles.length} componentes (${Math.round(folderOrganization)}%)`
|
|
313
|
+
});
|
|
314
|
+
const score = items.reduce((sum, item) => sum + item.points, 0);
|
|
315
|
+
const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
|
|
316
|
+
return {
|
|
317
|
+
name: "Nomenclatura",
|
|
318
|
+
score,
|
|
319
|
+
maxScore,
|
|
320
|
+
percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
|
|
321
|
+
items
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
async function analyzeDocumentation(projectPath, spinner) {
|
|
325
|
+
spinner.text = "Analisando documenta\xE7\xE3o...";
|
|
326
|
+
const items = [];
|
|
327
|
+
const hasReadme = fs.existsSync(path.join(projectPath, "README.md"));
|
|
328
|
+
items.push({
|
|
329
|
+
name: "README.md principal",
|
|
330
|
+
passed: hasReadme,
|
|
331
|
+
points: hasReadme ? 5 : 0,
|
|
332
|
+
maxPoints: 5,
|
|
333
|
+
message: hasReadme ? "README.md encontrado" : "README.md n\xE3o encontrado"
|
|
334
|
+
});
|
|
335
|
+
const hasComponentDocs = fs.existsSync(path.join(projectPath, "docs")) || fs.existsSync(path.join(projectPath, "documentation"));
|
|
336
|
+
items.push({
|
|
337
|
+
name: "Documenta\xE7\xE3o do projeto",
|
|
338
|
+
passed: hasComponentDocs,
|
|
339
|
+
points: hasComponentDocs ? 5 : 0,
|
|
340
|
+
maxPoints: 5,
|
|
341
|
+
message: hasComponentDocs ? "Diret\xF3rio de documenta\xE7\xE3o encontrado" : "Nenhum diret\xF3rio docs/ ou documentation/ encontrado"
|
|
342
|
+
});
|
|
343
|
+
const score = items.reduce((sum, item) => sum + item.points, 0);
|
|
344
|
+
const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
|
|
345
|
+
return {
|
|
346
|
+
name: "Documenta\xE7\xE3o",
|
|
347
|
+
score,
|
|
348
|
+
maxScore,
|
|
349
|
+
percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
|
|
350
|
+
items
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function findComponentsDirectory(projectPath) {
|
|
354
|
+
const possiblePaths = [
|
|
355
|
+
path.join(projectPath, "src", "components"),
|
|
356
|
+
path.join(projectPath, "components"),
|
|
357
|
+
path.join(projectPath, "src", "views"),
|
|
358
|
+
path.join(projectPath, "app", "components")
|
|
359
|
+
];
|
|
360
|
+
for (const p of possiblePaths) {
|
|
361
|
+
if (fs.existsSync(p)) {
|
|
362
|
+
return p;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
function countComponents(dir) {
|
|
368
|
+
return findAllComponents(dir).length;
|
|
369
|
+
}
|
|
370
|
+
function findAllComponents(dir) {
|
|
371
|
+
const components = [];
|
|
372
|
+
function walk(currentDir) {
|
|
373
|
+
if (!fs.existsSync(currentDir)) return;
|
|
374
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
375
|
+
for (const entry of entries) {
|
|
376
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
377
|
+
if (entry.isDirectory()) {
|
|
378
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
379
|
+
walk(fullPath);
|
|
380
|
+
} else if (entry.isFile()) {
|
|
381
|
+
const ext = path.extname(entry.name);
|
|
382
|
+
if (COMPONENT_EXTENSIONS.includes(ext)) {
|
|
383
|
+
const isTest = TEST_PATTERNS.some((pattern) => entry.name.includes(pattern));
|
|
384
|
+
const isStory = STORY_PATTERNS.some((pattern) => entry.name.includes(pattern));
|
|
385
|
+
const isAuxiliary = AUXILIARY_PATTERNS.some((pattern) => entry.name.endsWith(pattern));
|
|
386
|
+
const isBarrel = BARREL_FILES.includes(entry.name);
|
|
387
|
+
if (!isTest && !isStory && !isAuxiliary && !isBarrel) {
|
|
388
|
+
components.push(fullPath);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
walk(dir);
|
|
395
|
+
return components;
|
|
396
|
+
}
|
|
397
|
+
function findFilesByPattern(dir, patterns) {
|
|
398
|
+
const files = [];
|
|
399
|
+
function walk(currentDir) {
|
|
400
|
+
if (!fs.existsSync(currentDir)) return;
|
|
401
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
402
|
+
for (const entry of entries) {
|
|
403
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
404
|
+
if (entry.isDirectory()) {
|
|
405
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
406
|
+
walk(fullPath);
|
|
407
|
+
} else if (entry.isFile()) {
|
|
408
|
+
if (patterns.some((pattern) => entry.name.includes(pattern))) {
|
|
409
|
+
files.push(fullPath);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
walk(dir);
|
|
415
|
+
return files;
|
|
416
|
+
}
|
|
417
|
+
function hasFilesWithPattern(dir, pattern) {
|
|
418
|
+
function walk(currentDir) {
|
|
419
|
+
if (!fs.existsSync(currentDir)) return false;
|
|
420
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
421
|
+
for (const entry of entries) {
|
|
422
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
423
|
+
if (entry.isDirectory()) {
|
|
424
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
425
|
+
if (walk(fullPath)) return true;
|
|
426
|
+
} else if (entry.isFile()) {
|
|
427
|
+
if (pattern.test(entry.name)) return true;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
return walk(dir);
|
|
433
|
+
}
|
|
434
|
+
function stripExt(filePath) {
|
|
435
|
+
return filePath.replace(/\.[^.]+$/, "");
|
|
436
|
+
}
|
|
437
|
+
function stripTestSuffix(filePath, patterns) {
|
|
438
|
+
for (const pattern of patterns) {
|
|
439
|
+
if (filePath.includes(pattern)) {
|
|
440
|
+
return filePath.replace(pattern, "");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return stripExt(filePath);
|
|
444
|
+
}
|
|
445
|
+
function isVueFileUsingTypeScript(filePath) {
|
|
446
|
+
try {
|
|
447
|
+
if (!filePath.endsWith(".vue")) return false;
|
|
448
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
449
|
+
if (/<script\s+setup\s+lang=["']ts["']/.test(content)) return true;
|
|
450
|
+
if (/<script\s+lang=["']ts["']\s+setup/.test(content)) return true;
|
|
451
|
+
if (/<script\s+lang=["']ts["']/.test(content)) return true;
|
|
452
|
+
return false;
|
|
453
|
+
} catch {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function isFileUsingTypeScript(filePath) {
|
|
458
|
+
if (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) {
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
if (filePath.endsWith(".vue")) {
|
|
462
|
+
return isVueFileUsingTypeScript(filePath);
|
|
463
|
+
}
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
function generateSummary(percentage) {
|
|
467
|
+
if (percentage >= 90) return "Excelente! Projeto muito bem estruturado! \u{1F3C6}";
|
|
468
|
+
if (percentage >= 75) return "Muito bom! Algumas melhorias podem ser feitas. \u{1F3AF}";
|
|
469
|
+
if (percentage >= 60) return "Bom come\xE7o! H\xE1 espa\xE7o para melhorias. \u{1F4AA}";
|
|
470
|
+
if (percentage >= 40) return "Projeto precisa de melhorias significativas. \u26A0\uFE0F";
|
|
471
|
+
return "Projeto precisa de reestrutura\xE7\xE3o para seguir as melhores pr\xE1ticas. \u{1F527}";
|
|
472
|
+
}
|
|
473
|
+
function displayResults(result, options = {}) {
|
|
474
|
+
const { verbose = false } = options;
|
|
475
|
+
console.log("\n" + "=".repeat(60));
|
|
476
|
+
console.log(chalk.bold.cyan("\u{1F4CA} AN\xC1LISE DO PROJETO STORYTYPE"));
|
|
477
|
+
console.log("=".repeat(60) + "\n");
|
|
478
|
+
const scoreColor = result.percentage >= 75 ? chalk.green : result.percentage >= 60 ? chalk.yellow : chalk.red;
|
|
479
|
+
console.log(
|
|
480
|
+
chalk.bold("Score Geral: ") + scoreColor.bold(`${result.score}/${result.maxScore}`) + " " + scoreColor.bold(`(${result.percentage}%)`)
|
|
481
|
+
);
|
|
482
|
+
console.log(chalk.italic(result.summary) + "\n");
|
|
483
|
+
for (const category of result.categories) {
|
|
484
|
+
const catColor = category.percentage >= 75 ? chalk.green : category.percentage >= 60 ? chalk.yellow : chalk.red;
|
|
485
|
+
console.log(
|
|
486
|
+
chalk.bold(`
|
|
487
|
+
${category.name}: `) + catColor(`${category.score}/${category.maxScore}`) + catColor(` (${category.percentage}%)`)
|
|
488
|
+
);
|
|
489
|
+
for (const item of category.items) {
|
|
490
|
+
const icon = item.passed ? chalk.green("\u2713") : chalk.red("\u2717");
|
|
491
|
+
const points = item.passed ? chalk.green : chalk.gray;
|
|
492
|
+
console.log(` ${icon} ${item.name}: ${points(`${item.points}/${item.maxPoints} pts`)}`);
|
|
493
|
+
if (item.message) {
|
|
494
|
+
console.log(chalk.gray(` ${item.message}`));
|
|
495
|
+
}
|
|
496
|
+
if (verbose && !item.passed && item.fileIssues && item.fileIssues.length > 0) {
|
|
497
|
+
const MAX_SHOWN = 20;
|
|
498
|
+
const shown = item.fileIssues.slice(0, MAX_SHOWN);
|
|
499
|
+
for (const fi of shown) {
|
|
500
|
+
console.log(chalk.red(` \u2717 ${fi.file}`));
|
|
501
|
+
console.log(chalk.gray(` Problema: ${fi.issue}`));
|
|
502
|
+
console.log(chalk.cyan(` Como corrigir: ${fi.fix}`));
|
|
503
|
+
}
|
|
504
|
+
if (item.fileIssues.length > MAX_SHOWN) {
|
|
505
|
+
console.log(
|
|
506
|
+
chalk.gray(` ... e mais ${item.fileIssues.length - MAX_SHOWN} arquivos`)
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
console.log("\n" + "=".repeat(60) + "\n");
|
|
513
|
+
const recommendations = generateRecommendations(result);
|
|
514
|
+
if (recommendations.length > 0) {
|
|
515
|
+
console.log(chalk.bold.yellow("\u{1F4A1} Recomenda\xE7\xF5es:\n"));
|
|
516
|
+
recommendations.forEach((rec, index) => {
|
|
517
|
+
console.log(chalk.yellow(`${index + 1}. ${rec}`));
|
|
518
|
+
});
|
|
519
|
+
console.log();
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function generateRecommendations(result) {
|
|
523
|
+
const recommendations = [];
|
|
524
|
+
for (const category of result.categories) {
|
|
525
|
+
if (category.percentage < 60) {
|
|
526
|
+
for (const item of category.items) {
|
|
527
|
+
if (!item.passed) {
|
|
528
|
+
if (item.name === "N\xEDveis Atomic Design") {
|
|
529
|
+
recommendations.push(
|
|
530
|
+
"Organize seus componentes em n\xEDveis Atomic Design (atoms, molecules, organisms, templates, pages)"
|
|
531
|
+
);
|
|
532
|
+
} else if (item.name === "Componentes TypeScript") {
|
|
533
|
+
recommendations.push("Migre mais componentes para TypeScript para melhor type safety");
|
|
534
|
+
} else if (item.name === "Cobertura de testes") {
|
|
535
|
+
recommendations.push(
|
|
536
|
+
"Adicione mais testes unit\xE1rios para seus componentes (meta: 70%+)"
|
|
537
|
+
);
|
|
538
|
+
} else if (item.name === "Cobertura de stories") {
|
|
539
|
+
recommendations.push("Crie stories no Storybook para mais componentes (meta: 70%+)");
|
|
540
|
+
} else if (item.name === "Conven\xE7\xE3o PascalCase") {
|
|
541
|
+
recommendations.push("Use PascalCase para nomes de componentes (ex: MyComponent.vue)");
|
|
542
|
+
} else if (item.name === "README.md principal") {
|
|
543
|
+
recommendations.push("Adicione um arquivo README.md na raiz do projeto");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return recommendations.slice(0, 5);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export {
|
|
553
|
+
analyzeProject,
|
|
554
|
+
displayResults
|
|
555
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
analyzeProject,
|
|
4
4
|
displayResults
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-WOGXOJML.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { Command } from "commander";
|
|
9
|
+
import path3 from "path";
|
|
9
10
|
|
|
10
11
|
// package.json
|
|
11
|
-
var version = "0.2.
|
|
12
|
+
var version = "0.2.5";
|
|
12
13
|
|
|
13
14
|
// src/generate/Generate.ts
|
|
14
15
|
import fs from "fs-extra";
|
|
@@ -204,7 +205,7 @@ async function analyzeDirectory(dirPath, components, options) {
|
|
|
204
205
|
const componentName = getComponentBaseName(componentFile.name);
|
|
205
206
|
const pascalComponentName = toPascalCase2(componentName);
|
|
206
207
|
const dirName = path2.basename(dirPath);
|
|
207
|
-
const expectedDirName = toKebabCase2(
|
|
208
|
+
const expectedDirName = toKebabCase2(dirName);
|
|
208
209
|
const needsRename = dirName !== expectedDirName;
|
|
209
210
|
const files = [];
|
|
210
211
|
const existingFileNames = /* @__PURE__ */ new Set();
|
|
@@ -438,33 +439,56 @@ Componentes encontrados: ${result.components.length}`));
|
|
|
438
439
|
console.log(chalk.gray(`Diret\xF3rios a renomear: ${result.directoriesToRename}`));
|
|
439
440
|
console.log(chalk.gray(`Arquivos a renomear: ${result.filesToRename}`));
|
|
440
441
|
console.log(chalk.gray(`Arquivos a criar: ${result.filesToCreate}`));
|
|
441
|
-
if (options?.dryRun) {
|
|
442
|
-
console.log(chalk.
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
chalk.green("\n\u2713 Todos os componentes j\xE1 est\xE3o estruturados corretamente!")
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
if (options?.verbose) {
|
|
452
|
-
console.log(chalk.gray("\nMudan\xE7as detalhadas:"));
|
|
442
|
+
if ((options?.dryRun || options?.verbose) && result.directoriesToRename + result.filesToRename + result.filesToCreate > 0) {
|
|
443
|
+
console.log(chalk.cyan("\n\u{1F4CB} Mudan\xE7as detalhadas:\n"));
|
|
444
|
+
const cwd = process.cwd();
|
|
445
|
+
const relativePath = (absolutePath) => {
|
|
446
|
+
const rel = path3.relative(cwd, absolutePath);
|
|
447
|
+
return rel.startsWith("..") ? absolutePath : rel;
|
|
448
|
+
};
|
|
453
449
|
result.components.forEach((comp) => {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
450
|
+
const hasChanges = comp.needsRename || comp.missingFiles.length > 0 || comp.files.some((f) => f.currentPath !== f.targetPath);
|
|
451
|
+
if (hasChanges) {
|
|
452
|
+
console.log(chalk.bold(`
|
|
453
|
+
Componente: ${comp.componentName}`));
|
|
457
454
|
if (comp.needsRename) {
|
|
455
|
+
console.log(chalk.yellow(` \u{1F4C1} Renomear diret\xF3rio:`));
|
|
456
|
+
console.log(chalk.gray(` ${relativePath(comp.currentPath)}`));
|
|
457
|
+
console.log(chalk.gray(` \u2192 ${relativePath(comp.targetPath)}`));
|
|
458
|
+
}
|
|
459
|
+
const filesToRename = comp.files.filter((f) => f.currentPath !== f.targetPath);
|
|
460
|
+
if (filesToRename.length > 0) {
|
|
458
461
|
console.log(
|
|
459
|
-
chalk.yellow(` Renomear
|
|
462
|
+
chalk.yellow(` \u{1F4C4} Renomear arquivo${filesToRename.length > 1 ? "s" : ""}:`)
|
|
460
463
|
);
|
|
464
|
+
filesToRename.forEach((file) => {
|
|
465
|
+
console.log(chalk.gray(` ${relativePath(file.currentPath)}`));
|
|
466
|
+
console.log(chalk.gray(` \u2192 ${relativePath(file.targetPath)}`));
|
|
467
|
+
});
|
|
461
468
|
}
|
|
462
469
|
if (comp.missingFiles.length > 0) {
|
|
463
|
-
console.log(
|
|
470
|
+
console.log(
|
|
471
|
+
chalk.green(` \u2728 Criar arquivo${comp.missingFiles.length > 1 ? "s" : ""}:`)
|
|
472
|
+
);
|
|
473
|
+
comp.missingFiles.forEach((fileName) => {
|
|
474
|
+
const targetDir = comp.needsRename ? comp.targetPath : comp.currentPath;
|
|
475
|
+
const fullPath = `${targetDir}/${fileName}`;
|
|
476
|
+
console.log(chalk.gray(` ${relativePath(fullPath)}`));
|
|
477
|
+
});
|
|
464
478
|
}
|
|
465
479
|
}
|
|
466
480
|
});
|
|
467
481
|
}
|
|
482
|
+
if (options?.dryRun) {
|
|
483
|
+
console.log(chalk.yellow("\n\u26A0\uFE0F Modo dry-run: nenhuma mudan\xE7a foi feita"));
|
|
484
|
+
console.log(chalk.gray("Execute sem --dry-run para aplicar as mudan\xE7as\n"));
|
|
485
|
+
} else if (result.directoriesToRename + result.filesToRename + result.filesToCreate > 0) {
|
|
486
|
+
console.log(chalk.green("\n\u2713 Normaliza\xE7\xE3o conclu\xEDda com sucesso!"));
|
|
487
|
+
} else {
|
|
488
|
+
console.log(
|
|
489
|
+
chalk.green("\n\u2713 Todos os componentes j\xE1 est\xE3o estruturados corretamente!")
|
|
490
|
+
);
|
|
491
|
+
}
|
|
468
492
|
} else {
|
|
469
493
|
console.error(chalk.red(`
|
|
470
494
|
\u2717 Erro: ${result.error}`));
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storytype/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "CLI tool for scaffolding Storytype components and analyzing project structure",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -47,17 +47,6 @@
|
|
|
47
47
|
"src/templates",
|
|
48
48
|
"README.md"
|
|
49
49
|
],
|
|
50
|
-
"scripts": {
|
|
51
|
-
"build": "tsup src/cli.ts src/index.ts --format esm --dts && pnpm build:templates",
|
|
52
|
-
"build:templates": "mkdir -p dist/templates && cp -r src/templates/* dist/templates/",
|
|
53
|
-
"dev": "tsup src/cli.ts src/index.ts --format esm --dts --watch",
|
|
54
|
-
"clean": "rm -rf dist",
|
|
55
|
-
"lint": "tsc --noEmit",
|
|
56
|
-
"typecheck": "tsc --noEmit",
|
|
57
|
-
"test": "vitest run",
|
|
58
|
-
"test:watch": "vitest",
|
|
59
|
-
"prepublishOnly": "pnpm build"
|
|
60
|
-
},
|
|
61
50
|
"dependencies": {
|
|
62
51
|
"chalk": "^5.3.0",
|
|
63
52
|
"commander": "^12.0.0",
|
|
@@ -71,8 +60,20 @@
|
|
|
71
60
|
"@types/handlebars": "^4.1.0",
|
|
72
61
|
"@types/node": "^20.11.30",
|
|
73
62
|
"@types/prompts": "^2.4.9",
|
|
63
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
74
64
|
"tsup": "^8.0.2",
|
|
75
65
|
"typescript": "^5.4.5",
|
|
76
|
-
"vitest": "^1.
|
|
66
|
+
"vitest": "^4.1.5"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsup src/cli.ts src/index.ts --format esm --dts && pnpm build:templates",
|
|
70
|
+
"build:templates": "mkdir -p dist/templates && cp -r src/templates/* dist/templates/",
|
|
71
|
+
"dev": "tsup src/cli.ts src/index.ts --format esm --dts --watch",
|
|
72
|
+
"clean": "rm -rf dist",
|
|
73
|
+
"lint": "tsc --noEmit",
|
|
74
|
+
"typecheck": "tsc --noEmit",
|
|
75
|
+
"test": "vitest run --coverage",
|
|
76
|
+
"test:watch": "vitest",
|
|
77
|
+
"test:no-coverage": "vitest run"
|
|
77
78
|
}
|
|
78
|
-
}
|
|
79
|
+
}
|