Skip to content

Commit c5f3fda

Browse files
committed
Use ESLint and JSCS
1 parent f9661cf commit c5f3fda

17 files changed

+140
-166
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
coverage/
3+
tmp/

.eslintrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "hexo",
3+
"root": true
4+
}

.jscsrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"excludeFiles": ["node_modules/**", "coverage/**", "tmp/**"],
3+
"preset": "hexo"
4+
}

.jshintrc

-13
This file was deleted.

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ test/
22
tmp/
33
coverage/
44
*.log
5-
.jshintrc
65
.travis.yml
76
gulpfile.js
87
.idea/

.travis.yml

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
language: node_js
22

3-
node_js:
4-
- "0.10"
5-
- "0.11"
3+
sudo: false
4+
5+
cache:
6+
apt: true
7+
directories:
8+
- node_modules
69

7-
before_script:
8-
- git config --global user.email "[email protected]"
9-
- git config --global user.name "John Doe"
10+
node_js:
11+
- "0.12"
12+
- "4"
13+
- "5"
1014

1115
script:
12-
- npm test
16+
- npm run eslint
17+
- npm run jscs
18+
- npm run test-cov
1319

1420
after_script:
21+
- npm install coveralls
1522
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

appveyor.yml

+11-17
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,36 @@
1-
# Based on https://github.com/gruntjs/grunt/blob/master/appveyor.yml
2-
# http://www.appveyor.com/docs/appveyor-yml
3-
41
# Fix line endings in Windows. (runs before repo cloning)
52
init:
63
- git config --global core.autocrlf input
7-
- git config --global user.email "[email protected]"
8-
- git config --global user.name "John Doe"
94

105
# Test against these versions of Node.js.
116
environment:
127
matrix:
13-
- nodejs_version: "0.10"
14-
- nodejs_version: "0.11"
8+
- nodejs_version: "0.12"
9+
- nodejs_version: "4"
10+
- nodejs_version: "5"
1511

16-
# Allow failing jobs for bleeding-edge Node.js versions.
1712
matrix:
18-
allow_failures:
19-
- nodejs_version: "0.11"
13+
fast_finish: true
2014

2115
# Install scripts. (runs after repo cloning)
2216
install:
23-
# Get the latest stable version of Node 0.STABLE.latest
2417
- ps: Install-Product node $env:nodejs_version
25-
# Typical npm stuff.
18+
- npm install -g npm
2619
- npm install
2720

21+
cache:
22+
- node_modules -> package.json
23+
2824
# Post-install test scripts.
2925
test_script:
3026
# Output useful info for debugging.
3127
- node --version
3228
- npm --version
33-
# We test multiple Windows shells because of prior stdout buffering issues
34-
# filed against Grunt. https://github.com/joyent/node/issues/3584
35-
- ps: "npm test # PowerShell" # Pass comment to PS for easier debugging
36-
- cmd: npm test
29+
# Run tests
30+
- npm test
3731

3832
# Don't actually build.
3933
build: off
4034

4135
# Set build version format here instead of in the admin panel.
42-
version: "{build}"
36+
version: "{build}"

gulpfile.js

-37
This file was deleted.

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
hexo.extend.deployer.register('git', require('./lib/deployer'));
1+
/* global hexo */
2+
'use strict';
3+
4+
hexo.extend.deployer.register('git', require('./lib/deployer'));

lib/deployer.js

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
'use strict';
2+
13
var pathFn = require('path');
24
var fs = require('hexo-fs');
35
var chalk = require('chalk');
46
var swig = require('swig');
57
var moment = require('moment');
6-
var util = require('hexo-util');
8+
var spawn = require('hexo-util/lib/spawn');
79
var parseConfig = require('./parse_config');
8-
var spawn = util.spawn;
910

