diff --git a/.eslintignore b/.eslintignore index 4ebc8ae..061f845 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,6 @@ coverage +build +dist +node_modules +run +app/public \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index c799fe5..5ca6dea 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,6 @@ { - "extends": "eslint-config-egg" + "extends": "eslint-config-egg", + "rules": { + "strict": "off" + } } diff --git a/agent.js b/agent.js index 7524bcd..2c7890d 100644 --- a/agent.js +++ b/agent.js @@ -1,3 +1,3 @@ -module.exports = app => { -}; \ No newline at end of file +module.exports = () => { +}; diff --git a/app.js b/app.js index 7524bcd..2c7890d 100644 --- a/app.js +++ b/app.js @@ -1,3 +1,3 @@ -module.exports = app => { -}; \ No newline at end of file +module.exports = () => { +}; diff --git a/app/controller/home.js b/app/controller/home.js index 3d068df..293c22c 100644 --- a/app/controller/home.js +++ b/app/controller/home.js @@ -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); } diff --git a/app/extend/context.js b/app/extend/context.js index b881e14..8aebab1 100644 --- a/app/extend/context.js +++ b/app/extend/context.js @@ -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; }, diff --git a/app/extend/helper.js b/app/extend/helper.js index 928df94..6dec256 100644 --- a/app/extend/helper.js +++ b/app/extend/helper.js @@ -2,4 +2,12 @@ // this.ctx => context 对象 // this.app => application 对象 -exports.util = require('util'); \ No newline at end of file +exports.util = require('util'); +const manifest = require('../../dist/manifest.json'); + +exports.Loader = function(resource) { + return { + css: manifest[resource + '.css'], + js: manifest[resource + '.js'], + }; +}; diff --git a/app/extend/helper.local.js b/app/extend/helper.local.js index 4e1a984..720ec40 100644 --- a/app/extend/helper.local.js +++ b/app/extend/helper.local.js @@ -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') - } -}; \ No newline at end of file + js: url.resolve(publicPath, resource + '.js'), + }; +}; diff --git a/app/extend/helper.prod.js b/app/extend/helper.prod.js deleted file mode 100644 index c061658..0000000 --- a/app/extend/helper.prod.js +++ /dev/null @@ -1,12 +0,0 @@ -// this 是 helper 对象,在其中可以调用其他 helper 方法 -// this.ctx => context 对象 -// this.app => application 对象 -const manifest = require('../../dist/manifest.json'); -const url = require('url'); - -exports.Loader = function (resource) { - return { - css: manifest[resource +'.css'], - js: manifest[resource +'.js'] - } -}; \ No newline at end of file diff --git a/app/service/jobs.js b/app/service/jobs.js index f8cf129..bf76b9b 100644 --- a/app/service/jobs.js +++ b/app/service/jobs.js @@ -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; } @@ -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; diff --git a/build/bs.config.js b/build/bs.config.js index bc7c494..1d04485 100644 --- a/build/bs.config.js +++ b/build/bs.config.js @@ -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]); } }); @@ -26,7 +26,7 @@ module.exports = (config) => { return { init: true, files: [ - "app/view/**/*", + 'app/view/**/*', // "app/public/**/*" ], logConnections: false, @@ -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 @@ -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, + }), + ], }; -}; \ No newline at end of file +}; diff --git a/build/util.js b/build/util.js index d196288..6151ee6 100644 --- a/build/util.js +++ b/build/util.js @@ -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(), }; diff --git a/build/webpack.base.config.js b/build/webpack.base.config.js index 6789d4d..c8c0ca7 100644 --- a/build/webpack.base.config.js +++ b/build/webpack.base.config.js @@ -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', + }, -}; \ No newline at end of file +}; diff --git a/build/webpack.dev.config.js b/build/webpack.dev.config.js index 70d8e8f..b6617d0 100644 --- a/build/webpack.dev.config.js +++ b/build/webpack.dev.config.js @@ -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', ], }, ], @@ -43,4 +43,4 @@ const devConfig = { ], }; -module.exports = merge(baseConfig,devConfig); +module.exports = merge(baseConfig, devConfig); diff --git a/build/webpack.prod.config.js b/build/webpack.prod.config.js index 0a9fe04..813d7d0 100644 --- a/build/webpack.prod.config.js +++ b/build/webpack.prod.config.js @@ -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'); @@ -11,39 +11,39 @@ 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({ @@ -51,7 +51,7 @@ const prodConfig = { NODE_ENV: '"production"', }, }), - extractLESS,//设置其路径(路径相对于path) + extractLESS, // 设置其路径(路径相对于path) extractCSS, new WebpackAssetsManifest({ output: 'manifest.json', @@ -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: { @@ -76,4 +76,4 @@ const prodConfig = { ], }; -module.exports = merge(baseConfig,prodConfig); +module.exports = merge(baseConfig, prodConfig); diff --git a/config/config.default.js b/config/config.default.js index bf565f4..bdccaf8 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -12,7 +12,7 @@ module.exports = appInfo => { }; - config.apiHost ='https://remotex.ooclab.org'; + config.apiHost = 'https://remotex.ooclab.org'; return config; }; diff --git a/config/config.local.js b/config/config.local.js index 367d795..e1b3185 100644 --- a/config/config.local.js +++ b/config/config.local.js @@ -1,5 +1,5 @@ const path = require('path'); -const {ip} = require('../build/util'); +const { ip } = require('../build/util'); module.exports = appInfo => { const config = {}; @@ -7,10 +7,10 @@ module.exports = appInfo => { config.browsersync = { configPath: path.resolve(__dirname, '../build/bs.config'), - options:{ + options: { port: bsPort, - publicPath: `http://${ip}:${bsPort}/` - } + publicPath: `http://${ip}:${bsPort}/`, + }, }; return config; diff --git a/config/config.prod.js b/config/config.prod.js index 21bb598..2991089 100644 --- a/config/config.prod.js +++ b/config/config.prod.js @@ -1,4 +1,4 @@ -const path = require("path"); +const path = require('path'); module.exports = appInfo => { const config = {}; @@ -6,7 +6,7 @@ module.exports = appInfo => { config.static = { maxAge: 31536000, prefix: '/public/', - dir: path.join(appInfo.baseDir, 'dist') + dir: path.join(appInfo.baseDir, 'dist'), }; return config; diff --git a/config/plugin.js b/config/plugin.js index f2d371c..9c6612b 100644 --- a/config/plugin.js +++ b/config/plugin.js @@ -11,4 +11,4 @@ exports.nunjucks = { // exports['webpack-dev-server'] = { // enable: false, // package: 'egg-webpack-dev-server', -// }; \ No newline at end of file +// }; diff --git a/package.json b/package.json index 9461ec3..d18ea86 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "test": "npm run lint -- --fix && npm run test-local", "test-local": "egg-bin test", "cov": "egg-bin cov", - "lint": "eslint .", + "lint": "eslint test app", "ci": "npm run lint && npm run cov", "autod": "autod", "build": "rm -rf dist/** && webpack --config build/webpack.prod.config.js" diff --git a/test/app/controller/home.test.js b/test/app/controller/home.test.js index d66a679..7e0ae1c 100644 --- a/test/app/controller/home.test.js +++ b/test/app/controller/home.test.js @@ -20,7 +20,6 @@ describe('test/app/controller/home.test.js', () => { it('should GET /', () => { return app.httpRequest() .get('/') - .expect('hi, egg') .expect(200); }); }); diff --git a/test/opts.js b/test/opts.js deleted file mode 100644 index 5eb9a70..0000000 --- a/test/opts.js +++ /dev/null @@ -1,63 +0,0 @@ - -// const browserSync = require("browser-sync").create(); -var webpack = require('webpack'); -var webpackDevMiddleware = require('webpack-dev-middleware'); -var webpackHotMiddleware = require('webpack-hot-middleware'); - -var webpackConfig = require('../build/webpack.config'); -webpackConfig.output.publicPath = 'http://localhost:3000/public/' - -console.log(webpackConfig) -// 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://localhost:3000/__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 ]); - } -}); -// console.log(webpackConfig) -var bundler = webpack(webpackConfig); - -const opts = { - init: true, - files: [ - "app/view/**/*", - // "app/public/**/*" - ], - logConnections: false, - - middleware: [ - webpackDevMiddleware(bundler, { - // IMPORTANT: dev middleware can't access config, so we should - // provide publicPath by ourselves - publicPath: webpackConfig.output.publicPath, - - // pretty colored output - 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 - }), - - // bundler should be the same as above - webpackHotMiddleware(bundler,{ - log: false, - path: "/__webpack_hmr", - heartbeat: 2000 - }) - ] -}; -// -// browserSync.init(opts,(err, instance)=>{ -// // console.log(err,instance) -// }); - -module.exports = opts \ No newline at end of file