gasolin @ coscup 2016
https://hackmd.io/p/HJ7dfgVc#/
(Chat) Bot, 可以和人對話的程式
解決大家日常生活中的一些瑣碎問題
透過多種途徑查看Coscup會議交通, 地圖, 議程, …
使用npm
$ npm search hubot-scripts ... $ npm install hubot-xxx
3 行就可以寫一份 hubot 腳本
module.exports (robot) -> robot.respond /(hello)/i, (res) -> res.send 'hi';
CoffeeScript is a little language that compiles into JavaScript
支援 class, arrow function, rest argument, destructuring…
http://coffeescript.org/
module.exports = function(robot) { robot.respond(/(hello)/i, function(res) { res.send('hi'); }); }
Class, arrow function, rest argument, destructuring
執行ES6程式需要…
ES6 -> Plain Javascript
http://babeljs.io/
可以寫ES6版腳本了
module.exports = (robot) => { robot.respond(/(hello)/i, (res) => { res.send('hi'); }); }
不用 grunt, gulp, 或 Makefile 建構工具
在 package.json 裡直接加入 scripts 區塊:
"scripts": { "prebuild": "shx rm -rf dist coverage && shx mkdir dist", "build": "babel index.js -o dist/index.js && babel src -d dist/src", "postbuild": "shx cp package.json dist/", "test": "mocha --compilers js:babel-register -w", "test:single": "istanbul cover --root ./src _mocha -- 'test/**/*.js' --compilers js:babel-register -R spec", "lint": "eslint index.js bin/webby src/ test/", "report-coverage": "cat ./coverage/lcov.info | codecov" },
babel src -d dist/src
移植好一個測試後,再移植相應代測檔案
移植測試 -> 測試通過 ->
移植待測檔案 -> 測試通過 ->
移植下一個測試 ->
程式碼格式檢查
ESLint
http://eslint.org/
讓語法更符合ES6
遙遙無期阿
hubot 核心開發不活躍, review 頗慢, 幾乎不 merge…