mdsmith 1.0.2 → 1.1.1
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-MDSMITH.md +31 -0
- package/bin/{fundamentos.js → beta.js} +15 -14
- package/bin/index.js +284 -53
- package/mdsmith.config.json +8 -0
- package/package.json +2 -1
- package/bin/versaobeta.js +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
# mdsmith
|
|
3
|
+
|
|
4
|
+
CLI para gerar READMEs e arquivos Markdown
|
|
5
|
+
|
|
6
|
+
## 🔖 Project Info
|
|
7
|
+
- **Version:** 1.1.0
|
|
8
|
+
- **Package Manager:** npm
|
|
9
|
+
- **Type:** Node.js Project
|
|
10
|
+
|
|
11
|
+
## 🚀 Dependencies
|
|
12
|
+
No dependencies found.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## 📁 Project Structure
|
|
16
|
+
```
|
|
17
|
+
📂 bin
|
|
18
|
+
📄 beta.js
|
|
19
|
+
📄 index.js
|
|
20
|
+
📄 mdsmith.config.json
|
|
21
|
+
📄 package-lock.json
|
|
22
|
+
📄 package.json
|
|
23
|
+
📄 README-MDSMITH.md
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 📜 Available Scripts
|
|
28
|
+
No scripts available.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Generated by **mdSmith**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// npx
|
|
4
|
-
// npx
|
|
5
|
-
// npx
|
|
6
|
-
// npx
|
|
3
|
+
// npx mdsmith --help # ajuda
|
|
4
|
+
// npx mdsmith --tree # mostra estrutura
|
|
5
|
+
// npx mdsmith --deps # mostra dependências
|
|
6
|
+
// npx mdsmith --readme # gera README
|
|
7
7
|
|
|
8
8
|
const fs = require("fs");
|
|
9
9
|
|
|
@@ -63,7 +63,7 @@ function generateReadme(packageJson, tree){
|
|
|
63
63
|
const content = `
|
|
64
64
|
# ${packageJson.name || "Nome não informado."}
|
|
65
65
|
|
|
66
|
-
${packageJson.description || "Projeto Node.js analisado automaticamente pelo
|
|
66
|
+
${packageJson.description || "Projeto Node.js analisado automaticamente pelo mdSmith."}
|
|
67
67
|
|
|
68
68
|
## 🔖 Informações
|
|
69
69
|
- **Versão:** ${packageJson.version || "Versão não informada."}
|
|
@@ -78,7 +78,7 @@ ${formatDependencies(packageJson.dependencies)}
|
|
|
78
78
|
${tree}
|
|
79
79
|
\`\`\`
|
|
80
80
|
|
|
81
|
-
📄 *README gerado automaticamente pelo **
|
|
81
|
+
📄 *README gerado automaticamente pelo **mdSmith***
|
|
82
82
|
`
|
|
83
83
|
|
|
84
84
|
return content
|
|
@@ -87,18 +87,18 @@ ${tree}
|
|
|
87
87
|
|
|
88
88
|
if(args.length == 0){
|
|
89
89
|
console.log(`
|
|
90
|
-
Bem vindo ao
|
|
90
|
+
Bem vindo ao mdSmith!
|
|
91
91
|
Analisador de projetos Node.js
|
|
92
92
|
|
|
93
|
-
Digite
|
|
93
|
+
Digite npx mdsmith --help se quiser ver os comandos disponíveis
|
|
94
94
|
`);
|
|
95
95
|
process.exit(0);
|
|
96
96
|
} else if(args.includes("--help")){
|
|
97
97
|
console.log(`
|
|
98
|
-
npx
|
|
99
|
-
npx
|
|
100
|
-
npx
|
|
101
|
-
npx
|
|
98
|
+
npx mdsmith --help Mostra os comandos possíveis
|
|
99
|
+
npx mdsmith --tree Mostra a estrutura do projeto
|
|
100
|
+
npx mdsmith --deps Mostra as dependências
|
|
101
|
+
npx mdsmith --readme Gera um README automaticamente
|
|
102
102
|
`)
|
|
103
103
|
} else if (args.includes("--tree")){
|
|
104
104
|
console.log("\n🌳 Estrutura do projeto:\n");
|
|
@@ -110,7 +110,8 @@ if(args.length == 0){
|
|
|
110
110
|
} else if (args.includes("--readme")){
|
|
111
111
|
const content = generateReadme(packageJson, scanDir(projectRoot, 0))
|
|
112
112
|
|
|
113
|
-
fs.writeFileSync("README-
|
|
113
|
+
fs.writeFileSync("README-MDSMITH.md", content)
|
|
114
|
+
console.log("✅ README-MDSMITH.md gerado com sucesso!")
|
|
114
115
|
} else {
|
|
115
|
-
console.log("❌ Comando não reconhecido. Use --help para ver as opções.")
|
|
116
|
+
console.log("❌ Comando não reconhecido. Use npx mdsmith --help para ver as opções.")
|
|
116
117
|
}
|
package/bin/index.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// npx mdsmith --help
|
|
4
|
-
// npx mdsmith --
|
|
5
|
-
// npx mdsmith --
|
|
6
|
-
// npx mdsmith --
|
|
3
|
+
// npx mdsmith --help # show help
|
|
4
|
+
// npx mdsmith --init # create config file
|
|
5
|
+
// npx mdsmith --tree # show project structure
|
|
6
|
+
// npx mdsmith --deps # list dependencies
|
|
7
|
+
// npx mdsmith --readme # generate README
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
const fs = require("fs");
|
|
9
11
|
|
|
10
12
|
const path = require("path");
|
|
11
13
|
|
|
14
|
+
const readline = require("readline");
|
|
15
|
+
|
|
16
|
+
const rl = readline.createInterface({
|
|
17
|
+
input: process.stdin,
|
|
18
|
+
output: process.stdout
|
|
19
|
+
});
|
|
20
|
+
|
|
12
21
|
const projectRoot = process.cwd();
|
|
13
22
|
|
|
14
23
|
if(!fs.existsSync(path.join(process.cwd(), "package.json"))){
|
|
15
|
-
console.log(
|
|
24
|
+
console.log(`
|
|
25
|
+
Error: package.json not found.
|
|
26
|
+
Please run mdsmith from the project root.
|
|
27
|
+
`)
|
|
16
28
|
process.exit(1)
|
|
17
29
|
}
|
|
18
30
|
|
|
@@ -20,11 +32,15 @@ const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.j
|
|
|
20
32
|
|
|
21
33
|
const args = process.argv.slice(2)
|
|
22
34
|
|
|
23
|
-
const
|
|
35
|
+
const defaultConfig = {
|
|
36
|
+
ignore: ["node_modules", ".git", ".vscode"],
|
|
37
|
+
depth: Infinity
|
|
38
|
+
}
|
|
39
|
+
|
|
24
40
|
|
|
25
41
|
function formatDependencies(deps) {
|
|
26
42
|
if (!deps || Object.keys(deps).length === 0) {
|
|
27
|
-
return "
|
|
43
|
+
return "No dependencies found.\n";
|
|
28
44
|
}
|
|
29
45
|
|
|
30
46
|
return Object.entries(deps)
|
|
@@ -32,8 +48,13 @@ function formatDependencies(deps) {
|
|
|
32
48
|
.join("\n");
|
|
33
49
|
}
|
|
34
50
|
|
|
35
|
-
function scanDir(dirPath, padding) {
|
|
36
|
-
const entries = fs.readdirSync(dirPath, { withFileTypes: true })
|
|
51
|
+
function scanDir(dirPath, padding, config) {
|
|
52
|
+
const entries = fs.readdirSync(dirPath, { withFileTypes: true })
|
|
53
|
+
.sort((a, b) => {
|
|
54
|
+
if (a.isDirectory() && !b.isDirectory()) return -1
|
|
55
|
+
if (!a.isDirectory() && b.isDirectory()) return 1
|
|
56
|
+
return a.name.localeCompare(b.name)
|
|
57
|
+
})
|
|
37
58
|
|
|
38
59
|
let treeContent = ""
|
|
39
60
|
|
|
@@ -43,13 +64,17 @@ function scanDir(dirPath, padding) {
|
|
|
43
64
|
const fullPath = path.join(dirPath, entry.name);
|
|
44
65
|
|
|
45
66
|
if (entry.isDirectory()) {
|
|
46
|
-
if (
|
|
47
|
-
|
|
67
|
+
if (config.ignore.includes(entry.name)){
|
|
68
|
+
continue
|
|
48
69
|
} else {
|
|
49
70
|
treeContent += `${" ".repeat(padding*2)} 📂 ${entry.name}\n`
|
|
50
|
-
padding
|
|
51
|
-
|
|
52
|
-
|
|
71
|
+
if (config.depth === null || padding < config.depth){
|
|
72
|
+
padding ++
|
|
73
|
+
treeContent += scanDir(fullPath, padding, config)
|
|
74
|
+
padding --
|
|
75
|
+
} else {
|
|
76
|
+
treeContent += `${" ".repeat((padding + 1) * 2)} ··· \n`
|
|
77
|
+
}
|
|
53
78
|
}
|
|
54
79
|
} else {
|
|
55
80
|
treeContent += `${" ".repeat(padding*2)} 📄 ${entry.name}\n`
|
|
@@ -59,59 +84,265 @@ function scanDir(dirPath, padding) {
|
|
|
59
84
|
return treeContent
|
|
60
85
|
}
|
|
61
86
|
|
|
62
|
-
function
|
|
87
|
+
function perguntar(pergunta) {
|
|
88
|
+
return new Promise(resolve => {
|
|
89
|
+
rl.question(pergunta, resolve);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function buscarNome(nome){
|
|
94
|
+
if(!nome || nome == "" || nome == false){
|
|
95
|
+
|
|
96
|
+
let respostaValida = false
|
|
97
|
+
let resposta = ""
|
|
98
|
+
while(!respostaValida){
|
|
99
|
+
resposta = await perguntar(`
|
|
100
|
+
Project name not found in package.json.
|
|
101
|
+
Would you like to provide one? (y/n):
|
|
102
|
+
`)
|
|
103
|
+
resposta = resposta.trim().toLowerCase()
|
|
104
|
+
|
|
105
|
+
if(resposta == "y" || resposta == "n"){
|
|
106
|
+
respostaValida = true
|
|
107
|
+
}else {
|
|
108
|
+
console.log("Please type y or n.")
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if(resposta == "n"){
|
|
114
|
+
console.log("\nProject name will be set as Unnamed Project.\n")
|
|
115
|
+
return "Unnamed Project"
|
|
116
|
+
}if(resposta == "y"){
|
|
117
|
+
let nome = await perguntar("Enter the project name: ")
|
|
118
|
+
console.log(`Project name set to "${nome}".`)
|
|
119
|
+
return nome
|
|
120
|
+
}else{
|
|
121
|
+
console.error("Failed to generate project name.")
|
|
122
|
+
process.exit(1)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return nome
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function buscarDescricao(descricao){
|
|
130
|
+
if(!descricao || descricao == "" || descricao == false){
|
|
131
|
+
|
|
132
|
+
let respostaValida = false
|
|
133
|
+
let resposta = ""
|
|
134
|
+
while(!respostaValida){
|
|
135
|
+
resposta = await perguntar(`
|
|
136
|
+
Project description not found.
|
|
137
|
+
Would you like to provide one? (y/n):
|
|
138
|
+
`)
|
|
139
|
+
resposta = resposta.trim().toLowerCase()
|
|
140
|
+
|
|
141
|
+
if(resposta == "y" || resposta == "n"){
|
|
142
|
+
respostaValida = true
|
|
143
|
+
}else {
|
|
144
|
+
console.log("Please type y or n.")
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
if(resposta == "n"){
|
|
150
|
+
console.log("\nDescription placeholder added.\n")
|
|
151
|
+
return "*Project description goes here*"
|
|
152
|
+
}if(resposta == "y"){
|
|
153
|
+
let descricao = await perguntar("Enter the project description: ")
|
|
154
|
+
console.log("\nDescription saved.\n")
|
|
155
|
+
return descricao
|
|
156
|
+
}else{
|
|
157
|
+
console.error("Failed to generate project description.")
|
|
158
|
+
process.exit(1)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return descricao
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function detectarTipoProjeto(packageJson) {
|
|
166
|
+
const deps = {
|
|
167
|
+
...packageJson.dependencies,
|
|
168
|
+
...packageJson.devDependencies
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (deps.react) return "Frontend React"
|
|
172
|
+
if (deps.next) return "Next.js Application"
|
|
173
|
+
if (deps.express) return "API REST (Express)"
|
|
174
|
+
if (deps.typescript) return "Projeto TypeScript"
|
|
175
|
+
|
|
176
|
+
return "Node.js Project"
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function formatScripts(scripts) {
|
|
180
|
+
if (!scripts || Object.keys(scripts).length === 0) {
|
|
181
|
+
return "No scripts available.\n";
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return Object.entries(scripts)
|
|
185
|
+
.map(([name, script]) => `- ${name} -> ${script}`)
|
|
186
|
+
.join("\n");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
async function generateReadme(packageJson, tree){
|
|
191
|
+
|
|
192
|
+
const nomeProjeto = await buscarNome(packageJson.name);
|
|
193
|
+
const descricaoProjeto = await buscarDescricao(packageJson.description);
|
|
194
|
+
|
|
63
195
|
const content = `
|
|
64
|
-
# ${
|
|
196
|
+
# ${nomeProjeto}
|
|
65
197
|
|
|
66
|
-
${
|
|
198
|
+
${descricaoProjeto}
|
|
67
199
|
|
|
68
|
-
## 🔖
|
|
69
|
-
- **
|
|
70
|
-
- **
|
|
71
|
-
- **
|
|
200
|
+
## 🔖 Project Info
|
|
201
|
+
- **Version:** ${packageJson.version || "Not specified"}
|
|
202
|
+
- **Package Manager:** npm
|
|
203
|
+
- **Type:** ${detectarTipoProjeto(packageJson)}
|
|
72
204
|
|
|
73
|
-
## 🚀
|
|
205
|
+
## 🚀 Dependencies
|
|
74
206
|
${formatDependencies(packageJson.dependencies)}
|
|
75
207
|
|
|
76
|
-
## 📁
|
|
208
|
+
## 📁 Project Structure
|
|
77
209
|
\`\`\`
|
|
78
210
|
${tree}
|
|
79
211
|
\`\`\`
|
|
80
212
|
|
|
81
|
-
|
|
213
|
+
## 📜 Available Scripts
|
|
214
|
+
${formatScripts(packageJson.scripts)}
|
|
215
|
+
|
|
216
|
+
Generated by **mdSmith**
|
|
82
217
|
`
|
|
83
218
|
|
|
84
219
|
return content
|
|
85
220
|
|
|
86
221
|
}
|
|
87
222
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
223
|
+
function loadConfig(projectRoot) {
|
|
224
|
+
const configPath = path.join(projectRoot, "mdsmith.config.json")
|
|
225
|
+
|
|
226
|
+
if (!fs.existsSync(configPath)) {
|
|
227
|
+
return defaultConfig
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
const fileContent = fs.readFileSync(configPath, "utf-8")
|
|
232
|
+
const userConfig = JSON.parse(fileContent)
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
...defaultConfig,
|
|
236
|
+
...userConfig,
|
|
237
|
+
ignore: [
|
|
238
|
+
...defaultConfig.ignore,
|
|
239
|
+
...(userConfig.ignore || [])
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.log("Failed to read mdsmith.config.json. Using default configuration.")
|
|
246
|
+
return defaultConfig
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function main() {
|
|
251
|
+
const config = loadConfig(projectRoot)
|
|
252
|
+
|
|
253
|
+
if(args.length == 0){
|
|
254
|
+
console.log(`
|
|
255
|
+
mdSmith
|
|
256
|
+
Node.js project analyzer
|
|
257
|
+
────────────────────────
|
|
258
|
+
|
|
259
|
+
Run "mdsmith --help" to view available commands.
|
|
260
|
+
`);
|
|
261
|
+
process.exit(0);
|
|
262
|
+
}else if (args.includes("--init")) {
|
|
263
|
+
|
|
264
|
+
const configPath = path.join(projectRoot, "mdsmith.config.json")
|
|
265
|
+
|
|
266
|
+
if (fs.existsSync(configPath)) {
|
|
267
|
+
console.log("mdsmith.config.json already exists.")
|
|
268
|
+
process.exit(0)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
fs.writeFileSync(
|
|
272
|
+
configPath,
|
|
273
|
+
JSON.stringify(defaultConfig, null, 2)
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
console.log("Configuration file created.")
|
|
277
|
+
process.exit(0)
|
|
278
|
+
|
|
279
|
+
} else if(args.includes("--help")){
|
|
280
|
+
console.log(`
|
|
281
|
+
mdSmith — Available Commands
|
|
282
|
+
────────────────────────
|
|
283
|
+
|
|
284
|
+
--help Show help
|
|
285
|
+
--init Create config file
|
|
286
|
+
--tree Show project structure
|
|
287
|
+
--deps List dependencies
|
|
288
|
+
--readme Generate README
|
|
289
|
+
`)
|
|
290
|
+
process.exit(0)
|
|
291
|
+
} else if (args.includes("--tree")){
|
|
292
|
+
console.log(`
|
|
293
|
+
Project Structure
|
|
294
|
+
────────────────────────
|
|
295
|
+
`);
|
|
296
|
+
console.log(scanDir(projectRoot, 0, config))
|
|
297
|
+
process.exit(0)
|
|
298
|
+
} else if (args.includes("--deps")){
|
|
299
|
+
console.log(`
|
|
300
|
+
Dependencies
|
|
301
|
+
────────────────────────
|
|
302
|
+
`)
|
|
303
|
+
const deps = formatDependencies(packageJson.dependencies)
|
|
304
|
+
console.log(deps)
|
|
305
|
+
process.exit(0)
|
|
306
|
+
} else if (args.includes("--readme")){
|
|
307
|
+
const content = await generateReadme(packageJson, scanDir(projectRoot, 0, config))
|
|
308
|
+
|
|
309
|
+
console.log(`
|
|
310
|
+
README Preview
|
|
311
|
+
────────────────────────
|
|
312
|
+
`)
|
|
313
|
+
|
|
314
|
+
console.log(content)
|
|
315
|
+
|
|
316
|
+
let respostaValida = false
|
|
317
|
+
let confirm = ""
|
|
318
|
+
|
|
319
|
+
while (!respostaValida) {
|
|
320
|
+
confirm = await perguntar("\nGenerate README-MDSMITH.md? (y/n): ")
|
|
321
|
+
confirm = confirm.trim().toLowerCase()
|
|
322
|
+
|
|
323
|
+
if (confirm === "y" || confirm === "n") {
|
|
324
|
+
respostaValida = true
|
|
325
|
+
} else {
|
|
326
|
+
console.log("\nPlease type y or n.")
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (confirm === "y") {
|
|
331
|
+
fs.writeFileSync("README-MDSMITH.md", content)
|
|
332
|
+
console.log("\nREADME-MDSMITH.md created.\n")
|
|
333
|
+
process.exit(0)
|
|
334
|
+
} else {
|
|
335
|
+
console.log("\nOperation cancelled.\n")
|
|
336
|
+
process.exit(0)
|
|
337
|
+
}
|
|
338
|
+
} else {
|
|
339
|
+
console.log(`
|
|
340
|
+
Unknown command.
|
|
341
|
+
Run "mdsmith --help" for usage.
|
|
342
|
+
`)
|
|
343
|
+
process.exit(0)
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
main()
|
|
92
348
|
|
|
93
|
-
Digite npx mdsmith --help se quiser ver os comandos disponíveis
|
|
94
|
-
`);
|
|
95
|
-
process.exit(0);
|
|
96
|
-
} else if(args.includes("--help")){
|
|
97
|
-
console.log(`
|
|
98
|
-
npx mdsmith --help Mostra os comandos possíveis
|
|
99
|
-
npx mdsmith --tree Mostra a estrutura do projeto
|
|
100
|
-
npx mdsmith --deps Mostra as dependências
|
|
101
|
-
npx mdsmith --readme Gera um README automaticamente
|
|
102
|
-
`)
|
|
103
|
-
} else if (args.includes("--tree")){
|
|
104
|
-
console.log("\n🌳 Estrutura do projeto:\n");
|
|
105
|
-
console.log(scanDir(projectRoot, 0))
|
|
106
|
-
} else if (args.includes("--deps")){
|
|
107
|
-
console.log(`O projeto ${packageJson.name} na versão ${packageJson.version}, tem as seguintes dependencias:`)
|
|
108
|
-
const deps = packageJson.dependencies || "Projeto sem depedencias"
|
|
109
|
-
console.log(deps)
|
|
110
|
-
} else if (args.includes("--readme")){
|
|
111
|
-
const content = generateReadme(packageJson, scanDir(projectRoot, 0))
|
|
112
|
-
|
|
113
|
-
fs.writeFileSync("README-MDSMITH.md", content)
|
|
114
|
-
console.log("✅ README-MDSMITH.md gerado com sucesso!")
|
|
115
|
-
} else {
|
|
116
|
-
console.log("❌ Comando não reconhecido. Use npx mdsmith --help para ver as opções.")
|
|
117
|
-
}
|
package/package.json
CHANGED
package/bin/versaobeta.js
DELETED
|
File without changes
|