Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
fix: 修改eslint,加上单元测试以及travisci
Browse files Browse the repository at this point in the history
  • Loading branch information
sydeEvans committed May 10, 2017
1 parent 6f25ab4 commit 84f9dc9
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 160 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
coverage
build
dist
node_modules
run
app/public
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "eslint-config-egg"
"extends": "eslint-config-egg",
"rules": {
"strict": "off"
}
}
4 changes: 2 additions & 2 deletions agent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

module.exports = app => {
};
module.exports = () => {
};
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

module.exports = app => {
};
module.exports = () => {
};
4 changes: 2 additions & 2 deletions app/controller/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = app => {
const page = this.ctx.params.page || 1;
const jsonResult = yield this.ctx.service.jobs.queryJobList({
p: page,
lm: 10
lm: 10,
});
const data = {
name: 'home',
list: jsonResult.data,
info: jsonResult.filter
info: jsonResult.filter,
};
yield this.ctx.render('home/index', data);
}
Expand Down
10 changes: 5 additions & 5 deletions app/extend/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
gzip {Boolean} - let you get the res object when request connected, default false. alias customResponse
*/
const querystring = require('querystring');
const url = require('url');
// const url = require('url');

module.exports = {
* fetch(api, options = {}) {
const apiHost = this.app.config.apiHost;
let {query} = options;
let { query } = options;
query = querystring.stringify(query);
let url = `${apiHost}/api${api}?${query}`;
const url = `${apiHost}/api${api}?${query}`;

const result = yield this.curl(url, Object.assign({
dataType: 'json',
timeout: 10000, // 默认超时时间
}, options));
const {data} = result;

const { data } = result;

return data;
},
Expand Down
10 changes: 9 additions & 1 deletion app/extend/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@
// this.ctx => context 对象
// this.app => application 对象

exports.util = require('util');
exports.util = require('util');
const manifest = require('../../dist/manifest.json');

exports.Loader = function(resource) {
return {
css: manifest[resource + '.css'],
js: manifest[resource + '.js'],
};
};
8 changes: 4 additions & 4 deletions app/extend/helper.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// this.app => application 对象
const url = require('url');

exports.Loader = function (resource) {
exports.Loader = function(resource) {
const publicPath = this.app.config.browsersync.options.publicPath;
return {
js: url.resolve(publicPath,resource+'.js')
}
};
js: url.resolve(publicPath, resource + '.js'),
};
};
12 changes: 0 additions & 12 deletions app/extend/helper.prod.js

This file was deleted.

