@storytype/cli 0.2.4 → 0.3.0

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  analyzeProject,
3
3
  displayResults
4
- } from "./chunk-ROL3KHCC.js";
4
+ } from "./chunk-PNYCPIWD.js";
5
5
 
6
6
  // src/index.ts
7
7
  async function generateComponent(options) {
@@ -1,4 +1,4 @@
1
1
  export * from './{{pascalCase name}}.types';
2
- export * from './{{pascalCase name}}.mock';
3
- export * as Stories from './{{pascalCase name}}.stories';
4
- export { default } from './{{pascalCase name}}.vue';
2
+ {{#if hasMock}}export * from './{{pascalCase name}}.mock';
3
+ {{/if}}{{#if hasStories}}export * as Stories from './{{pascalCase name}}.stories';
4
+ {{/if}}export { default } from '{{entry}}';
@@ -0,0 +1,19 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ {{#if isVue}}import { mount } from '@vue/test-utils';
3
+ {{/if}}import {{pascalCase name}} from '{{entry}}';
4
+ {{#if hasMock}}import { generateMockData } from './{{pascalCase name}}.mock';
5
+ {{/if}}
6
+
7
+ describe('{{pascalCase name}}', () => {
8
+ {{#if isVue}} it('renderiza', () => {
9
+ const wrapper = mount({{pascalCase name}}{{#if hasMock}}, { props: generateMockData().props }{{/if}});
10
+
11
+ expect(wrapper.exists()).toBe(true);
12
+ });
13
+ {{else}} it('e definido', () => {
14
+ expect({{pascalCase name}}).toBeDefined();
15
+ });
16
+ {{/if}}
17
+
18
+ //TODO: Add tests here
19
+ });
@@ -1,9 +1,10 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3';
2
- import {{pascalCase name}} from './{{pascalCase name}}.vue';
3
- import { generateMockData } from './{{pascalCase name}}.mock';
2
+ import {{pascalCase name}} from '{{entry}}';
3
+ {{#if hasMock}}import { generateMockData } from './{{pascalCase name}}.mock';
4
+ {{/if}}
4
5
 
5
6
  const meta: Meta<typeof {{pascalCase name}}> = {
6
- title: '{{#if (eq type "atomos")}}01 - Átomos{{else if (eq type "moleculas")}}02 - Moléculas{{else if (eq type "organismos")}}03 - Organismos{{else if (eq type "templates")}}04 - Templates{{else}}05 - Pages{{/if}}/{{pascalCase name}}',
7
+ title: '{{section}}/{{pascalCase name}}',
7
8
  component: {{pascalCase name}},
8
9
  tags: ['autodocs'],
9
10
  parameters: {
@@ -18,7 +19,7 @@ const meta: Meta<typeof {{pascalCase name}}> = {
18
19
  export default meta;
19
20
  type Story = StoryObj<typeof meta>;
20
21
 
21
- const mockData = generateMockData();
22
+ {{#if hasMock}}const mockData = generateMockData();
22
23
 
23
24
  export const Default: Story = {
24
25
  args: {
@@ -26,3 +27,9 @@ export const Default: Story = {
26
27
  ...mockData.models,
27
28
  },
28
29
  };
30
+ {{else}}export const Default: Story = {
31
+ args: {
32
+ //TODO: Add args here
33
+ },
34
+ };
35
+ {{/if}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storytype/cli",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "CLI tool for scaffolding Storytype components and analyzing project structure",
5
5
  "keywords": [
6
6
  "cli",
@@ -53,9 +53,10 @@
53
53
  "dev": "tsup src/cli.ts src/index.ts --format esm --dts --watch",
54
54
  "clean": "rm -rf dist",
55
55
  "lint": "tsc --noEmit",
56
- "typecheck": "tsc --noEmit",
57
- "test": "vitest run",
56
+ "typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
57
+ "test": "vitest run --coverage",
58
58
  "test:watch": "vitest",
59
+ "test:no-coverage": "vitest run",
59
60
  "prepublishOnly": "pnpm build"
60
61
  },
61
62
  "dependencies": {
@@ -68,11 +69,11 @@
68
69
  },
69
70
  "devDependencies": {
70
71
  "@types/fs-extra": "^11.0.4",
71
- "@types/handlebars": "^4.1.0",
72
72
  "@types/node": "^20.11.30",
73
73
  "@types/prompts": "^2.4.9",
74
+ "@vitest/coverage-v8": "^4.1.5",
74
75
  "tsup": "^8.0.2",
75
76
  "typescript": "^5.4.5",
76
- "vitest": "^1.6.0"
77
+ "vitest": "^4.1.5"
77
78
  }
78
79
  }
@@ -1,4 +1,4 @@
1
1
  export * from './{{pascalCase name}}.types';
2
- export * from './{{pascalCase name}}.mock';
3
- export * as Stories from './{{pascalCase name}}.stories';
4
- export { default } from './{{pascalCase name}}.vue';
2
+ {{#if hasMock}}export * from './{{pascalCase name}}.mock';
3
+ {{/if}}{{#if hasStories}}export * as Stories from './{{pascalCase name}}.stories';
4
+ {{/if}}export { default } from '{{entry}}';
@@ -0,0 +1,19 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ {{#if isVue}}import { mount } from '@vue/test-utils';
3
+ {{/if}}import {{pascalCase name}} from '{{entry}}';
4
+ {{#if hasMock}}import { generateMockData } from './{{pascalCase name}}.mock';
5
+ {{/if}}
6
+
7
+ describe('{{pascalCase name}}', () => {
8
+ {{#if isVue}} it('renderiza', () => {
9
+ const wrapper = mount({{pascalCase name}}{{#if hasMock}}, { props: generateMockData().props }{{/if}});
10
+
11
+ expect(wrapper.exists()).toBe(true);
12
+ });
13
+ {{else}} it('e definido', () => {
14
+ expect({{pascalCase name}}).toBeDefined();
15
+ });
16
+ {{/if}}
17
+
18
+ //TODO: Add tests here
19
+ });
@@ -1,9 +1,10 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3';
2
- import {{pascalCase name}} from './{{pascalCase name}}.vue';
3
- import { generateMockData } from './{{pascalCase name}}.mock';
2
+ import {{pascalCase name}} from '{{entry}}';
3
+ {{#if hasMock}}import { generateMockData } from './{{pascalCase name}}.mock';
4
+ {{/if}}
4
5
 
5
6
  const meta: Meta<typeof {{pascalCase name}}> = {
6
- title: '{{#if (eq type "atomos")}}01 - Átomos{{else if (eq type "moleculas")}}02 - Moléculas{{else if (eq type "organismos")}}03 - Organismos{{else if (eq type "templates")}}04 - Templates{{else}}05 - Pages{{/if}}/{{pascalCase name}}',
7
+ title: '{{section}}/{{pascalCase name}}',
7
8
  component: {{pascalCase name}},
8
9
  tags: ['autodocs'],
9
10
  parameters: {
@@ -18,7 +19,7 @@ const meta: Meta<typeof {{pascalCase name}}> = {
18
19
  export default meta;
19
20
  type Story = StoryObj<typeof meta>;
20
21
 
21
- const mockData = generateMockData();
22
+ {{#if hasMock}}const mockData = generateMockData();
22
23
 
23
24
  export const Default: Story = {
24
25
  args: {
@@ -26,3 +27,9 @@ export const Default: Story = {
26
27
  ...mockData.models,
27
28
  },
28
29
  };
30
+ {{else}}export const Default: Story = {
31
+ args: {
32
+ //TODO: Add args here
33
+ },
34
+ };
35
+ {{/if}}
@@ -1,507 +0,0 @@
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
- async function analyzeProject(projectPath = process.cwd()) {
11
- const spinner = ora("Analisando projeto...").start();
12
- try {
13
- const categories = [];
14
- categories.push(await analyzeStructure(projectPath, spinner));
15
- categories.push(await analyzeTypeScript(projectPath, spinner));
16
- categories.push(await analyzeTestsAndStories(projectPath, spinner));
17
- categories.push(await analyzeNaming(projectPath, spinner));
18
- categories.push(await analyzeDocumentation(projectPath, spinner));
19
- const totalScore = categories.reduce((sum, cat) => sum + cat.score, 0);
20
- const maxScore = categories.reduce((sum, cat) => sum + cat.maxScore, 0);
21
- const percentage = maxScore > 0 ? Math.round(totalScore / maxScore * 100) : 0;
22
- spinner.succeed("An\xE1lise completa!");
23
- return {
24
- score: totalScore,
25
- maxScore,
26
- percentage,
27
- categories,
28
- summary: generateSummary(percentage)
29
- };
30
- } catch (error) {
31
- spinner.fail("Erro ao analisar projeto");
32
- throw error;
33
- }
34
- }
35
- async function analyzeStructure(projectPath, spinner) {
36
- spinner.text = "Analisando estrutura Atomic Design...";
37
- const items = [];
38
- const componentsPath = findComponentsDirectory(projectPath);
39
- if (!componentsPath) {
40
- items.push({
41
- name: "Diret\xF3rio de componentes",
42
- passed: false,
43
- points: 0,
44
- maxPoints: 10,
45
- message: "Nenhum diret\xF3rio de componentes encontrado (src/components, components, etc.)"
46
- });
47
- return {
48
- name: "Estrutura Atomic Design",
49
- score: 0,
50
- maxScore: 50,
51
- percentage: 0,
52
- items
53
- };
54
- }
55
- const foundLevels = ATOMIC_LEVELS.filter(
56
- (level) => fs.existsSync(path.join(componentsPath, level))
57
- );
58
- items.push({
59
- name: "Diret\xF3rio de componentes",
60
- passed: true,
61
- points: 10,
62
- maxPoints: 10,
63
- message: `Encontrado em: ${path.relative(projectPath, componentsPath)}`
64
- });
65
- items.push({
66
- name: "N\xEDveis Atomic Design",
67
- passed: foundLevels.length >= 3,
68
- points: foundLevels.length * 5,
69
- maxPoints: 25,
70
- message: `Encontrados: ${foundLevels.join(", ") || "nenhum"} (${foundLevels.length}/5)`
71
- });
72
- const totalComponents = countComponents(componentsPath);
73
- const wellOrganized = foundLevels.length >= 3 && totalComponents >= 3;
74
- items.push({
75
- name: "Organiza\xE7\xE3o de componentes",
76
- passed: wellOrganized,
77
- points: wellOrganized ? 15 : Math.min(totalComponents * 3, 15),
78
- maxPoints: 15,
79
- message: `${totalComponents} componentes encontrados`
80
- });
81
- const score = items.reduce((sum, item) => sum + item.points, 0);
82
- const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
83
- return {
84
- name: "Estrutura Atomic Design",
85
- score,
86
- maxScore,
87
- percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
88
- items
89
- };
90
- }
91
- async function analyzeTypeScript(projectPath, spinner) {
92
- spinner.text = "Analisando uso de TypeScript...";
93
- const items = [];
94
- const hasTsConfig = fs.existsSync(path.join(projectPath, "tsconfig.json"));
95
- items.push({
96
- name: "Configura\xE7\xE3o TypeScript",
97
- passed: hasTsConfig,
98
- points: hasTsConfig ? 10 : 0,
99
- maxPoints: 10,
100
- message: hasTsConfig ? "tsconfig.json encontrado" : "tsconfig.json n\xE3o encontrado"
101
- });
102
- const componentsPath = findComponentsDirectory(projectPath);
103
- if (componentsPath) {
104
- const allComponents = findAllComponents(componentsPath);
105
- const tsComponents = allComponents.filter((f) => f.endsWith(".ts") || f.endsWith(".tsx"));
106
- const nonTsComponents = allComponents.filter((f) => !f.endsWith(".ts") && !f.endsWith(".tsx"));
107
- const total = allComponents.length;
108
- const typescript = tsComponents.length;
109
- const tsPercentage = total > 0 ? typescript / total * 100 : 0;
110
- items.push({
111
- name: "Componentes TypeScript",
112
- passed: tsPercentage >= 80,
113
- points: Math.round(tsPercentage / 100 * 15),
114
- maxPoints: 15,
115
- message: `${typescript}/${total} componentes (${Math.round(tsPercentage)}%)`,
116
- fileIssues: nonTsComponents.map((f) => ({
117
- file: f,
118
- issue: `Arquivo n\xE3o usa TypeScript: "${path.basename(f)}"`,
119
- fix: `Renomeie para "${path.basename(f, path.extname(f))}.ts" e adicione tipagem`
120
- }))
121
- });
122
- } else {
123
- items.push({
124
- name: "Componentes TypeScript",
125
- passed: false,
126
- points: 0,
127
- maxPoints: 15,
128
- message: "Diret\xF3rio de componentes n\xE3o encontrado"
129
- });
130
- }
131
- const hasTypesDir = componentsPath && fs.existsSync(path.join(componentsPath, "types"));
132
- const hasTypesFiles = componentsPath && hasFilesWithPattern(componentsPath, /types\.ts$/i);
133
- items.push({
134
- name: "Arquivos de tipos",
135
- passed: Boolean(hasTypesDir || hasTypesFiles),
136
- points: hasTypesDir || hasTypesFiles ? 5 : 0,
137
- maxPoints: 5,
138
- message: hasTypesDir ? "Diret\xF3rio types/ encontrado" : hasTypesFiles ? "Arquivos types.ts encontrados" : "Nenhum arquivo de tipos dedicado"
139
- });
140
- const score = items.reduce((sum, item) => sum + item.points, 0);
141
- const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
142
- return {
143
- name: "TypeScript",
144
- score,
145
- maxScore,
146
- percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
147
- items
148
- };
149
- }
150
- async function analyzeTestsAndStories(projectPath, spinner) {
151
- spinner.text = "Analisando testes e stories...";
152
- const items = [];
153
- const componentsPath = findComponentsDirectory(projectPath);
154
- if (!componentsPath) {
155
- return {
156
- name: "Testes e Stories",
157
- score: 0,
158
- maxScore: 30,
159
- percentage: 0,
160
- items: [
161
- {
162
- name: "Cobertura de testes",
163
- passed: false,
164
- points: 0,
165
- maxPoints: 15,
166
- message: "Diret\xF3rio de componentes n\xE3o encontrado"
167
- },
168
- {
169
- name: "Cobertura de stories",
170
- passed: false,
171
- points: 0,
172
- maxPoints: 15,
173
- message: "Diret\xF3rio de componentes n\xE3o encontrado"
174
- }
175
- ]
176
- };
177
- }
178
- const componentFiles = findAllComponents(componentsPath);
179
- const testFiles = findFilesByPattern(componentsPath, TEST_PATTERNS);
180
- const storyFiles = findFilesByPattern(componentsPath, STORY_PATTERNS);
181
- const testFileBases = new Set(testFiles.map((f) => stripTestSuffix(f, TEST_PATTERNS)));
182
- const storyFileBases = new Set(storyFiles.map((f) => stripTestSuffix(f, STORY_PATTERNS)));
183
- const componentsMissingTests = componentFiles.filter((f) => !testFileBases.has(stripExt(f)));
184
- const componentsMissingStories = componentFiles.filter((f) => !storyFileBases.has(stripExt(f)));
185
- const testCoverage = componentFiles.length > 0 ? testFiles.length / componentFiles.length * 100 : 0;
186
- const storyCoverage = componentFiles.length > 0 ? storyFiles.length / componentFiles.length * 100 : 0;
187
- items.push({
188
- name: "Cobertura de testes",
189
- passed: testCoverage >= 70,
190
- points: Math.round(Math.min(testCoverage, 100) / 100 * 15),
191
- maxPoints: 15,
192
- message: `${testFiles.length}/${componentFiles.length} componentes (${Math.round(testCoverage)}%)`,
193
- fileIssues: componentsMissingTests.map((f) => ({
194
- file: f,
195
- issue: "Sem arquivo de teste",
196
- fix: `Crie ${path.join(path.dirname(f), path.basename(f, path.extname(f)) + ".spec.ts")}`
197
- }))
198
- });
199
- items.push({
200
- name: "Cobertura de stories",
201
- passed: storyCoverage >= 70,
202
- points: Math.round(Math.min(storyCoverage, 100) / 100 * 15),
203
- maxPoints: 15,
204
- message: `${storyFiles.length}/${componentFiles.length} componentes (${Math.round(storyCoverage)}%)`,
205
- fileIssues: componentsMissingStories.map((f) => ({
206
- file: f,
207
- issue: "Sem arquivo de story",
208
- fix: `Crie ${path.join(path.dirname(f), path.basename(f, path.extname(f)) + ".stories.ts")}`
209
- }))
210
- });
211
- const score = items.reduce((sum, item) => sum + item.points, 0);
212
- const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
213
- return {
214
- name: "Testes e Stories",
215
- score,
216
- maxScore,
217
- percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
218
- items
219
- };
220
- }
221
- async function analyzeNaming(projectPath, spinner) {
222
- spinner.text = "Analisando nomenclatura...";
223
- const items = [];
224
- const componentsPath = findComponentsDirectory(projectPath);
225
- if (!componentsPath) {
226
- return {
227
- name: "Nomenclatura",
228
- score: 0,
229
- maxScore: 15,
230
- percentage: 0,
231
- items: [
232
- {
233
- name: "Conven\xE7\xE3o PascalCase",
234
- passed: false,
235
- points: 0,
236
- maxPoints: 10,
237
- message: "Diret\xF3rio de componentes n\xE3o encontrado"
238
- },
239
- {
240
- name: "Organiza\xE7\xE3o por pastas",
241
- passed: false,
242
- points: 0,
243
- maxPoints: 5,
244
- message: "Diret\xF3rio de componentes n\xE3o encontrado"
245
- }
246
- ]
247
- };
248
- }
249
- const componentFiles = findAllComponents(componentsPath);
250
- const pascalCaseFiles = componentFiles.filter((file) => {
251
- const fileName = path.basename(file, path.extname(file));
252
- return /^[A-Z][a-zA-Z0-9]*$/.test(fileName);
253
- });
254
- const nonPascalFiles = componentFiles.filter((file) => {
255
- const fileName = path.basename(file, path.extname(file));
256
- return !/^[A-Z][a-zA-Z0-9]*$/.test(fileName);
257
- });
258
- const pascalCasePercentage = componentFiles.length > 0 ? pascalCaseFiles.length / componentFiles.length * 100 : 0;
259
- items.push({
260
- name: "Conven\xE7\xE3o PascalCase",
261
- passed: pascalCasePercentage >= 90,
262
- points: Math.round(pascalCasePercentage / 100 * 10),
263
- maxPoints: 10,
264
- message: `${pascalCaseFiles.length}/${componentFiles.length} componentes (${Math.round(pascalCasePercentage)}%)`,
265
- fileIssues: nonPascalFiles.map((f) => {
266
- const oldName = path.basename(f);
267
- const ext = path.extname(f);
268
- const baseName = path.basename(f, ext);
269
- const pascalName = baseName.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase());
270
- return {
271
- file: f,
272
- issue: `Nome em formato incorreto: "${oldName}"`,
273
- fix: `Renomeie para "${pascalName}${ext}"`
274
- };
275
- })
276
- });
277
- const folderedComponents = componentFiles.filter((file) => {
278
- const dir = path.dirname(file);
279
- const fileName = path.basename(file, path.extname(file));
280
- const parentFolder = path.basename(dir);
281
- return fileName === parentFolder || fileName === "index";
282
- });
283
- const folderOrganization = componentFiles.length > 0 ? folderedComponents.length / componentFiles.length * 100 : 0;
284
- items.push({
285
- name: "Organiza\xE7\xE3o por pastas",
286
- passed: folderOrganization >= 60,
287
- points: Math.round(folderOrganization / 100 * 5),
288
- maxPoints: 5,
289
- message: `${folderedComponents.length}/${componentFiles.length} componentes (${Math.round(folderOrganization)}%)`
290
- });
291
- const score = items.reduce((sum, item) => sum + item.points, 0);
292
- const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
293
- return {
294
- name: "Nomenclatura",
295
- score,
296
- maxScore,
297
- percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
298
- items
299
- };
300
- }
301
- async function analyzeDocumentation(projectPath, spinner) {
302
- spinner.text = "Analisando documenta\xE7\xE3o...";
303
- const items = [];
304
- const hasReadme = fs.existsSync(path.join(projectPath, "README.md"));
305
- items.push({
306
- name: "README.md principal",
307
- passed: hasReadme,
308
- points: hasReadme ? 5 : 0,
309
- maxPoints: 5,
310
- message: hasReadme ? "README.md encontrado" : "README.md n\xE3o encontrado"
311
- });
312
- const hasComponentDocs = fs.existsSync(path.join(projectPath, "docs")) || fs.existsSync(path.join(projectPath, "documentation"));
313
- items.push({
314
- name: "Documenta\xE7\xE3o do projeto",
315
- passed: hasComponentDocs,
316
- points: hasComponentDocs ? 5 : 0,
317
- maxPoints: 5,
318
- message: hasComponentDocs ? "Diret\xF3rio de documenta\xE7\xE3o encontrado" : "Nenhum diret\xF3rio docs/ ou documentation/ encontrado"
319
- });
320
- const score = items.reduce((sum, item) => sum + item.points, 0);
321
- const maxScore = items.reduce((sum, item) => sum + item.maxPoints, 0);
322
- return {
323
- name: "Documenta\xE7\xE3o",
324
- score,
325
- maxScore,
326
- percentage: maxScore > 0 ? Math.round(score / maxScore * 100) : 0,
327
- items
328
- };
329
- }
330
- function findComponentsDirectory(projectPath) {
331
- const possiblePaths = [
332
- path.join(projectPath, "src", "components"),
333
- path.join(projectPath, "components"),
334
- path.join(projectPath, "src", "views"),
335
- path.join(projectPath, "app", "components")
336
- ];
337
- for (const p of possiblePaths) {
338
- if (fs.existsSync(p)) {
339
- return p;
340
- }
341
- }
342
- return null;
343
- }
344
- function countComponents(dir) {
345
- return findAllComponents(dir).length;
346
- }
347
- function findAllComponents(dir) {
348
- const components = [];
349
- function walk(currentDir) {
350
- if (!fs.existsSync(currentDir)) return;
351
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
352
- for (const entry of entries) {
353
- const fullPath = path.join(currentDir, entry.name);
354
- if (entry.isDirectory()) {
355
- if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
356
- walk(fullPath);
357
- } else if (entry.isFile()) {
358
- const ext = path.extname(entry.name);
359
- if (COMPONENT_EXTENSIONS.includes(ext)) {
360
- const isTest = TEST_PATTERNS.some((pattern) => entry.name.includes(pattern));
361
- const isStory = STORY_PATTERNS.some((pattern) => entry.name.includes(pattern));
362
- if (!isTest && !isStory) {
363
- components.push(fullPath);
364
- }
365
- }
366
- }
367
- }
368
- }
369
- walk(dir);
370
- return components;
371
- }
372
- function findFilesByPattern(dir, patterns) {
373
- const files = [];
374
- function walk(currentDir) {
375
- if (!fs.existsSync(currentDir)) return;
376
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
377
- for (const entry of entries) {
378
- const fullPath = path.join(currentDir, entry.name);
379
- if (entry.isDirectory()) {
380
- if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
381
- walk(fullPath);
382
- } else if (entry.isFile()) {
383
- if (patterns.some((pattern) => entry.name.includes(pattern))) {
384
- files.push(fullPath);
385
- }
386
- }
387
- }
388
- }
389
- walk(dir);
390
- return files;
391
- }
392
- function hasFilesWithPattern(dir, pattern) {
393
- function walk(currentDir) {
394
- if (!fs.existsSync(currentDir)) return false;
395
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
396
- for (const entry of entries) {
397
- const fullPath = path.join(currentDir, entry.name);
398
- if (entry.isDirectory()) {
399
- if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
400
- if (walk(fullPath)) return true;
401
- } else if (entry.isFile()) {
402
- if (pattern.test(entry.name)) return true;
403
- }
404
- }
405
- return false;
406
- }
407
- return walk(dir);
408
- }
409
- function stripExt(filePath) {
410
- return filePath.replace(/\.[^.]+$/, "");
411
- }
412
- function stripTestSuffix(filePath, patterns) {
413
- for (const pattern of patterns) {
414
- if (filePath.includes(pattern)) {
415
- return filePath.replace(pattern, "");
416
- }
417
- }
418
- return stripExt(filePath);
419
- }
420
- function generateSummary(percentage) {
421
- if (percentage >= 90) return "Excelente! Projeto muito bem estruturado! \u{1F3C6}";
422
- if (percentage >= 75) return "Muito bom! Algumas melhorias podem ser feitas. \u{1F3AF}";
423
- if (percentage >= 60) return "Bom come\xE7o! H\xE1 espa\xE7o para melhorias. \u{1F4AA}";
424
- if (percentage >= 40) return "Projeto precisa de melhorias significativas. \u26A0\uFE0F";
425
- return "Projeto precisa de reestrutura\xE7\xE3o para seguir as melhores pr\xE1ticas. \u{1F527}";
426
- }
427
- function displayResults(result, options = {}) {
428
- const { verbose = false } = options;
429
- console.log("\n" + "=".repeat(60));
430
- console.log(chalk.bold.cyan("\u{1F4CA} AN\xC1LISE DO PROJETO STORYTYPE"));
431
- console.log("=".repeat(60) + "\n");
432
- const scoreColor = result.percentage >= 75 ? chalk.green : result.percentage >= 60 ? chalk.yellow : chalk.red;
433
- console.log(
434
- chalk.bold("Score Geral: ") + scoreColor.bold(`${result.score}/${result.maxScore}`) + " " + scoreColor.bold(`(${result.percentage}%)`)
435
- );
436
- console.log(chalk.italic(result.summary) + "\n");
437
- for (const category of result.categories) {
438
- const catColor = category.percentage >= 75 ? chalk.green : category.percentage >= 60 ? chalk.yellow : chalk.red;
439
- console.log(
440
- chalk.bold(`
441
- ${category.name}: `) + catColor(`${category.score}/${category.maxScore}`) + catColor(` (${category.percentage}%)`)
442
- );
443
- for (const item of category.items) {
444
- const icon = item.passed ? chalk.green("\u2713") : chalk.red("\u2717");
445
- const points = item.passed ? chalk.green : chalk.gray;
446
- console.log(` ${icon} ${item.name}: ${points(`${item.points}/${item.maxPoints} pts`)}`);
447
- if (item.message) {
448
- console.log(chalk.gray(` ${item.message}`));
449
- }
450
- if (verbose && !item.passed && item.fileIssues && item.fileIssues.length > 0) {
451
- const MAX_SHOWN = 20;
452
- const shown = item.fileIssues.slice(0, MAX_SHOWN);
453
- for (const fi of shown) {
454
- console.log(chalk.red(` \u2717 ${fi.file}`));
455
- console.log(chalk.gray(` Problema: ${fi.issue}`));
456
- console.log(chalk.cyan(` Como corrigir: ${fi.fix}`));
457
- }
458
- if (item.fileIssues.length > MAX_SHOWN) {
459
- console.log(chalk.gray(` ... e mais ${item.fileIssues.length - MAX_SHOWN} arquivos`));
460
- }
461
- }
462
- }
463
- }
464
- console.log("\n" + "=".repeat(60) + "\n");
465
- const recommendations = generateRecommendations(result);
466
- if (recommendations.length > 0) {
467
- console.log(chalk.bold.yellow("\u{1F4A1} Recomenda\xE7\xF5es:\n"));
468
- recommendations.forEach((rec, index) => {
469
- console.log(chalk.yellow(`${index + 1}. ${rec}`));
470
- });
471
- console.log();
472
- }
473
- }
474
- function generateRecommendations(result) {
475
- const recommendations = [];
476
- for (const category of result.categories) {
477
- if (category.percentage < 60) {
478
- for (const item of category.items) {
479
- if (!item.passed) {
480
- if (item.name === "N\xEDveis Atomic Design") {
481
- recommendations.push(
482
- "Organize seus componentes em n\xEDveis Atomic Design (atoms, molecules, organisms, templates, pages)"
483
- );
484
- } else if (item.name === "Componentes TypeScript") {
485
- recommendations.push("Migre mais componentes para TypeScript para melhor type safety");
486
- } else if (item.name === "Cobertura de testes") {
487
- recommendations.push(
488
- "Adicione mais testes unit\xE1rios para seus componentes (meta: 70%+)"
489
- );
490
- } else if (item.name === "Cobertura de stories") {
491
- recommendations.push("Crie stories no Storybook para mais componentes (meta: 70%+)");
492
- } else if (item.name === "Conven\xE7\xE3o PascalCase") {
493
- recommendations.push("Use PascalCase para nomes de componentes (ex: MyComponent.vue)");
494
- } else if (item.name === "README.md principal") {
495
- recommendations.push("Adicione um arquivo README.md na raiz do projeto");
496
- }
497
- }
498
- }
499
- }
500
- }
501
- return recommendations.slice(0, 5);
502
- }
503
-
504
- export {
505
- analyzeProject,
506
- displayResults
507
- };