2016-06-21 05:57:54 +08:00
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
const processors = fs.readdirSync(__dirname)
|
|
|
|
.filter((file) => file !== 'index.js')
|
|
|
|
.map((file) => {
|
2016-06-23 01:59:22 +08:00
|
|
|
const {processMessage, order} = require(`./${file}`)
|
2016-06-28 07:05:31 +08:00
|
|
|
if (!processMessage) {
|
|
|
|
throw new Error(`${file} does not export a method named processMessage.`)
|
2016-06-23 01:59:22 +08:00
|
|
|
}
|
2016-06-28 07:05:31 +08:00
|
|
|
return {processMessage, order}
|
2016-06-21 05:57:54 +08:00
|
|
|
})
|
2016-06-28 07:05:31 +08:00
|
|
|
.sort((p1, p2) => p1.order - p2.order)
|
|
|
|
.map((p) => p.processMessage)
|
2016-06-21 05:57:54 +08:00
|
|
|
|
|
|
|
module.exports = {processors}
|