Skip to content

Commit

Permalink
add: 添加eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongwilee committed Aug 13, 2017
1 parent 04ef44d commit f8945d7
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 28 deletions.
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
"env": {
"node": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
6 changes: 1 addition & 5 deletions bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

'use strict';

global.Promise = require('bluebird')
global.Promise = require('bluebird');


const http = require('http');
const fs = require('fs');
const path = require('path');
const utils = require('../src/utils');

const args = utils.parseArg();
Expand Down
6 changes: 2 additions & 4 deletions config/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
* 默认公共配置文件
*/

"use strict";

let env = process.env.NODE_ENV || 'development';
'use strict';

module.exports = {
// 用以配置不在代码仓储中的配置文件
extend: './config/server.json'
}
};
4 changes: 2 additions & 2 deletions config/main.production.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';

process.env.DEBUG = process.env.DEBUG || 'koa-grace-error:*';

Expand Down Expand Up @@ -104,4 +104,4 @@ module.exports = {

// session配置
session: {}
}
};
4 changes: 2 additions & 2 deletions config/main.testing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';

process.env.DEBUG = process.env.DEBUG || 'koa-grace*';

Expand Down Expand Up @@ -105,4 +105,4 @@ module.exports = {

// session配置
session: {}
}
};
4 changes: 2 additions & 2 deletions middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const curPath = __dirname;
fs.readdirSync(curPath).forEach((item) => {
let filePath = `${curPath}/${item}/index.js`;
if (fs.existsSync(filePath)) {
exports[item] = require(filePath)
exports[item] = require(filePath);
}
})
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"swiger": "0.0.2"
},
"devDependencies": {
"eslint": "^4.4.1",
"mm": "^2.0.0",
"mocha": "^3.1.0",
"nodemon": "^1.10.2",
Expand Down
11 changes: 6 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

const path = require('path');
const koa = require('koa');
const Middles = require('../middleware/')
const Middles = require('../middleware/');

const config = global.config;
const app = new koa();

// compress(gzip)
Expand Down Expand Up @@ -34,19 +35,19 @@ let vhosts = Object.keys(config.vhost).map((item) => {
// 如果在csrf的module名单里才使用csrf防护功能
config.csrf.module.indexOf(appName) > -1 && vapp.use(Middles.secure(vapp, {
throw: true
}))
}));

// 在开发环境才使用mock数据功能
config.site.env == 'development' && vapp.use(Middles.mock(vapp, {
root: appPath + '/mock/',
prefix: config.mock.prefix + appName
}))
}));

// 如果配置了连接数据库
config.mongo.api[appName] && vapp.use(Middles.mongo(vapp, {
root: appPath + '/model/mongo',
connect: config.mongo.api[appName]
}))
}));

// 配置api
vapp.use(Middles.proxy(vapp, config.api, {
Expand Down Expand Up @@ -87,7 +88,7 @@ let vhosts = Object.keys(config.vhost).map((item) => {
return {
host: item,
app: vapp
}
};
});

// 注入vhosts路由
Expand Down
3 changes: 1 addition & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const fs = require('fs');
const path = require('path');
const extend = require('extend');

Expand Down Expand Up @@ -40,4 +39,4 @@ module.exports = function config(args) {
}

return cfg;
}
};
10 changes: 4 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ exports.parseArg = function parseArg() {
let argvs = process.argv;
let result = {};

let REG = /^--[a-zA-Z0-9]+\=[a-zA-Z0-9]+$/;
let REG = /^--[a-zA-Z0-9]+=[a-zA-Z0-9]+$/;

argvs.map(function(item) {
if (!REG.test(item)) {
return
}
if (!REG.test(item)) return;

let arr = item.split('=');
let key = arr[0].slice(2);

result[key] = arr[1];
})
});

return result;
}
};

0 comments on commit f8945d7

Please sign in to comment.