mdsmith 1.1.0 β 1.1.2
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 +13 -13
- package/bin/index.js +175 -59
- package/mdsmith.config.json +8 -0
- package/package.json +2 -1
package/README-MDSMITH.md
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
|
|
2
|
-
#
|
|
2
|
+
# Docuapi
|
|
3
3
|
|
|
4
4
|
CLI para gerar READMEs e arquivos Markdown
|
|
5
5
|
|
|
6
|
-
## π
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
6
|
+
## π Project Info
|
|
7
|
+
- **Version:** 1.1.1
|
|
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
|
-
π package-lock.json
|
|
20
|
+
π mdsmith.config.json
|
|
21
21
|
π package.json
|
|
22
22
|
π README-MDSMITH.md
|
|
23
23
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## π Scripts
|
|
27
|
-
|
|
26
|
+
## π Available Scripts
|
|
27
|
+
No scripts available.
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
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,16 +64,24 @@ 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
|
+
if (config.ignore.includes(entry.name)){
|
|
81
|
+
continue
|
|
82
|
+
} else{
|
|
83
|
+
treeContent += `${" ".repeat(padding*2)} π ${entry.name}\n`
|
|
84
|
+
}
|
|
63
85
|
}
|
|
64
86
|
}
|
|
65
87
|
|
|
@@ -78,26 +100,28 @@ async function buscarNome(nome){
|
|
|
78
100
|
let respostaValida = false
|
|
79
101
|
let resposta = ""
|
|
80
102
|
while(!respostaValida){
|
|
81
|
-
resposta = await perguntar(
|
|
82
|
-
|
|
103
|
+
resposta = await perguntar(`
|
|
104
|
+
Project name not found in package.json.
|
|
105
|
+
Would you like to provide one? (y/n): `)
|
|
106
|
+
resposta = resposta.trim().toLowerCase()
|
|
83
107
|
|
|
84
108
|
if(resposta == "y" || resposta == "n"){
|
|
85
109
|
respostaValida = true
|
|
86
110
|
}else {
|
|
87
|
-
console.log("
|
|
111
|
+
console.log("Please type y or n.")
|
|
88
112
|
}
|
|
89
113
|
}
|
|
90
114
|
|
|
91
115
|
|
|
92
116
|
if(resposta == "n"){
|
|
93
|
-
console.log("
|
|
94
|
-
return "
|
|
117
|
+
console.log("\nProject name will be set as Unnamed Project.\n")
|
|
118
|
+
return "Unnamed Project"
|
|
95
119
|
}if(resposta == "y"){
|
|
96
|
-
let nome = await perguntar("
|
|
97
|
-
console.log(
|
|
120
|
+
let nome = await perguntar("Enter the project name: ")
|
|
121
|
+
console.log(`Project name set to "${nome}".`)
|
|
98
122
|
return nome
|
|
99
123
|
}else{
|
|
100
|
-
console.error("
|
|
124
|
+
console.error("Failed to generate project name.")
|
|
101
125
|
process.exit(1)
|
|
102
126
|
}
|
|
103
127
|
}
|
|
@@ -111,26 +135,28 @@ async function buscarDescricao(descricao){
|
|
|
111
135
|
let respostaValida = false
|
|
112
136
|
let resposta = ""
|
|
113
137
|
while(!respostaValida){
|
|
114
|
-
resposta = await perguntar(
|
|
115
|
-
|
|
138
|
+
resposta = await perguntar(`
|
|
139
|
+
Project description not found.
|
|
140
|
+
Would you like to provide one? (y/n): `)
|
|
141
|
+
resposta = resposta.trim().toLowerCase()
|
|
116
142
|
|
|
117
143
|
if(resposta == "y" || resposta == "n"){
|
|
118
144
|
respostaValida = true
|
|
119
145
|
}else {
|
|
120
|
-
console.log("
|
|
146
|
+
console.log("Please type y or n.")
|
|
121
147
|
}
|
|
122
148
|
}
|
|
123
149
|
|
|
124
150
|
|
|
125
151
|
if(resposta == "n"){
|
|
126
|
-
console.log("\
|
|
127
|
-
return "*
|
|
152
|
+
console.log("\nDescription placeholder added.\n")
|
|
153
|
+
return "*Project description goes here*"
|
|
128
154
|
}if(resposta == "y"){
|
|
129
|
-
let descricao = await perguntar("
|
|
130
|
-
console.log("\
|
|
155
|
+
let descricao = await perguntar("Enter the project description: ")
|
|
156
|
+
console.log("\nDescription saved.\n")
|
|
131
157
|
return descricao
|
|
132
158
|
}else{
|
|
133
|
-
console.error("
|
|
159
|
+
console.error("Failed to generate project description.")
|
|
134
160
|
process.exit(1)
|
|
135
161
|
}
|
|
136
162
|
}
|
|
@@ -149,12 +175,12 @@ function detectarTipoProjeto(packageJson) {
|
|
|
149
175
|
if (deps.express) return "API REST (Express)"
|
|
150
176
|
if (deps.typescript) return "Projeto TypeScript"
|
|
151
177
|
|
|
152
|
-
return "
|
|
178
|
+
return "Node.js Project"
|
|
153
179
|
}
|
|
154
180
|
|
|
155
181
|
function formatScripts(scripts) {
|
|
156
182
|
if (!scripts || Object.keys(scripts).length === 0) {
|
|
157
|
-
return "
|
|
183
|
+
return "No scripts available.\n";
|
|
158
184
|
}
|
|
159
185
|
|
|
160
186
|
return Object.entries(scripts)
|
|
@@ -173,62 +199,152 @@ const content = `
|
|
|
173
199
|
|
|
174
200
|
${descricaoProjeto}
|
|
175
201
|
|
|
176
|
-
## π
|
|
177
|
-
- **
|
|
178
|
-
- **
|
|
179
|
-
- **
|
|
202
|
+
## π Project Info
|
|
203
|
+
- **Version:** ${packageJson.version || "Not specified"}
|
|
204
|
+
- **Package Manager:** npm
|
|
205
|
+
- **Type:** ${detectarTipoProjeto(packageJson)}
|
|
180
206
|
|
|
181
|
-
## π
|
|
207
|
+
## π Dependencies
|
|
182
208
|
${formatDependencies(packageJson.dependencies)}
|
|
183
209
|
|
|
184
|
-
## π
|
|
210
|
+
## π Project Structure
|
|
185
211
|
\`\`\`
|
|
186
212
|
${tree}
|
|
187
213
|
\`\`\`
|
|
188
214
|
|
|
189
|
-
## π Scripts
|
|
215
|
+
## π Available Scripts
|
|
190
216
|
${formatScripts(packageJson.scripts)}
|
|
191
217
|
|
|
192
|
-
|
|
193
|
-
π *README gerado automaticamente pelo **mdSmith***
|
|
218
|
+
Generated by **mdSmith**
|
|
194
219
|
`
|
|
195
220
|
|
|
196
221
|
return content
|
|
197
222
|
|
|
198
223
|
}
|
|
199
224
|
|
|
225
|
+
function loadConfig(projectRoot) {
|
|
226
|
+
const configPath = path.join(projectRoot, "mdsmith.config.json")
|
|
227
|
+
|
|
228
|
+
if (!fs.existsSync(configPath)) {
|
|
229
|
+
return defaultConfig
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
const fileContent = fs.readFileSync(configPath, "utf-8")
|
|
234
|
+
const userConfig = JSON.parse(fileContent)
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
...defaultConfig,
|
|
238
|
+
...userConfig,
|
|
239
|
+
ignore: [
|
|
240
|
+
...defaultConfig.ignore,
|
|
241
|
+
...(userConfig.ignore || [])
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
} catch (error) {
|
|
247
|
+
console.log("Failed to read mdsmith.config.json. Using default configuration.")
|
|
248
|
+
return defaultConfig
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
200
252
|
async function main() {
|
|
253
|
+
const config = loadConfig(projectRoot)
|
|
254
|
+
|
|
201
255
|
if(args.length == 0){
|
|
202
256
|
console.log(`
|
|
203
|
-
|
|
204
|
-
|
|
257
|
+
mdSmith
|
|
258
|
+
Node.js project analyzer
|
|
259
|
+
ββββββββββββββββββββββββ
|
|
205
260
|
|
|
206
|
-
|
|
261
|
+
Run "mdsmith --help" to view available commands.
|
|
207
262
|
`);
|
|
208
263
|
process.exit(0);
|
|
264
|
+
}else if (args.includes("--init")) {
|
|
265
|
+
|
|
266
|
+
const configPath = path.join(projectRoot, "mdsmith.config.json")
|
|
267
|
+
|
|
268
|
+
if (fs.existsSync(configPath)) {
|
|
269
|
+
console.log("mdsmith.config.json already exists.")
|
|
270
|
+
process.exit(0)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
fs.writeFileSync(
|
|
274
|
+
configPath,
|
|
275
|
+
JSON.stringify(defaultConfig, null, 2)
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
console.log("Configuration file created.")
|
|
279
|
+
process.exit(0)
|
|
280
|
+
|
|
209
281
|
} else if(args.includes("--help")){
|
|
210
282
|
console.log(`
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
283
|
+
mdSmith β Available Commands
|
|
284
|
+
ββββββββββββββββββββββββ
|
|
285
|
+
|
|
286
|
+
--help Show help
|
|
287
|
+
--init Create config file
|
|
288
|
+
--tree Show project structure
|
|
289
|
+
--deps List dependencies
|
|
290
|
+
--readme Generate README
|
|
215
291
|
`)
|
|
292
|
+
process.exit(0)
|
|
216
293
|
} else if (args.includes("--tree")){
|
|
217
|
-
console.log(
|
|
218
|
-
|
|
294
|
+
console.log(`
|
|
295
|
+
Project Structure
|
|
296
|
+
ββββββββββββββββββββββββ
|
|
297
|
+
`);
|
|
298
|
+
console.log(scanDir(projectRoot, 0, config))
|
|
299
|
+
process.exit(0)
|
|
219
300
|
} else if (args.includes("--deps")){
|
|
220
|
-
console.log(`
|
|
221
|
-
|
|
301
|
+
console.log(`
|
|
302
|
+
Dependencies
|
|
303
|
+
ββββββββββββββββββββββββ
|
|
304
|
+
`)
|
|
305
|
+
const deps = formatDependencies(packageJson.dependencies)
|
|
222
306
|
console.log(deps)
|
|
307
|
+
process.exit(0)
|
|
223
308
|
} else if (args.includes("--readme")){
|
|
224
|
-
const content = await generateReadme(packageJson, scanDir(projectRoot, 0))
|
|
309
|
+
const content = await generateReadme(packageJson, scanDir(projectRoot, 0, config))
|
|
225
310
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
311
|
+
console.log(`
|
|
312
|
+
README Preview
|
|
313
|
+
ββββββββββββββββββββββββ
|
|
314
|
+
`)
|
|
315
|
+
|
|
316
|
+
console.log(content)
|
|
317
|
+
|
|
318
|
+
let respostaValida = false
|
|
319
|
+
let confirm = ""
|
|
320
|
+
|
|
321
|
+
while (!respostaValida) {
|
|
322
|
+
confirm = await perguntar("\nGenerate README-MDSMITH.md? (y/n): ")
|
|
323
|
+
confirm = confirm.trim().toLowerCase()
|
|
324
|
+
|
|
325
|
+
if (confirm === "y" || confirm === "n") {
|
|
326
|
+
respostaValida = true
|
|
327
|
+
} else {
|
|
328
|
+
console.log("\nPlease type y or n.")
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (confirm === "y") {
|
|
333
|
+
fs.writeFileSync("README-MDSMITH.md", content)
|
|
334
|
+
console.log("\nREADME-MDSMITH.md created.\n")
|
|
335
|
+
process.exit(0)
|
|
336
|
+
} else {
|
|
337
|
+
console.log("\nOperation cancelled.\n")
|
|
338
|
+
process.exit(0)
|
|
339
|
+
}
|
|
229
340
|
} else {
|
|
230
|
-
console.log(
|
|
341
|
+
console.log(`
|
|
342
|
+
Unknown command.
|
|
343
|
+
Run "mdsmith --help" for usage.
|
|
344
|
+
`)
|
|
345
|
+
process.exit(0)
|
|
231
346
|
}
|
|
232
347
|
}
|
|
233
348
|
|
|
234
|
-
main()
|
|
349
|
+
main()
|
|
350
|
+
|