Skip to content

Commit 4b7ae2f

Browse files
committed
refactor: async controllers loader
1 parent dcab51e commit 4b7ae2f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/controller.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const fs = require('fs')
33
const winston = require('winston')
44
const chalk = require('chalk')
55
const path = require('path')
6-
7-
function readDir(dir) {
8-
const files = fs.readdirSync(dir)
6+
const { promisify } = require('util')
7+
async function readDir(dir) {
8+
const files = await promisify(fs.readdir)(dir)
99
if (files.length <= 0) return
1010
const map = {}
1111
for (const file of files) {
@@ -14,9 +14,9 @@ function readDir(dir) {
1414
continue
1515
}
1616
const filePath = path.join(dir, file)
17-
const stat = fs.statSync(filePath)
17+
const stat = await promisify(fs.stat)(filePath)
1818
if (stat.isDirectory()) {
19-
const subDirMaps = readDir(filePath)
19+
const subDirMaps = await readDir(filePath)
2020
if (subDirMaps) {
2121
map[file] = map[file]
2222
? Object.assign(map[file], subDirMaps)
@@ -70,7 +70,7 @@ class controllers {
7070
async load() {
7171
try {
7272
// Load Controller
73-
const controllers = genControllersMap()
73+
const controllers = await genControllersMap()
7474
return controllers
7575
} catch (e) {
7676
winston.error(chalk.red(e))

0 commit comments

Comments
 (0)