0%

Software Engineering Notes

軟體工程筆記, using Javasript

Linter

ESLint

http://eslint.org/
https://github.com/eslint/eslint

$ npm install eslint -g(x) or npm install eslint --save-dev(o)
$ cd project-folder
$ eslint --init

Editor package name

Sublime

SublimeLinter
SublimeLinter-contrib-eslint

VS Code

ESLint

My Config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// .eslintrc.js
module.exports = {
"extends": "standard",
"plugins": [
"standard",
"promise"
],
"env": {
"mocha": true
},
"rules": {
"indent": [
"error",
4
],
"semi": [
"error",
"never"
]
}
};

Style References

https://github.com/feross/standard
https://github.com/airbnb/javascript
https://google.github.io/styleguide/jsguide.html

Unit Test

Mocha

JavaScript Test Framework
https://mochajs.org/
https://github.com/mochajs/mocha
npm install mocha -g(x) or npm install mocha --save-dev(o)

Assertion Library

choose one

TDD+BDD

http://chaijs.com
https://github.com/chaijs/chai
npm install chai --save-dev
npm install chai-as-promised --save-dev

BDD

http://shouldjs.github.io/
https://github.com/shouldjs/should.js
npm install should --save-dev

BDD

https://github.com/Automattic/expect.js

Continuous Integration

Travis CI

https://travis-ci.org/

1
2
3
4
5
6
language: node_js
node_js:
- '7'
- '6'
script: npm run ci
# default command if not specify: npm run test

Jenkins

https://jenkins.io/
https://github.com/jenkinsci/jenkins

Installing Jenkins on Ubuntu

https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu

systemctl status jenkins.service
sudo systemctl start jenkins.service

http://loclahost:8080

sudo vim /var/lib/jenkins/secrets/initialAdminPassword
要存起來 之後就不見了

/var/log/jenkins/ Log生很快,容量超大

加入ssh key 到 github & jenkins

讓jenkins可以Clone with SSH
sudo su jenkins
ssh-keygen
cat .ssh/id_rsa.pub to github.com
Jenkins > Credentials > System > Global credentials (unrestricted)Add Credentials 加入ssh

Proxy

可以收HTTP Request for webhook & 好看的網址
sudo a2enmod proxy proxy_http
sudo systemctl restart apache2.service
cd /etc/apache2/sites-available
sudo cp 000-default.conf jenkins.conf
sudo vim jenkins.conf
sudo a2ensite jenkins.conf

1
2
3
4
5
6
7
8
9
10
11
12
<VirtualHost *:80>
ServerName "YOUR_JENKINS_URL"
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass / http://localhost:8080/ nocanon
AllowEncodedSlashes NoDecode
</VirtualHost>

Jenkins > Jenkins Location > Jenkins URL > "YOUR_JENKINS_URL" > Apply

Build On Push (need setup proxy first)

Jenkins > Manage Jenkins > Configure System > 往下拉看到GitHub > Advanced... > Manage additional GitHub actions(Convert login and password to token) -> From login and password -> 拿到persional access token之後點上面 Add GitHub Server -> Credentials輸入剛剛的token -> Apply
似乎要 uncheck “manage hooks” 不然github上的設定會不見
http://jagdeesh1009.blogspot.tw/2016/04/jenkins-github-hooks-problems.html

到github專案網址 > Settings > Integrations & services > Add service > 搜尋Jenkins (GitHub plugin) > 輸入URL(預設http://x.x.x.x/github-webhook/) > 確定
可以點進去按Test

Jenkins > Your Project > Configure > Build Triggers > 勾GitHub hook trigger for GITScm polling

現在可到專案看 GitHub Hook Log

Plugins

embeddable-build-status
https://plugins.jenkins.io/embeddable-build-status
https://wiki.jenkins-ci.org/display/JENKINS/Embeddable+Build+Status+Plugin

Restart Jenkins Url

http://loclahost:8080/safeRestart/