forked from hubotio/hubot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
40 lines (32 loc) · 1.13 KB
/
index.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
'use strict'
require('coffeescript/register')
const inherits = require('util').inherits
const hubotExport = require('./es2015')
// make all es2015 class declarations compatible with CoffeeScript’s extend
// see https://github.com/hubotio/evolution/pull/4#issuecomment-306437501
module.exports = Object.keys(hubotExport).reduce((map, current) => {
if (current !== 'loadBot') {
map[current] = makeClassCoffeeScriptCompatible(hubotExport[current])
} else {
map[current] = hubotExport[current]
}
return map
}, {})
function makeClassCoffeeScriptCompatible (klass) {
function CoffeeScriptCompatibleClass () {
const Hack = Function.prototype.bind.apply(klass, [null].concat([].slice.call(arguments)))
const instance = new Hack()
// pass methods from child to returned instance
for (const key in this) {
instance[key] = this[key]
}
// support for constructor methods which call super()
// in which this.* properties are set
for (const key in instance) {
this[key] = instance[key]
}
return instance
}
inherits(CoffeeScriptCompatibleClass, klass)
return CoffeeScriptCompatibleClass
}