-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathdocs.js
42 lines (35 loc) · 1.12 KB
/
docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { execSync } = require('child_process')
const { readdirSync, statSync } = require('fs')
console.log(`### \`shep\``)
console.log('```')
console.log(execSync(`./cli.js --help`).toString().replace(/cli\.js/, 'shep').trim())
console.log('```')
const commandDir = './src/commands'
const allFiles = readdirSync(commandDir)
const mainCommands = allFiles
.filter(isFile)
const subCommands = allFiles
.filter(isDir)
.map(findSubCommands)
.reduce(flatten)
const allCommands = mainCommands.concat(subCommands).map((c) => c.replace(/\.js/g, '')).sort()
allCommands.forEach((command) => {
let help = execSync(`./cli.js ${command} --help`).toString().replace(/cli\.js/, 'shep').trim()
console.log(`#### \`shep ${command}\``)
console.log('```')
console.log(help)
console.log('```')
})
function isDir (path) {
return statSync(`${commandDir}/${path}`).isDirectory()
}
function isFile (path) {
return statSync(`${commandDir}/${path}`).isFile()
}
function findSubCommands (path) {
return readdirSync(`${commandDir}/${path}`)
.map((c) => `${path} ${c}`)
}
function flatten (acc, arr) {
return acc.concat(arr)
}