1011
var swigHelpers = {
11-
now: function(format){
12+
now: function(format) {
1213
return moment().format(format);
1314
}
1415
};
1516

16-
module.exports = function(args){
17+
module.exports = function(args) {
1718
var baseDir = this.base_dir;
1819
var deployDir = pathFn.join(baseDir, '.deploy_git');
1920
var publicDir = this.public_dir;
2021
var log = this.log;
2122
var message = commitMessage(args);
2223
var verbose = !args.silent;
2324

24-
if (!args.repo && !args.repository){
25+
if (!args.repo && !args.repository) {
2526
var help = '';
2627

2728
help += 'You have to configure the deployment settings in _config.yml first!\n\n';
@@ -37,11 +38,11 @@ module.exports = function(args){
3738
return;
3839
}
3940

40-
function git(){
41+
function git() {
4142
var len = arguments.length;
4243
var args = new Array(len);
4344

44-
for (var i = 0; i < len; i++){
45+
for (var i = 0; i < len; i++) {
4546
args[i] = arguments[i];
4647
}
4748

@@ -51,46 +52,46 @@ module.exports = function(args){
5152
});
5253
}
5354

54-
function setup(){
55+
function setup() {
5556
// Create a placeholder for the first commit
56-
return fs.writeFile(pathFn.join(deployDir, 'placeholder'), '').then(function(){
57+
return fs.writeFile(pathFn.join(deployDir, 'placeholder'), '').then(function() {
5758
return git('init');
58-
}).then(function(){
59+
}).then(function() {
5960
return git('add', '-A');
60-
}).then(function(){
61+
}).then(function() {
6162
return git('commit', '-m', 'First commit');
6263
});
6364
}
6465

65-
function push(repo){
66-
return git('add', '-A').then(function(){
67-
return git('commit', '-m', message).catch(function(){
66+
function push(repo) {
67+
return git('add', '-A').then(function() {
68+
return git('commit', '-m', message).catch(function() {
6869
// Do nothing. It's OK if nothing to commit.
6970
});
70-
}).then(function(){
71+
}).then(function() {
7172
return git('push', '-u', repo.url, 'HEAD:' + repo.branch, '--force');
7273
});
7374
}
7475

75-
return fs.exists(deployDir).then(function(exist){
76+
return fs.exists(deployDir).then(function(exist) {
7677
if (exist) return;
7778

7879
log.info('Setting up Git deployment...');
7980
return setup();
80-
}).then(function(){
81+
}).then(function() {
8182
log.info('Clearing .deploy_git folder...');
8283
return fs.emptyDir(deployDir);
83-
}).then(function(){
84+
}).then(function() {
8485
log.info('Copying files from public folder...');
8586
return fs.copyDir(publicDir, deployDir);
86-
}).then(function(){
87+
}).then(function() {
8788
return parseConfig(args);
88-
}).each(function(repo){
89+
}).each(function(repo) {
8990
return push(repo);
9091
});
9192
};
9293

93-
function commitMessage(args){
94+
function commitMessage(args) {
9495
var message = args.m || args.msg || args.message || 'Site updated: {{ now(\'YYYY-MM-DD HH:mm:ss\') }}';
9596
return swig.compile(message)(swigHelpers);
96-
}
97+
}

lib/parse_config.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
'use strict';
2+
13
var rRepoURL = /^(?:(?:git|https?|git\+https|git\+ssh):\/\/)?(?:[^@]+@)?([^\/]+?)[\/:](.+?)\.git$/;
24
var rGithubPage = /\.github\.(io|com)$/;
35

4-
function parseRepo(repo){
6+
function parseRepo(repo) {
57
var split = repo.split(',');
68
var url = split.shift();
79
var branch = split[0];
810

9-
if (!branch && rRepoURL.test(url)){
11+
if (!branch && rRepoURL.test(url)) {
1012
var match = url.match(rRepoURL);
1113
var host = match[1];
1214
var path = match[2];
1315

14-
if (host === 'github.com'){
16+
if (host === 'github.com') {
1517
branch = rGithubPage.test(path) ? 'master' : 'gh-pages';
16-
} else if (host === 'gitcafe.com'){
18+
} else if (host === 'gitcafe.com') {
1719
branch = 'gitcafe-pages';
1820
}
1921
}
@@ -24,11 +26,11 @@ function parseRepo(repo){
2426
};
2527
}
2628

27-
module.exports = function(args){
29+
module.exports = function(args) {
2830
var repo = args.repo || args.repository;
2931
if (!repo) throw new TypeError('repo is required!');
3032

31-
if (typeof repo === 'string'){
33+
if (typeof repo === 'string') {
3234
var data = parseRepo(repo);
3335
data.branch = args.branch || data.branch;
3436

@@ -38,9 +40,9 @@ module.exports = function(args){
3840
var result = [];
3941
var keys = Object.keys(repo);
4042

41-
for (var i = 0, len = keys.length; i < len; i++){
43+
for (var i = 0, len = keys.length; i < len; i++) {
4244
result.push(parseRepo(repo[keys[i]]));
4345
}
4446

4547
return result;
46-
};
48+
};

package.json

+16-19
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
"description": "Git deployer plugin of Hexo.",
55
"main": "index",
66
"scripts": {
7-
"test": "gulp test"
7+
"eslint": "eslint .",
8+
"jscs": "jscs .",
9+
"test": "mocha test/index.js",
10+
"test-cov": "istanbul cover --print both _mocha -- test/index.js"
811
},
912
"directories": {
1013
"lib": "./lib"
1114
},
12-
"engines": {
13-
"node": ">= 0.10.0"
14-
},
1515
"repository": "hexojs/hexo-deployer-git",
16-
"homepage": "http://hexo.io/",
16+
"homepage": "https://hexo.io/",
1717
"keywords": [
1818
"hexo",
1919
"git",
@@ -23,22 +23,19 @@
2323
"author": "Tommy Chen <[email protected]> (http://zespia.tw)",
2424
"license": "MIT",
2525
"devDependencies": {
26-
"chai": "^1.9.1",
27-
"coveralls": "^2.11.2",
28-
"gulp": "^3.8.9",
29-
"gulp-istanbul": "^0.5.0",
30-
"gulp-jshint": "^1.8.6",
31-
"gulp-load-plugins": "^0.8.0",
32-
"gulp-mocha": "^2.0.0",
33-
"jshint-stylish": "^1.0.0",
34-
"mocha": "^2.0.1",
35-
"rimraf": "^2.2.8"
26+
"chai": "^3.5.0",
27+
"eslint": "^1.10.3",
28+
"eslint-config-hexo": "^1.0.2",
29+
"istanbul": "^0.4.2",
30+
"jscs": "^2.9.0",
31+
"jscs-preset-hexo": "^1.0.1",
32+
"mocha": "^2.4.5"
3633
},
3734
"dependencies": {
38-
"chalk": "^0.5.1",
39-
"hexo-fs": "^0.1.0",
40-
"hexo-util": "^0.1.0",
41-
"moment": "^2.8.4",
35+
"chalk": "^1.1.1",
36+
"hexo-fs": "^0.1.5",
37+
"hexo-util": "^0.5.3",
38+
"moment": "^2.11.2",
4239
"swig": "^1.4.2"
4340
}
4441
}

test/.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "hexo/test"
3+
}

0 commit comments

Comments
 (0)