-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (24 loc) · 805 Bytes
/
Copy pathindex.js
File metadata and controls
33 lines (24 loc) · 805 Bytes
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
const COMMAND_DIR = 'cmd'
const init = require('./lib/init')
const fs = require('fs')
const joinPath = require('path').join
const modulePath = joinPath(__dirname, COMMAND_DIR)
const fileList = fs.readdirSync(modulePath)
const fileName = /.*(?=\.)/
// Initialize module
init()
// Export all commands
for (let file of fileList) {
// Skip hidden files
if (file.startsWith('.')) continue
const exportFile = require(joinPath(modulePath, file))
const exportFunction = fileName.exec(file)[0]
// Create Promise for every command, so that they may be used asynchronously
module.exports[exportFunction] = async argv => {
const result = await exportFile.handler(argv)
return new Promise(resolve => {
resolve(result)
})
}
module.exports[exportFunction].yargs = exportFile
}