mdsmith 1.1.0 β 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 +12 -11
- package/bin/index.js +172 -58
- package/mdsmith.config.json +8 -0
- package/package.json +2 -1
package/README-MDSMITH.md
CHANGED
|
@@ -3,28 +3,29 @@
|
|
|
3
3
|
|
|
4
4
|
CLI para gerar READMEs e arquivos Markdown
|
|
5
5
|
|
|
6
|
-
## π
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
6
|
+
## π Project Info
|
|
7
|
+
- **Version:** 1.1.0
|
|
8
|
+
- **Package Manager:** npm
|
|
9
|
+
- **Type:** Node.js Project
|
|
10
10
|
|
|
11
|
-
## π
|
|
12
|
-
|
|
11
|
+
## π Dependencies
|
|
12
|
+
No dependencies found.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
## π Project Structure
|
|
15
16
|
```
|
|
16
17
|
π bin
|
|
17
18
|
π beta.js
|
|
18
19
|
π index.js
|
|
19
|
-
|
|
20
|
+
π mdsmith.config.json
|
|
20
21
|
π package-lock.json
|
|
21
22
|
π package.json
|
|
22
23
|
π README-MDSMITH.md
|
|
23
24
|
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
## π Scripts
|
|
27
|
-
|
|
27
|
+
## π Available Scripts
|
|
28
|
+
No scripts available.
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
Generated by **mdSmith**
|
package/bin/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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
|
|
|
@@ -19,7 +21,10 @@ const rl = readline.createInterface({
|
|
|
19
21
|
const projectRoot = process.cwd();
|
|
20
22
|
|
|
21
23
|
if(!fs.existsSync(path.join(process.cwd(), "package.json"))){
|
|
22
|
-
console.log(
|
|
24
|
+
console.log(`
|
|
25
|
+
Error: package.json not found.
|
|
26
|
+
Please run mdsmith from the project root.
|
|
27
|
+
`)
|
|
23
28
|
process.exit(1)
|
|
24
29
|
}
|
|
25
30
|
|
|
@@ -27,11 +32,15 @@ const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.j
|
|
|
27
32
|
|
|
28
33
|
const args = process.argv.slice(2)
|
|
29
34
|
|
|
30
|
-
const
|
|
35
|
+
const defaultConfig = {
|
|
36
|
+
ignore: ["node_modules", ".git", ".vscode"],
|
|
37
|
+
depth: Infinity
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
|
|
32
41
|
function formatDependencies(deps) {
|
|
33
42
|
if (!deps || Object.keys(deps).length === 0) {
|
|
34
|
-
return "
|
|
43
|
+
return "No dependencies found.\n";
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
return Object.entries(deps)
|
|
@@ -39,8 +48,13 @@ function formatDependencies(deps) {
|
|
|
39
48
|
.join("\n");
|
|
40
49
|
}
|
|
41
50
|
|
|
42
|
-
function scanDir(dirPath, padding) {
|
|
43
|
-
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
|
+
})
|
|
44
58
|
|
|
45
59
|
let treeContent = ""
|
|
46
60
|
|
|
@@ -50,13 +64,17 @@ function scanDir(dirPath, padding) {
|
|
|
50
64
|
const fullPath = path.join(dirPath, entry.name);
|
|
51
65
|
|
|
52
66
|
if (entry.isDirectory()) {
|
|
53
|
-
if (
|
|
54
|
-
|
|
67
|
+
if (config.ignore.includes(entry.name)){
|
|
68
|
+
continue
|
|
55
69
|
} else {
|
|
56
70
|
treeContent += `${" ".repeat(padding*2)} π ${entry.name}\n`
|
|
57
|
-
padding
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
}
|
|
60
78
|
}
|
|
61
79
|
} else {
|
|
62
80
|
treeContent += `${" ".repeat(padding*2)} π ${entry.name}\n`
|
|
@@ -78,26 +96,29 @@ async function buscarNome(nome){
|
|
|
78
96
|
let respostaValida = false
|
|
79
97
|
let resposta = ""
|
|
80
98
|
while(!respostaValida){
|
|
81
|
-
resposta = await perguntar(
|
|
82
|
-
|
|
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()
|
|
83
104
|
|
|
84
105
|
if(resposta == "y" || resposta == "n"){
|
|
85
106
|
respostaValida = true
|
|
86
107
|
}else {
|
|
87
|
-
console.log("
|
|
108
|
+
console.log("Please type y or n.")
|
|
88
109
|
}
|
|
89
110
|
}
|
|
90
111
|
|
|
91
112
|
|
|
92
113
|
if(resposta == "n"){
|
|
93
|
-
console.log("
|
|
94
|
-
return "
|
|
114
|
+
console.log("\nProject name will be set as Unnamed Project.\n")
|
|
115
|
+
return "Unnamed Project"
|
|
95
116
|
}if(resposta == "y"){
|
|
96
|
-
let nome = await perguntar("
|
|
97
|
-
console.log(
|
|
117
|
+
let nome = await perguntar("Enter the project name: ")
|
|
118
|
+
console.log(`Project name set to "${nome}".`)
|
|
98
119
|
return nome
|
|
99
120
|
}else{
|
|
100
|
-
console.error("
|
|
121
|
+
console.error("Failed to generate project name.")
|
|
101
122
|
process.exit(1)
|
|
102
123
|
}
|
|
103
124
|
}
|
|
@@ -111,26 +132,29 @@ async function buscarDescricao(descricao){
|
|
|
111
132
|
let respostaValida = false
|
|
112
133
|
let resposta = ""
|
|
113
134
|
while(!respostaValida){
|
|
114
|
-
resposta = await perguntar(
|
|
115
|
-
|
|
135
|
+
resposta = await perguntar(`
|
|
136
|
+
Project description not found.
|
|
137
|
+
Would you like to provide one? (y/n):
|
|
138
|
+
`)
|
|
139
|
+
resposta = resposta.trim().toLowerCase()
|
|
116
140
|
|
|
117
141
|
if(resposta == "y" || resposta == "n"){
|
|
118
142
|
respostaValida = true
|
|
119
143
|
}else {
|
|
120
|
-
console.log("
|
|
144
|
+
console.log("Please type y or n.")
|
|
121
145
|
}
|
|
122
146
|
}
|
|
123
147
|
|
|
124
148
|
|
|
125
149
|
if(resposta == "n"){
|
|
126
|
-
console.log("\
|
|
127
|
-
return "*
|
|
150
|
+
console.log("\nDescription placeholder added.\n")
|
|
151
|
+
return "*Project description goes here*"
|
|
128
152
|
}if(resposta == "y"){
|
|
129
|
-
let descricao = await perguntar("
|
|
130
|
-
console.log("\
|
|
153
|
+
let descricao = await perguntar("Enter the project description: ")
|
|
154
|
+
console.log("\nDescription saved.\n")
|
|
131
155
|
return descricao
|
|
132
156
|
}else{
|
|
133
|
-
console.error("
|
|
157
|
+
console.error("Failed to generate project description.")
|
|
134
158
|
process.exit(1)
|
|
135
159
|
}
|
|
136
160
|
}
|
|
@@ -149,12 +173,12 @@ function detectarTipoProjeto(packageJson) {
|
|
|
149
173
|
if (deps.express) return "API REST (Express)"
|
|
150
174
|
if (deps.typescript) return "Projeto TypeScript"
|
|
151
175
|
|
|
152
|
-
return "
|
|
176
|
+
return "Node.js Project"
|
|
153
177
|
}
|
|
154
178
|
|
|
155
179
|
function formatScripts(scripts) {
|
|
156
180
|
if (!scripts || Object.keys(scripts).length === 0) {
|
|
157
|
-
return "
|
|
181
|
+
return "No scripts available.\n";
|
|
158
182
|
}
|
|
159
183
|
|
|
160
184
|
return Object.entries(scripts)
|
|
@@ -173,62 +197,152 @@ const content = `
|
|
|
173
197
|
|
|
174
198
|
${descricaoProjeto}
|
|
175
199
|
|
|
176
|
-
## π
|
|
177
|
-
- **
|
|
178
|
-
- **
|
|
179
|
-
- **
|
|
200
|
+
## π Project Info
|
|
201
|
+
- **Version:** ${packageJson.version || "Not specified"}
|
|
202
|
+
- **Package Manager:** npm
|
|
203
|
+
- **Type:** ${detectarTipoProjeto(packageJson)}
|
|
180
204
|
|
|
181
|
-
## π
|
|
205
|
+
## π Dependencies
|
|
182
206
|
${formatDependencies(packageJson.dependencies)}
|
|
183
207
|
|
|
184
|
-
## π
|
|
208
|
+
## π Project Structure
|
|
185
209
|
\`\`\`
|
|
186
210
|
${tree}
|
|
187
211
|
\`\`\`
|
|
188
212
|
|
|
189
|
-
## π Scripts
|
|
213
|
+
## π Available Scripts
|
|
190
214
|
${formatScripts(packageJson.scripts)}
|
|
191
215
|
|
|
192
|
-
|
|
193
|
-
π *README gerado automaticamente pelo **mdSmith***
|
|
216
|
+
Generated by **mdSmith**
|
|
194
217
|
`
|
|
195
218
|
|
|
196
219
|
return content
|
|
197
220
|
|
|
198
221
|
}
|
|
199
222
|
|
|
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
|
+
|
|
200
250
|
async function main() {
|
|
251
|
+
const config = loadConfig(projectRoot)
|
|
252
|
+
|
|
201
253
|
if(args.length == 0){
|
|
202
254
|
console.log(`
|
|
203
|
-
|
|
204
|
-
|
|
255
|
+
mdSmith
|
|
256
|
+
Node.js project analyzer
|
|
257
|
+
ββββββββββββββββββββββββ
|
|
205
258
|
|
|
206
|
-
|
|
259
|
+
Run "mdsmith --help" to view available commands.
|
|
207
260
|
`);
|
|
208
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
|
+
|
|
209
279
|
} else if(args.includes("--help")){
|
|
210
280
|
console.log(`
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
|
215
289
|
`)
|
|
290
|
+
process.exit(0)
|
|
216
291
|
} else if (args.includes("--tree")){
|
|
217
|
-
console.log(
|
|
218
|
-
|
|
292
|
+
console.log(`
|
|
293
|
+
Project Structure
|
|
294
|
+
ββββββββββββββββββββββββ
|
|
295
|
+
`);
|
|
296
|
+
console.log(scanDir(projectRoot, 0, config))
|
|
297
|
+
process.exit(0)
|
|
219
298
|
} else if (args.includes("--deps")){
|
|
220
|
-
console.log(`
|
|
221
|
-
|
|
299
|
+
console.log(`
|
|
300
|
+
Dependencies
|
|
301
|
+
ββββββββββββββββββββββββ
|
|
302
|
+
`)
|
|
303
|
+
const deps = formatDependencies(packageJson.dependencies)
|
|
222
304
|
console.log(deps)
|
|
305
|
+
process.exit(0)
|
|
223
306
|
} else if (args.includes("--readme")){
|
|
224
|
-
const content = await generateReadme(packageJson, scanDir(projectRoot, 0))
|
|
307
|
+
const content = await generateReadme(packageJson, scanDir(projectRoot, 0, config))
|
|
225
308
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
+
}
|
|
229
338
|
} else {
|
|
230
|
-
console.log(
|
|
339
|
+
console.log(`
|
|
340
|
+
Unknown command.
|
|
341
|
+
Run "mdsmith --help" for usage.
|
|
342
|
+
`)
|
|
343
|
+
process.exit(0)
|
|
231
344
|
}
|
|
232
345
|
}
|
|
233
346
|
|
|
234
|
-
main()
|
|
347
|
+
main()
|
|
348
|
+
|