@storytype/cli 0.2.3
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/README.md +282 -0
- package/dist/chunk-6DCDOH2S.js +507 -0
- package/dist/chunk-B35YCGV4.js +509 -0
- package/dist/chunk-C3R5YJAX.js +452 -0
- package/dist/chunk-IKQA7RO2.js +460 -0
- package/dist/chunk-MCTEMBK5.js +460 -0
- package/dist/chunk-ROL3KHCC.js +544 -0
- package/dist/chunk-U5YZ7DDR.js +523 -0
- package/dist/chunk-YXHZ2IEP.js +518 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +491 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +18 -0
- package/dist/templates/component/component.vue.hbs +20 -0
- package/dist/templates/component/index.ts.hbs +4 -0
- package/dist/templates/component/mock.ts.hbs +21 -0
- package/dist/templates/component/stories.ts.hbs +28 -0
- package/dist/templates/component/types.ts.hbs +17 -0
- package/package.json +78 -0
- package/src/templates/component/component.vue.hbs +20 -0
- package/src/templates/component/index.ts.hbs +4 -0
- package/src/templates/component/mock.ts.hbs +21 -0
- package/src/templates/component/stories.ts.hbs +28 -0
- package/src/templates/component/types.ts.hbs +17 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
analyzeProject,
|
|
4
|
+
displayResults
|
|
5
|
+
} from "./chunk-ROL3KHCC.js";
|
|
6
|
+
|
|
7
|
+
// src/cli.ts
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
|
|
10
|
+
// package.json
|
|
11
|
+
var version = "0.2.3";
|
|
12
|
+
|
|
13
|
+
// src/generate/Generate.ts
|
|
14
|
+
import fs from "fs-extra";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import { fileURLToPath } from "url";
|
|
17
|
+
import Handlebars from "handlebars";
|
|
18
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
var __dirname = path.dirname(__filename);
|
|
20
|
+
function toKebabCase(str) {
|
|
21
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
function toPascalCase(str) {
|
|
24
|
+
if (/^[A-Z][a-zA-Z0-9]*$/.test(str)) {
|
|
25
|
+
return str;
|
|
26
|
+
}
|
|
27
|
+
const withHyphens = str.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
28
|
+
return withHyphens.split(/[-_\s]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
29
|
+
}
|
|
30
|
+
Handlebars.registerHelper("kebabCase", (str) => toKebabCase(str));
|
|
31
|
+
Handlebars.registerHelper("pascalCase", (str) => toPascalCase(str));
|
|
32
|
+
Handlebars.registerHelper("eq", (a, b) => a === b);
|
|
33
|
+
function getTemplateDir() {
|
|
34
|
+
const possiblePaths = [
|
|
35
|
+
// Development (from dist/generate to src/templates)
|
|
36
|
+
path.join(__dirname, "..", "templates", "component"),
|
|
37
|
+
// Production build (dist/templates adjacent to dist/)
|
|
38
|
+
path.join(__dirname, "..", "..", "templates", "component"),
|
|
39
|
+
// From src/generate to src/templates
|
|
40
|
+
path.join(__dirname, "..", "..", "src", "templates", "component"),
|
|
41
|
+
// Global install
|
|
42
|
+
path.join(__dirname, "templates", "component")
|
|
43
|
+
];
|
|
44
|
+
for (const templatePath of possiblePaths) {
|
|
45
|
+
if (fs.existsSync(templatePath)) {
|
|
46
|
+
return templatePath;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Template directory not found. Searched paths: ${possiblePaths.join(", ")}`);
|
|
50
|
+
}
|
|
51
|
+
async function compileTemplate(templateName, data) {
|
|
52
|
+
const templateDir = getTemplateDir();
|
|
53
|
+
const templatePath = path.join(templateDir, templateName);
|
|
54
|
+
const templateContent = await fs.readFile(templatePath, "utf-8");
|
|
55
|
+
const template = Handlebars.compile(templateContent);
|
|
56
|
+
return template(data);
|
|
57
|
+
}
|
|
58
|
+
async function generateVueTemplate(componentName, type) {
|
|
59
|
+
return compileTemplate("component.vue.hbs", { name: componentName, type });
|
|
60
|
+
}
|
|
61
|
+
async function generateTypesFile(componentName) {
|
|
62
|
+
return compileTemplate("types.ts.hbs", { name: componentName });
|
|
63
|
+
}
|
|
64
|
+
async function generateStoriesFile(componentName, type) {
|
|
65
|
+
return compileTemplate("stories.ts.hbs", { name: componentName, type });
|
|
66
|
+
}
|
|
67
|
+
async function generateMockFile(componentName) {
|
|
68
|
+
return compileTemplate("mock.ts.hbs", { name: componentName });
|
|
69
|
+
}
|
|
70
|
+
async function generateIndexFile(componentName) {
|
|
71
|
+
return compileTemplate("index.ts.hbs", { name: componentName });
|
|
72
|
+
}
|
|
73
|
+
async function generateComponent(options) {
|
|
74
|
+
try {
|
|
75
|
+
const componentName = toPascalCase(options.name);
|
|
76
|
+
const dirName = toKebabCase(options.name);
|
|
77
|
+
const basePath = options.path || process.cwd();
|
|
78
|
+
const componentDir = path.join(basePath, options.type, dirName);
|
|
79
|
+
await fs.ensureDir(componentDir);
|
|
80
|
+
const files = [];
|
|
81
|
+
const vueFile = path.join(componentDir, `${componentName}.vue`);
|
|
82
|
+
await fs.writeFile(vueFile, await generateVueTemplate(componentName, options.type));
|
|
83
|
+
files.push(vueFile);
|
|
84
|
+
const typesFile = path.join(componentDir, `${componentName}.types.ts`);
|
|
85
|
+
await fs.writeFile(typesFile, await generateTypesFile(componentName));
|
|
86
|
+
files.push(typesFile);
|
|
87
|
+
const storiesFile = path.join(componentDir, `${componentName}.stories.ts`);
|
|
88
|
+
await fs.writeFile(storiesFile, await generateStoriesFile(componentName, options.type));
|
|
89
|
+
files.push(storiesFile);
|
|
90
|
+
const mockFile = path.join(componentDir, `${componentName}.mock.ts`);
|
|
91
|
+
await fs.writeFile(mockFile, await generateMockFile(componentName));
|
|
92
|
+
files.push(mockFile);
|
|
93
|
+
const indexFile = path.join(componentDir, "index.ts");
|
|
94
|
+
await fs.writeFile(indexFile, await generateIndexFile(componentName));
|
|
95
|
+
files.push(indexFile);
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
files
|
|
99
|
+
};
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return {
|
|
102
|
+
success: false,
|
|
103
|
+
files: [],
|
|
104
|
+
error: error instanceof Error ? error.message : String(error)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/normalize-components/NormalizeComponents.ts
|
|
110
|
+
import fs2 from "fs-extra";
|
|
111
|
+
import path2 from "path";
|
|
112
|
+
import { exec } from "child_process";
|
|
113
|
+
import { promisify } from "util";
|
|
114
|
+
var execAsync = promisify(exec);
|
|
115
|
+
function isCaseOnlyChange(from, to) {
|
|
116
|
+
return from.toLowerCase() === to.toLowerCase() && from !== to;
|
|
117
|
+
}
|
|
118
|
+
function toKebabCase2(str) {
|
|
119
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
120
|
+
}
|
|
121
|
+
function toPascalCase2(str) {
|
|
122
|
+
if (/^[A-Z][a-zA-Z0-9]*$/.test(str)) {
|
|
123
|
+
return str;
|
|
124
|
+
}
|
|
125
|
+
const withHyphens = str.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
126
|
+
return withHyphens.split(/[-_\s]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
127
|
+
}
|
|
128
|
+
async function isGitTracked(filePath) {
|
|
129
|
+
try {
|
|
130
|
+
const { stdout } = await execAsync(`git ls-files --error-unmatch "${filePath}"`, {
|
|
131
|
+
cwd: path2.dirname(filePath)
|
|
132
|
+
});
|
|
133
|
+
return stdout.trim().length > 0;
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function gitMoveManual(fromPath, toPath, isCaseOnly) {
|
|
139
|
+
const cwd = path2.dirname(fromPath);
|
|
140
|
+
if (isCaseOnly) {
|
|
141
|
+
const tempPath = `${toPath}-temp-rename`;
|
|
142
|
+
await fs2.move(fromPath, tempPath);
|
|
143
|
+
await fs2.move(tempPath, toPath);
|
|
144
|
+
} else {
|
|
145
|
+
await fs2.move(fromPath, toPath);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const repoRoot = (await execAsync("git rev-parse --show-toplevel", { cwd })).stdout.trim();
|
|
149
|
+
const relativeFrom = path2.relative(repoRoot, fromPath);
|
|
150
|
+
const relativeTo = path2.relative(repoRoot, toPath);
|
|
151
|
+
await execAsync(`git rm --cached "${relativeFrom}"`, { cwd: repoRoot });
|
|
152
|
+
await execAsync(`git add "${relativeTo}"`, { cwd: repoRoot });
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.warn(`Aviso: N\xE3o foi poss\xEDvel atualizar o \xEDndice Git para ${fromPath}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function getComponentBaseName(filePath) {
|
|
158
|
+
const fileName = path2.basename(filePath);
|
|
159
|
+
return fileName.replace(/\.(types|stories|story|spec|test|mock)\.(ts|tsx|js|jsx)$/, "").replace(/\.(ts|tsx|js|jsx|vue)$/, "");
|
|
160
|
+
}
|
|
161
|
+
function getFileType(fileName) {
|
|
162
|
+
if (fileName === "index.ts" || fileName === "index.js") return "index";
|
|
163
|
+
if (fileName.includes(".types.")) return "types";
|
|
164
|
+
if (fileName.includes(".spec.") || fileName.includes(".test.")) return "test";
|
|
165
|
+
if (fileName.includes(".stories.") || fileName.includes(".story.")) return "stories";
|
|
166
|
+
if (fileName.includes(".mock.")) return "mock";
|
|
167
|
+
if (fileName.endsWith(".vue")) return "component";
|
|
168
|
+
return "other";
|
|
169
|
+
}
|
|
170
|
+
async function analyzeComponentStructure(options) {
|
|
171
|
+
const components = [];
|
|
172
|
+
const targetPath = path2.resolve(options.path);
|
|
173
|
+
try {
|
|
174
|
+
await analyzeDirectory(targetPath, components, options);
|
|
175
|
+
return {
|
|
176
|
+
components,
|
|
177
|
+
directoriesToRename: components.filter((c) => c.needsRename).length,
|
|
178
|
+
filesToRename: components.reduce(
|
|
179
|
+
(sum, c) => sum + c.files.filter((f) => f.currentPath !== f.targetPath).length,
|
|
180
|
+
0
|
|
181
|
+
),
|
|
182
|
+
filesToCreate: components.reduce((sum, c) => sum + c.missingFiles.length, 0),
|
|
183
|
+
importsToUpdate: 0,
|
|
184
|
+
// TODO: Implement import detection
|
|
185
|
+
success: true
|
|
186
|
+
};
|
|
187
|
+
} catch (error) {
|
|
188
|
+
return {
|
|
189
|
+
components: [],
|
|
190
|
+
directoriesToRename: 0,
|
|
191
|
+
filesToRename: 0,
|
|
192
|
+
filesToCreate: 0,
|
|
193
|
+
importsToUpdate: 0,
|
|
194
|
+
success: false,
|
|
195
|
+
error: error instanceof Error ? error.message : String(error)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async function analyzeDirectory(dirPath, components, options) {
|
|
200
|
+
const entries = await fs2.readdir(dirPath, { withFileTypes: true });
|
|
201
|
+
const vueFiles = entries.filter((e) => e.isFile() && e.name.endsWith(".vue"));
|
|
202
|
+
if (vueFiles.length > 0) {
|
|
203
|
+
const componentFile = vueFiles[0];
|
|
204
|
+
const componentName = getComponentBaseName(componentFile.name);
|
|
205
|
+
const pascalComponentName = toPascalCase2(componentName);
|
|
206
|
+
const dirName = path2.basename(dirPath);
|
|
207
|
+
const expectedDirName = toKebabCase2(componentName);
|
|
208
|
+
const needsRename = dirName !== expectedDirName;
|
|
209
|
+
const files = [];
|
|
210
|
+
const existingFileNames = /* @__PURE__ */ new Set();
|
|
211
|
+
for (const entry of entries) {
|
|
212
|
+
if (entry.isFile()) {
|
|
213
|
+
const currentPath = path2.join(dirPath, entry.name);
|
|
214
|
+
const fileType = getFileType(entry.name);
|
|
215
|
+
const baseName = getComponentBaseName(entry.name);
|
|
216
|
+
const pascalName = toPascalCase2(baseName);
|
|
217
|
+
let targetName = entry.name;
|
|
218
|
+
if (fileType === "component" || fileType === "types" || fileType === "test" || fileType === "stories" || fileType === "mock") {
|
|
219
|
+
targetName = entry.name.replace(baseName, pascalName);
|
|
220
|
+
}
|
|
221
|
+
const targetPath = needsRename ? path2.join(path2.dirname(dirPath), expectedDirName, targetName) : path2.join(dirPath, targetName);
|
|
222
|
+
files.push({
|
|
223
|
+
currentPath,
|
|
224
|
+
targetPath,
|
|
225
|
+
isGitTracked: await isGitTracked(currentPath),
|
|
226
|
+
type: fileType
|
|
227
|
+
});
|
|
228
|
+
existingFileNames.add(entry.name);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const missingFiles = [];
|
|
232
|
+
if (!existingFileNames.has("index.ts") && !existingFileNames.has("index.js")) {
|
|
233
|
+
missingFiles.push("index.ts");
|
|
234
|
+
}
|
|
235
|
+
if (!existingFileNames.has(`${pascalComponentName}.types.ts`)) {
|
|
236
|
+
missingFiles.push(`${pascalComponentName}.types.ts`);
|
|
237
|
+
}
|
|
238
|
+
if (!existingFileNames.has(`${pascalComponentName}.spec.ts`) && !existingFileNames.has(`${pascalComponentName}.test.ts`)) {
|
|
239
|
+
missingFiles.push(`${pascalComponentName}.spec.ts`);
|
|
240
|
+
}
|
|
241
|
+
components.push({
|
|
242
|
+
currentPath: dirPath,
|
|
243
|
+
targetPath: needsRename ? path2.join(path2.dirname(dirPath), expectedDirName) : dirPath,
|
|
244
|
+
componentName: pascalComponentName,
|
|
245
|
+
files,
|
|
246
|
+
missingFiles,
|
|
247
|
+
needsRename
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
for (const entry of entries) {
|
|
251
|
+
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
252
|
+
await analyzeDirectory(path2.join(dirPath, entry.name), components, options);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function generateFileContent(fileName, componentName) {
|
|
257
|
+
if (fileName === "index.ts") {
|
|
258
|
+
return `export * from './${componentName}.types';
|
|
259
|
+
export { default } from './${componentName}.vue';
|
|
260
|
+
`;
|
|
261
|
+
}
|
|
262
|
+
if (fileName.endsWith(".types.ts")) {
|
|
263
|
+
return `export interface ${componentName}Type {
|
|
264
|
+
models: ${componentName}Models;
|
|
265
|
+
props: ${componentName}Props;
|
|
266
|
+
emits: ${componentName}Emits;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface ${componentName}Models {
|
|
270
|
+
//TODO: Add models here
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface ${componentName}Props {
|
|
274
|
+
//TODO: Add props here
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface ${componentName}Emits {
|
|
278
|
+
//TODO: Add emits here
|
|
279
|
+
}
|
|
280
|
+
`;
|
|
281
|
+
}
|
|
282
|
+
if (fileName.endsWith(".spec.ts")) {
|
|
283
|
+
return `import { describe, it, expect } from 'vitest';
|
|
284
|
+
import ${componentName} from './${componentName}.vue';
|
|
285
|
+
|
|
286
|
+
describe('${componentName}', () => {
|
|
287
|
+
it('should render', () => {
|
|
288
|
+
// TODO: Add tests
|
|
289
|
+
expect(${componentName}).toBeDefined();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
`;
|
|
293
|
+
}
|
|
294
|
+
return "";
|
|
295
|
+
}
|
|
296
|
+
async function normalizeComponents(options) {
|
|
297
|
+
const analysis = await analyzeComponentStructure(options);
|
|
298
|
+
if (!analysis.success || options.dryRun) {
|
|
299
|
+
return analysis;
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
if (!options.dirsOnly) {
|
|
303
|
+
for (const component of analysis.components) {
|
|
304
|
+
for (const missingFile of component.missingFiles) {
|
|
305
|
+
const targetPath = component.needsRename ? path2.join(component.targetPath, missingFile) : path2.join(component.currentPath, missingFile);
|
|
306
|
+
const content = generateFileContent(missingFile, component.componentName);
|
|
307
|
+
if (component.needsRename) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
await fs2.writeFile(targetPath, content, "utf-8");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (!options.filesOnly) {
|
|
315
|
+
for (const component of analysis.components) {
|
|
316
|
+
if (component.needsRename) {
|
|
317
|
+
const hasGitFiles = component.files.some((f) => f.isGitTracked);
|
|
318
|
+
const isCaseOnly = isCaseOnlyChange(component.currentPath, component.targetPath);
|
|
319
|
+
if (hasGitFiles) {
|
|
320
|
+
await gitMoveManual(component.currentPath, component.targetPath, isCaseOnly);
|
|
321
|
+
} else {
|
|
322
|
+
if (isCaseOnly) {
|
|
323
|
+
const tempPath = `${component.targetPath}-temp-rename`;
|
|
324
|
+
await fs2.move(component.currentPath, tempPath);
|
|
325
|
+
await fs2.move(tempPath, component.targetPath);
|
|
326
|
+
} else {
|
|
327
|
+
await fs2.move(component.currentPath, component.targetPath);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
for (const missingFile of component.missingFiles) {
|
|
331
|
+
const targetPath = path2.join(component.targetPath, missingFile);
|
|
332
|
+
const content = generateFileContent(missingFile, component.componentName);
|
|
333
|
+
await fs2.writeFile(targetPath, content, "utf-8");
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (!options.dirsOnly) {
|
|
339
|
+
for (const component of analysis.components) {
|
|
340
|
+
const currentDir = component.needsRename && !options.filesOnly ? component.targetPath : component.currentPath;
|
|
341
|
+
for (const file of component.files) {
|
|
342
|
+
const currentFilePath = component.needsRename && !options.filesOnly ? path2.join(currentDir, path2.basename(file.currentPath)) : file.currentPath;
|
|
343
|
+
const targetFilePath = component.needsRename && !options.filesOnly ? file.targetPath : path2.join(currentDir, path2.basename(file.targetPath));
|
|
344
|
+
if (path2.basename(currentFilePath) === path2.basename(targetFilePath)) {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const isCaseOnly = isCaseOnlyChange(currentFilePath, targetFilePath);
|
|
348
|
+
if (file.isGitTracked) {
|
|
349
|
+
await gitMoveManual(currentFilePath, targetFilePath, isCaseOnly);
|
|
350
|
+
} else {
|
|
351
|
+
if (isCaseOnly) {
|
|
352
|
+
const tempPath = `${targetFilePath}-temp-rename`;
|
|
353
|
+
await fs2.move(currentFilePath, tempPath);
|
|
354
|
+
await fs2.move(tempPath, targetFilePath);
|
|
355
|
+
} else {
|
|
356
|
+
await fs2.move(currentFilePath, targetFilePath);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
...analysis,
|
|
364
|
+
success: true
|
|
365
|
+
};
|
|
366
|
+
} catch (error) {
|
|
367
|
+
return {
|
|
368
|
+
...analysis,
|
|
369
|
+
success: false,
|
|
370
|
+
error: error instanceof Error ? error.message : String(error)
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/cli.ts
|
|
376
|
+
import chalk from "chalk";
|
|
377
|
+
var program = new Command();
|
|
378
|
+
program.name("storytype").description("Ferramenta CLI para criar componentes Storytype").version(version);
|
|
379
|
+
program.command("generate <type> <name>").alias("g").description("Gerar um novo componente (atomo, molecula, organismo, template)").option("-p, --path <path>", "Caminho customizado para o componente").action(async (type, name, options) => {
|
|
380
|
+
const typeMap = {
|
|
381
|
+
atomo: "atomos",
|
|
382
|
+
atomos: "atomos",
|
|
383
|
+
molecula: "moleculas",
|
|
384
|
+
moleculas: "moleculas",
|
|
385
|
+
organismo: "organismos",
|
|
386
|
+
organismos: "organismos",
|
|
387
|
+
template: "templates",
|
|
388
|
+
templates: "templates"
|
|
389
|
+
};
|
|
390
|
+
const mappedType = typeMap[type.toLowerCase()];
|
|
391
|
+
if (!mappedType) {
|
|
392
|
+
console.error(chalk.red(`Tipo de componente inv\xE1lido: ${type}`));
|
|
393
|
+
console.log(chalk.yellow("Tipos v\xE1lidos: atomo, molecula, organismo, template"));
|
|
394
|
+
console.log(
|
|
395
|
+
chalk.gray("(formas plurais tamb\xE9m aceitas: atomos, moleculas, organismos, templates)")
|
|
396
|
+
);
|
|
397
|
+
process.exit(1);
|
|
398
|
+
}
|
|
399
|
+
console.log(chalk.blue(`Gerando componente ${type}: ${name}`));
|
|
400
|
+
try {
|
|
401
|
+
const result = await generateComponent({
|
|
402
|
+
name,
|
|
403
|
+
type: mappedType,
|
|
404
|
+
path: options.path
|
|
405
|
+
});
|
|
406
|
+
if (result.success) {
|
|
407
|
+
console.log(chalk.green("\u2713 Componente gerado com sucesso!"));
|
|
408
|
+
console.log(chalk.gray("\nArquivos criados:"));
|
|
409
|
+
result.files.forEach((file) => {
|
|
410
|
+
console.log(chalk.gray(` - ${file}`));
|
|
411
|
+
});
|
|
412
|
+
} else {
|
|
413
|
+
console.error(chalk.red(`\u2717 Erro: ${result.error}`));
|
|
414
|
+
process.exit(1);
|
|
415
|
+
}
|
|
416
|
+
} catch (error) {
|
|
417
|
+
console.error(chalk.red("Erro ao gerar componente:"), error);
|
|
418
|
+
process.exit(1);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
program.command("normalize [path]").description(
|
|
422
|
+
"Normalizar estrutura de componentes (diret\xF3rios em kebab-case, arquivos em PascalCase)"
|
|
423
|
+
).option("-d, --dry-run", "Mostrar mudan\xE7as sem execut\xE1-las").option("--dirs-only", "Normalizar apenas nomes de diret\xF3rios").option("--files-only", "Normalizar apenas nomes de arquivos").option("-v, --verbose", "Mostrar sa\xEDda detalhada").action(
|
|
424
|
+
async (targetPath, options) => {
|
|
425
|
+
try {
|
|
426
|
+
console.log(chalk.blue("Analisando estrutura de componentes..."));
|
|
427
|
+
const result = await normalizeComponents({
|
|
428
|
+
path: targetPath || process.cwd(),
|
|
429
|
+
dryRun: options?.dryRun || false,
|
|
430
|
+
dirsOnly: options?.dirsOnly || false,
|
|
431
|
+
filesOnly: options?.filesOnly || false,
|
|
432
|
+
verbose: options?.verbose || false
|
|
433
|
+
});
|
|
434
|
+
if (result.success) {
|
|
435
|
+
console.log(chalk.green("\n\u2713 An\xE1lise completa!"));
|
|
436
|
+
console.log(chalk.gray(`
|
|
437
|
+
Componentes encontrados: ${result.components.length}`));
|
|
438
|
+
console.log(chalk.gray(`Diret\xF3rios a renomear: ${result.directoriesToRename}`));
|
|
439
|
+
console.log(chalk.gray(`Arquivos a renomear: ${result.filesToRename}`));
|
|
440
|
+
console.log(chalk.gray(`Arquivos a criar: ${result.filesToCreate}`));
|
|
441
|
+
if (options?.dryRun) {
|
|
442
|
+
console.log(chalk.yellow("\n\u26A0 Modo dry-run: nenhuma mudan\xE7a foi feita"));
|
|
443
|
+
console.log(chalk.gray("Execute sem --dry-run para aplicar as mudan\xE7as"));
|
|
444
|
+
} else if (result.directoriesToRename + result.filesToRename + result.filesToCreate > 0) {
|
|
445
|
+
console.log(chalk.green("\n\u2713 Normaliza\xE7\xE3o conclu\xEDda com sucesso!"));
|
|
446
|
+
} else {
|
|
447
|
+
console.log(
|
|
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:"));
|
|
453
|
+
result.components.forEach((comp) => {
|
|
454
|
+
if (comp.needsRename || comp.missingFiles.length > 0) {
|
|
455
|
+
console.log(chalk.gray(`
|
|
456
|
+
${comp.componentName}:`));
|
|
457
|
+
if (comp.needsRename) {
|
|
458
|
+
console.log(
|
|
459
|
+
chalk.yellow(` Renomear: ${comp.currentPath} \u2192 ${comp.targetPath}`)
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
if (comp.missingFiles.length > 0) {
|
|
463
|
+
console.log(chalk.yellow(` Criar: ${comp.missingFiles.join(", ")}`));
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
} else {
|
|
469
|
+
console.error(chalk.red(`
|
|
470
|
+
\u2717 Erro: ${result.error}`));
|
|
471
|
+
process.exit(1);
|
|
472
|
+
}
|
|
473
|
+
} catch (error) {
|
|
474
|
+
console.error(chalk.red("Erro ao normalizar componentes:"), error);
|
|
475
|
+
process.exit(1);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
program.command("init").description("Inicializar Storytype no seu projeto").action(() => {
|
|
480
|
+
console.log("Inicializando Storytype...");
|
|
481
|
+
});
|
|
482
|
+
program.command("analyze [path]").alias("audit").description("Analisar e pontuar projeto baseado nas melhores pr\xE1ticas Storytype").option("-v, --verbose", "Mostrar problemas por arquivo e como corrigir cada um").action(async (projectPath, options) => {
|
|
483
|
+
try {
|
|
484
|
+
const result = await analyzeProject(projectPath);
|
|
485
|
+
displayResults(result, { verbose: options?.verbose });
|
|
486
|
+
} catch (error) {
|
|
487
|
+
console.error("Erro ao analisar projeto:", error);
|
|
488
|
+
process.exit(1);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
program.parse();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @storytype/cli - Project Analyzer
|
|
3
|
+
* Analyzes and scores projects based on Storytype best practices
|
|
4
|
+
*/
|
|
5
|
+
interface AnalysisResult {
|
|
6
|
+
score: number;
|
|
7
|
+
maxScore: number;
|
|
8
|
+
percentage: number;
|
|
9
|
+
categories: CategoryResult[];
|
|
10
|
+
summary: string;
|
|
11
|
+
}
|
|
12
|
+
interface CategoryResult {
|
|
13
|
+
name: string;
|
|
14
|
+
score: number;
|
|
15
|
+
maxScore: number;
|
|
16
|
+
percentage: number;
|
|
17
|
+
items: CheckItem[];
|
|
18
|
+
}
|
|
19
|
+
interface FileIssue {
|
|
20
|
+
file: string;
|
|
21
|
+
issue: string;
|
|
22
|
+
fix: string;
|
|
23
|
+
}
|
|
24
|
+
interface CheckItem {
|
|
25
|
+
name: string;
|
|
26
|
+
passed: boolean;
|
|
27
|
+
points: number;
|
|
28
|
+
maxPoints: number;
|
|
29
|
+
message?: string;
|
|
30
|
+
fileIssues?: FileIssue[];
|
|
31
|
+
}
|
|
32
|
+
interface DisplayOptions {
|
|
33
|
+
verbose?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Analyze a project directory
|
|
37
|
+
*/
|
|
38
|
+
declare function analyzeProject(projectPath?: string): Promise<AnalysisResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Display analysis results
|
|
41
|
+
*/
|
|
42
|
+
declare function displayResults(result: AnalysisResult, options?: DisplayOptions): void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* storytype
|
|
46
|
+
* Programmatic API for the Storytype CLI
|
|
47
|
+
*/
|
|
48
|
+
type ComponentLevel = 'atom' | 'molecule' | 'organism' | 'template' | 'page';
|
|
49
|
+
interface GenerateOptions {
|
|
50
|
+
level: ComponentLevel;
|
|
51
|
+
name: string;
|
|
52
|
+
path?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Generate a new component programmatically
|
|
56
|
+
*/
|
|
57
|
+
declare function generateComponent(options: GenerateOptions): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Initialize Storytype in a project
|
|
60
|
+
*/
|
|
61
|
+
declare function initStorytype(projectPath?: string): Promise<void>;
|
|
62
|
+
|
|
63
|
+
export { type AnalysisResult, type CategoryResult, type CheckItem, type ComponentLevel, type DisplayOptions, type FileIssue, type GenerateOptions, analyzeProject, displayResults, generateComponent, initStorytype };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeProject,
|
|
3
|
+
displayResults
|
|
4
|
+
} from "./chunk-ROL3KHCC.js";
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
async function generateComponent(options) {
|
|
8
|
+
console.log(`Generating ${options.level}: ${options.name}`);
|
|
9
|
+
}
|
|
10
|
+
async function initStorytype(projectPath) {
|
|
11
|
+
console.log("Initializing Storytype...");
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
analyzeProject,
|
|
15
|
+
displayResults,
|
|
16
|
+
generateComponent,
|
|
17
|
+
initStorytype
|
|
18
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="{{kebabCase name}}">
|
|
3
|
+
<!-- Conteúdo -->
|
|
4
|
+
<p>Parabéns! Você criou o componente {{pascalCase name}}!</p>
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { {{pascalCase name}}Props } from './{{pascalCase name}}.types';
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{{pascalCase name}}Props>(), {
|
|
12
|
+
// Add default props here
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<style scoped>
|
|
17
|
+
.{{kebabCase name}} {
|
|
18
|
+
/* Add component styles here */
|
|
19
|
+
}
|
|
20
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { {{pascalCase name}}Models, {{pascalCase name}}Props, {{pascalCase name}}Emits, {{pascalCase name}}Type } from './{{pascalCase name}}.types';
|
|
2
|
+
|
|
3
|
+
export const generateMockData = (): {{pascalCase name}}Type => {
|
|
4
|
+
const props: {{pascalCase name}}Props = {
|
|
5
|
+
//TODO: Add props here
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const models: {{pascalCase name}}Models = {
|
|
9
|
+
//TODO: Add models here
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const emits: {{pascalCase name}}Emits = {
|
|
13
|
+
//TODO: Add emits here ex.: (e: 'click', event: Event): void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
props,
|
|
18
|
+
models,
|
|
19
|
+
emits,
|
|
20
|
+
} satisfies {{pascalCase name}}Type as {{pascalCase name}}Type;
|
|
21
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
|
2
|
+
import {{pascalCase name}} from './{{pascalCase name}}.vue';
|
|
3
|
+
import { generateMockData } from './{{pascalCase name}}.mock';
|
|
4
|
+
|
|
5
|
+
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
|
+
component: {{pascalCase name}},
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component: 'Descrição do componente {{pascalCase name}}',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
} satisfies Meta<typeof {{pascalCase name}}>;
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
type Story = StoryObj<typeof meta>;
|
|
20
|
+
|
|
21
|
+
const mockData = generateMockData();
|
|
22
|
+
|
|
23
|
+
export const Default: Story = {
|
|
24
|
+
args: {
|
|
25
|
+
...mockData.props,
|
|
26
|
+
...mockData.models,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface {{pascalCase name}}Type {
|
|
2
|
+
models: {{pascalCase name}}Models;
|
|
3
|
+
props: {{pascalCase name}}Props;
|
|
4
|
+
emits: {{pascalCase name}}Emits;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface {{pascalCase name}}Models {
|
|
8
|
+
//TODO: Add models here
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface {{pascalCase name}}Props {
|
|
12
|
+
//TODO: Add props here
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface {{pascalCase name}}Emits {
|
|
16
|
+
//TODO: Add emits here
|
|
17
|
+
}
|