20 changes: 10 additions & 10 deletions app/service/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ module.exports = app => {

class Jobs extends app.Service {
* queryJobList(query) {
const result = yield this.ctx.fetch(`/jobx/job`, {query});
const result = yield this.ctx.fetch('/jobx/job', { query });
result.data.map(item => {
item.platform.name = item.platform.name || '-';
item.more_link = `${apiHost}/api/jobx/job/${item.id}/url`
item.release_date = moment(item.release_date).startOf('day').fromNow()
item.price = numeral(item.price).format('0,0')
item.more_link = `${apiHost}/api/jobx/job/${item.id}/url`;
item.release_date = moment(item.release_date).startOf('day').fromNow();
item.price = numeral(item.price).format('0,0');
return item;
});

const total = result.total;
const {page_size, current_page} = result.filter;
const { page_size, current_page } = result.filter;
result.filter.total_page = Math.ceil(total / page_size);
result.filter.pagination = pagination(current_page, result.filter.total_page)
result.filter.pagination = pagination(current_page, result.filter.total_page);

return result;
}
Expand All @@ -39,18 +39,18 @@ module.exports = app => {

function pagination(curr, total) {
let arr = [];
for (let i = curr + 2 > total ? total:curr + 2; i > 0 && i >= curr - 2; i--) {
for (let i = curr + 2 > total ? total : curr + 2; i > 0 && i >= curr - 2; i--) {
arr.push(i);
}
arr = arr.reverse();
if (arr[0] >= 3) {
arr.unshift('...');
arr.unshift(1)
arr.unshift(1);
}

if (arr[arr.length - 1] <= total - 1) {
arr.push('...')
arr.push(total)
arr.push('...');
arr.push(total);
}

return arr;
Expand Down
28 changes: 14 additions & 14 deletions build/bs.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const path = require("path");
const path = require('path');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const {ip} = require('../build/util');
const { ip } = require('../build/util');

// return a function to ge bs config
module.exports = (config) => {
const {port,publicPath} = config;
module.exports = config => {
const { port, publicPath } = config;
const webpackConfig = require('./webpack.dev.config');
webpackConfig.output.publicPath = publicPath;

// Add the client which connects to our middleware
// You can use full urls like 'webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr'
// useful if you run your app from another point like django
const hotSet = `webpack-hot-middleware/client?path=http://${ip}:${port}/__webpack_hmr&timeout=2000&overlay=false&reload=true`
const hotSet = `webpack-hot-middleware/client?path=http://${ip}:${port}/__webpack_hmr&timeout=2000&overlay=false&reload=true`;
// add dev-server entry
Object.keys(webpackConfig.entry).forEach(name => {
if (!/\./.test(name)) {
webpackConfig.entry[name] = [hotSet].concat(webpackConfig.entry[name]);
webpackConfig.entry[name] = [ hotSet ].concat(webpackConfig.entry[name]);
}
});

Expand All @@ -26,7 +26,7 @@ module.exports = (config) => {
return {
init: true,
files: [
"app/view/**/*",
'app/view/**/*',
// "app/public/**/*"
],
logConnections: false,
Expand All @@ -40,12 +40,12 @@ module.exports = (config) => {
publicPath: webpackConfig.output.publicPath,

// pretty colored output
stats: {colors: true},
stats: { colors: true },

headers: {
'X-information': 'egg-webpack-dev-server',
'Access-Control-Allow-Origin': '*',
}
},

// for other settings see
// http://webpack.github.io/docs/webpack-dev-middleware.html
Expand All @@ -54,9 +54,9 @@ module.exports = (config) => {
// bundler should be the same as above
webpackHotMiddleware(bundler, {
log: false,
path: "/__webpack_hmr",
heartbeat: 2000
})
]
path: '/__webpack_hmr',
heartbeat: 2000,
}),
],
};
};
};
8 changes: 4 additions & 4 deletions build/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const os = require('os');
function getIp() {
let host = null;
try {
host = os.networkInterfaces()['en0'].find(ip => ip.family === 'IPv4').address
}catch (e){
host = '127.0.0.1'
host = os.networkInterfaces().en0.find(ip => ip.family === 'IPv4').address;
} catch (e) {
host = '127.0.0.1';
}

return host;
}

module.exports = {
ip:getIp()
ip: getIp(),
};
10 changes: 5 additions & 5 deletions build/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {

entry: {
// Add the client which connects to our middleware
home: ['./app/public/home/index.js'],
about: ['./app/public/about/index.js'],
home: [ './app/public/home/index.js' ],
about: [ './app/public/about/index.js' ],
},

externals: {
jquery: "jQuery"
}
jquery: 'jQuery',
},

};
};
12 changes: 6 additions & 6 deletions build/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ const devConfig = {
{
test: /\.css$/,
use: [
"style-loader",
"css-loader",
'style-loader',
'css-loader',
],
},
{
test: /\.less$/i,
use: [
"style-loader",
"css-loader",
"less-loader"
'style-loader',
'css-loader',
'less-loader',
],
},
],
Expand All @@ -43,4 +43,4 @@ const devConfig = {
],
};

module.exports = merge(baseConfig,devConfig);
module.exports = merge(baseConfig, devConfig);
38 changes: 19 additions & 19 deletions build/webpack.prod.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const path = require("path");
const path = require('path');
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.config');

Expand All @@ -11,47 +11,47 @@ const extractLESS = new ExtractTextPlugin('[name]/index.[contenthash].css');

const prodConfig = {
output: {
path: path.resolve(__dirname, "../dist"),
path: path.resolve(__dirname, '../dist'),
publicPath: '/public/',
filename: '[name]/index.[chunkhash].js'
filename: '[name]/index.[chunkhash].js',
},
module: {
rules:[
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, "../app"),
include: path.resolve(__dirname, '../app'),
// exclude: /node_modules/,
loader: 'babel-loader'
loader: 'babel-loader',
},
{
test: /\.css$/,
use: extractCSS.extract([ {
use: extractCSS.extract([{
loader: 'css-loader',
options: {
minimize: true
}
}])
minimize: true,
},
}]),
},
{
test: /\.less$/i,
use: extractLESS.extract([ {
use: extractLESS.extract([{
loader: 'css-loader',
options: {
minimize: true
}
}, 'less-loader' ])
minimize: true,
},
}, 'less-loader' ]),
},
]
],
},
node: {Buffer: false},
node: { Buffer: false },
devtool: false,
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
extractLESS,//设置其路径(路径相对于path)
extractLESS, // 设置其路径(路径相对于path)
extractCSS,
new WebpackAssetsManifest({
output: 'manifest.json',
Expand All @@ -61,7 +61,7 @@ const prodConfig = {
fileExtRegex: /\.\w{2,4}\.(?:map|gz)$|\.\w+$/i,
sortManifest: true,
merge: false,
publicPath: '/public/'
publicPath: '/public/',
}),
new webpack.optimize.UglifyJsPlugin({
output: {
Expand All @@ -76,4 +76,4 @@ const prodConfig = {
],
};

module.exports = merge(baseConfig,prodConfig);
module.exports = merge(baseConfig, prodConfig);
2 changes: 1 addition & 1 deletion config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = appInfo => {
};


config.apiHost ='https://remotex.ooclab.org';
config.apiHost = 'https://remotex.ooclab.org';

return config;
};
Loading

0 comments on commit 84f9dc9

Please sign in to comment.