-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript #4
base: master
Are you sure you want to change the base?
JavaScript #4
Changes from 1 commit
6dcd2f4
7d3b514
fbc1e10
cf16911
93ada84
6bbe7a5
3d3fd6a
d499b70
7ce6add
5575a5f
f87f365
853491d
1008fa7
1d91ad8
cbd1fc2
837bd2f
0556920
df32778
b0655b9
a400b15
a8dee2d
3d3c579
10e2a51
d2d3938
6fbb8af
114937e
908a971
f693a59
6d19dcd
824481b
b21b7a0
f6cc3ba
be1550c
fc03570
8a77fec
ebf1bfe
f1a9cfe
25e0c30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,6 @@ Converting of all CoffeeScript to JavaScript which can run natively on Node 4 ([ | |
|
||
## Detailed process | ||
|
||
**TODO:** make one or two sample CoffeeScript to JavaScript conversions (I’m working on it right now and will make it part of the proposal PR for the evolution repository) | ||
|
||
The steps of the conversation will be | ||
|
||
- [ ] Convert source files from CoffeeScript to JavaScript. | ||
|
@@ -39,6 +37,8 @@ The steps of the conversation will be | |
- [ ] add script for JavaScript linting | ||
- [ ] Update documentation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything in hubotio/hubot#1327 should also be in this list, especially https://github.com/github/generator-hubot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation should be updated before the release. I want to make sure that the files that are packaged include updated documentation with how to use the Javascript support. |
||
|
||
See also [examples](#examples) below | ||
|
||
### Convert source files from CoffeeScript to JavaScript | ||
|
||
Convert all source files from CoffeeScript to JavaScript with a tool like [decaffeinate](https://github.com/decaffeinate/decaffeinate), see also [github/hubot#1138](https://github.com/github/hubot/issues/1138). | ||
|
@@ -104,3 +104,189 @@ Only breaking change is dropping support of Node 0.10 and 0.12. | |
The reason we decided against it is that the complexity of Hubot core is not too high, the code can be made very readable even when using Promises. Once the one-time conversion from CoffeeScript to JavaScript is done, only smaller parts of the code base will be touched, the effect of async/await vs. promises will be limited. | ||
|
||
More importantly, we would make it much harder for existing users to upgrade to the new Hubot version. Hubot is a widely used project and having a clear upgrade plan with a reasonable pace is critical. If we only drop support for versions which are no longer maintained we can align with Node’s [LTS schedule](https://github.com/nodejs/LTS#readme) so we can avoid a recurring discussion of when to drop support for what versions once and for all. | ||
|
||
<a name="examples"></a> | ||
## Examples | ||
|
||
- [`index.coffee`](#example1) | ||
- [`src/robot.coffee`](#example2) | ||
|
||
<a name="example1"></a> | ||
### `index.coffee` | ||
|
||
Original CoffeeScript | ||
|
||
```coffeescript | ||
User = require './src/user' | ||
Brain = require './src/brain' | ||
Robot = require './src/robot' | ||
Adapter = require './src/adapter' | ||
Response = require './src/response' | ||
{Listener,TextListener} = require './src/listener' | ||
{Message,TextMessage,EnterMessage,LeaveMessage,TopicMessage,CatchAllMessage} = require './src/message' | ||
|
||
module.exports = { | ||
User | ||
Brain | ||
Robot | ||
Adapter | ||
Response | ||
Listener | ||
TextListener | ||
Message | ||
TextMessage | ||
EnterMessage | ||
LeaveMessage | ||
TopicMessage | ||
CatchAllMessage | ||
} | ||
|
||
module.exports.loadBot = (adapterPath, adapterName, enableHttpd, botName, botAlias) -> | ||
new Robot adapterPath, adapterName, enableHttpd, botName, botAlias | ||
``` | ||
|
||
JavaScript compatible with Node 4 | ||
|
||
```javascript | ||
'use strict' | ||
|
||
const User = require('./src/user') | ||
const Brain = require('./src/brain') | ||
const Robot = require('./src/robot') | ||
const Adapter = require('./src/adapter') | ||
const Response = require('./src/response') | ||
const Listener = require('./src/listener') | ||
const Message = require('./src/message') | ||
|
||
module.exports = { | ||
User, | ||
Brain, | ||
Robot, | ||
Adapter, | ||
Response, | ||
Listener: Listener.Listener, | ||
TextListener: Listener.TextListener, | ||
Message: Message.Message, | ||
TextMessage: Message.TextMessage, | ||
EnterMessage: Message.EnterMessage, | ||
LeaveMessage: Message.LeaveMessage, | ||
TopicMessage: Message.TopicMessage, | ||
CatchAllMessage: Message.CatchAllMessage, | ||
|
||
loadBot (adapterPath, adapterName, enableHttpd, botName, botAlias) { | ||
return new Robot(adapterPath, adapterName, enableHttpd, botName, botAlias) | ||
} | ||
} | ||
|
||
module.exports.loadBot = function loadBot (adapterPath, adapterName, enableHttpd, botName, botAlias) { | ||
return new Robot(adapterPath, adapterName, enableHttpd, botName, botAlias) | ||
} | ||
``` | ||
|
||
JavaScript compatible with Node 7.6+ | ||
|
||
```js | ||
const User = require('./src/user') | ||
const Brain = require('./src/brain') | ||
const Robot = require('./src/robot') | ||
const Adapter = require('./src/adapter') | ||
const Response = require('./src/response') | ||
const {Listener, TextListener} = require('./src/listener') | ||
const {Message, TextMessage, EnterMessage, LeaveMessage, TopicMessage, CatchAllMessage} = require('./src/message') | ||
|
||
module.exports = { | ||
User, | ||
Brain, | ||
Robot, | ||
Adapter, | ||
Response, | ||
Listener, | ||
TextListener, | ||
Message, | ||
TextMessage, | ||
EnterMessage, | ||
LeaveMessage, | ||
TopicMessage, | ||
CatchAllMessage, | ||
|
||
loadBot (adapterPath, adapterName, enableHttpd, botName, botAlias) { | ||
return new Robot(adapterPath, adapterName, enableHttpd, botName, botAlias) | ||
} | ||
} | ||
``` | ||
|
||
<a name="example2"></a> | ||
### `src/robot.coffee` (excerpt) | ||
|
||
Original | ||
|
||
```coffeescript | ||
class Robot | ||
|
||
constructor: (adapterPath, adapter, httpd, name = 'Hubot', alias = false) -> | ||
@adapterPath ?= Path.join __dirname, "adapters" | ||
|
||
@name = name | ||
|
||
@on 'error', (err, res) => | ||
@invokeErrorHandlers(err, res) | ||
@onUncaughtException = (err) => | ||
@emit 'error', err | ||
process.on 'uncaughtException', @onUncaughtException | ||
|
||
send: (envelope, strings...) -> | ||
@adapter.send envelope, strings... | ||
``` | ||
|
||
JavaScript compatible with Node 4 | ||
|
||
```javascript | ||
'use strict' | ||
|
||
class Robot { | ||
constructor (adapterPath, adapter, httpd, name, alias) { | ||
if (name == null) { name = 'Hubot' } | ||
if (alias == null) { alias = false } | ||
|
||
this.name = name | ||
|
||
this.on('error', (err, res) => { | ||
return this.invokeErrorHandlers(err, res) | ||
}) | ||
this.onUncaughtException = err => { | ||
return this.emit('error', err) | ||
} | ||
process.on('uncaughtException', this.onUncaughtException) | ||
} | ||
|
||
send (envelope /*, ...strings */) { | ||
const strings = [].slice.call(arguments, 1) | ||
return this.adapter.send(envelope, strings) | ||
} | ||
} | ||
``` | ||
|
||
JavaScript compatible with Node 7.6+ | ||
|
||
```javascript | ||
class Robot { | ||
constructor (adapterPath, adapter, httpd, name, alias) { | ||
if (name == null) { name = 'Hubot' } | ||
if (alias == null) { alias = false } | ||
|
||
this.name = name | ||
|
||
this.on('error', (err, res) => { | ||
return this.invokeErrorHandlers(err, res) | ||
}) | ||
this.onUncaughtException = err => { | ||
return this.emit('error', err) | ||
} | ||
process.on('uncaughtException', this.onUncaughtException) | ||
} | ||
|
||
send (envelope, ...strings) { | ||
return this.adapter.send(envelope, ...Array.from(strings)) | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intent to do each of these as a PR per item? One big PRs? Some combination?