-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump-command-info.js
52 lines (40 loc) · 1.68 KB
/
dump-command-info.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
43
44
45
46
47
48
49
50
51
52
const path = require('path')
const fs = require('fs-extra')
const requireAll = require('require-all')
;(async () => {
try {
// Remove extraneous command line parameters
process.argv.splice(0, 2)
const wildbeastPath = process.argv[0]
if (!fs.existsSync(wildbeastPath)) {
console.error(`Could not find a directory at ${wildbeastPath}! Exiting...`)
process.exit(1)
}
const commandsPath = path.join(wildbeastPath, 'src/commands')
if (!fs.existsSync(commandsPath)) {
console.log(`Could not find a valid WildBeast command directory at ${commandsPath}! Exiting...`)
process.exit(1)
}
const commandDirectory = await fs.readdir(commandsPath)
const commands = {}
for (const category of commandDirectory) {
// Having to use process.cwd() here because requires need to be relative to this file
const categoryPath = path.join(process.cwd(), commandsPath, category)
const commandsInCategory = requireAll(categoryPath)
commands[category] = {}
for (const command in commandsInCategory) {
const currentCommand = commandsInCategory[command]
// Leave out fn property as it's not relevant to this info dump, we only want the command metadata
commands[category][command] = currentCommand.props
}
}
const dataDirectory = path.join(process.cwd(), 'data')
await fs.ensureDir(dataDirectory)
const dataFile = path.join(dataDirectory, 'commands.json')
await fs.writeFile(dataFile, JSON.stringify(commands))
console.log(`Command metadata successfully dumped to ${dataFile}`)
} catch (err) {
console.error('Could not dump command information: ', err)
process.exit(1)
}
})()