From 9e17cbe630fcde3dc1768d62a475da4937756ce7 Mon Sep 17 00:00:00 2001 From: gandchuan <1906357036@qq.com> Date: Mon, 9 Jul 2018 15:08:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20sonar=20=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/Application.js | 2 +- client/reducer/modules/user.js | 1 - .../MockCol/MockCol.js | 4 +- server/controllers/open.js | 18 +- server/utils/commons.js | 52 +++-- ykit.config.js | 182 +++++++++--------- 6 files changed, 126 insertions(+), 133 deletions(-) diff --git a/client/Application.js b/client/Application.js index c7b7c517..2082aab9 100755 --- a/client/Application.js +++ b/client/Application.js @@ -12,7 +12,7 @@ import Loading from './components/Loading/Loading'; import MyPopConfirm from './components/MyPopConfirm/MyPopConfirm'; import { checkLoginState } from './reducer/modules/user'; import { requireAuthentication } from './components/AuthenticatedComponent'; -import Notify from './components/Notify/Notify' +import Notify from './components/Notify/Notify'; const plugin = require('client/plugin.js'); diff --git a/client/reducer/modules/user.js b/client/reducer/modules/user.js index 951fb822..0a410320 100755 --- a/client/reducer/modules/user.js +++ b/client/reducer/modules/user.js @@ -117,7 +117,6 @@ export default (state = initialState, action) => { studyTip: 0 }; } - case SET_IMAGE_URL: { // console.log('state', state); return { diff --git a/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js b/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js index e23bbd97..f4819a7b 100644 --- a/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js +++ b/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js @@ -57,7 +57,6 @@ export default class MockCol extends Component { }); record.res_body = JSON.stringify(result.data); } - // console.log(this.props.currInterface.req_body_is_json_schema) // 参数过滤schema形式 if (this.props.currInterface.req_body_is_json_schema) { let result = await axios.post('/api/interface/schema2json', { @@ -67,8 +66,7 @@ export default class MockCol extends Component { record.req_body_other = JSON.stringify(result.data); } - - this.setState({ + this.setState({ isAdd: isAdd, caseDesModalVisible: true, caseData: record diff --git a/server/controllers/open.js b/server/controllers/open.js index 2e845646..d858d1bf 100644 --- a/server/controllers/open.js +++ b/server/controllers/open.js @@ -130,7 +130,7 @@ class openController extends baseController { let result = []; Object.keys(params).map(item => { if (/env_/gi.test(item)) { - let curEnv = yapi.commons.trim(params[item]) + let curEnv = yapi.commons.trim(params[item]); let value = { curEnv, project_id: item.split('_')[1] }; result.push(value); } @@ -138,12 +138,12 @@ class openController extends baseController { return result; } async runAutoTest(ctx) { - if(!this.$tokenAuth ){ - return ctx.body = yapi.commons.resReturn(null, 40022, 'token 验证失败'); + if (!this.$tokenAuth) { + return (ctx.body = yapi.commons.resReturn(null, 40022, 'token 验证失败')); } // console.log(1231312) const token = ctx.query.token; - + const projectId = ctx.params.project_id; const startTime = new Date().getTime(); const records = (this.records = {}); @@ -151,7 +151,7 @@ class openController extends baseController { const testList = []; let id = ctx.params.id; let curEnvList = this.handleEvnParams(ctx.params); - + let colData = await this.interfaceColModel.get(id); if (!colData) { return (ctx.body = yapi.commons.resReturn(null, 40022, 'id值不存在')); @@ -172,7 +172,6 @@ class openController extends baseController { let curEnvItem = _.find(curEnvList, key => { return key.project_id == item.project_id; }); - item.case_env = curEnvItem ? curEnvItem.curEnv || item.case_env : item.case_env; item.req_headers = this.handleReqHeader(item.req_headers, projectEvn.env, item.case_env); @@ -192,7 +191,7 @@ class openController extends baseController { params: result.params, body: result.res_body }; - testList.push(result); + testList.push(result); } function getMessage(testList) { @@ -317,8 +316,6 @@ class openController extends baseController { return result; } - - async handleScriptTest(interfaceData, response, validRes, requestParams) { if (interfaceData.enable_script !== true) { return null; @@ -345,9 +342,8 @@ class openController extends baseController { } handleReqHeader(req_header, envData, curEnvName) { - let currDomain = handleCurrDomain(envData, curEnvName); - + let header = currDomain.header; header.forEach(item => { if (!checkNameIsExistInArray(item.name, req_header)) { diff --git a/server/utils/commons.js b/server/utils/commons.js index d31153b1..4a8de0d0 100755 --- a/server/utils/commons.js +++ b/server/utils/commons.js @@ -8,7 +8,7 @@ const interfaceColModel = require('../models/interfaceCol.js'); const interfaceCaseModel = require('../models/interfaceCase.js'); const interfaceModel = require('../models/interface.js'); const userModel = require('../models/user.js'); -const followModel = require('../models/follow.js') +const followModel = require('../models/follow.js'); const json5 = require('json5'); const _ = require('underscore'); const Ajv = require('ajv'); @@ -548,38 +548,36 @@ exports.getUserdata = async function getUserdata(uid, role) { }; exports.sendNotice = async function sendNotice(projectId, data) { - const followInst = yapi.getInst(followModel); - const userInst = yapi.getInst(userModel); - const projectInst = yapi.getInst(projectModel); - const list = await followInst.listByProjectId(projectId); - const starUsers = list.map(item => item.uid); + const followInst = yapi.getInst(followModel); + const userInst = yapi.getInst(userModel); + const projectInst = yapi.getInst(projectModel); + const list = await followInst.listByProjectId(projectId); + const starUsers = list.map(item => item.uid); - const projectList = await projectInst.get(projectId); - const projectMenbers = projectList.members.filter(item => item.email_notice).map(item => item.uid); + const projectList = await projectInst.get(projectId); + const projectMenbers = projectList.members + .filter(item => item.email_notice) + .map(item => item.uid); + const users = arrUnique(projectMenbers, starUsers); + const usersInfo = await userInst.findByUids(users); + const emails = usersInfo.map(item => item.email).join(','); - const users = arrUnique(projectMenbers, starUsers); - const usersInfo = await userInst.findByUids(users); - const emails = usersInfo.map(item => item.email).join(','); - - try { - yapi.commons.sendMail({ - to: emails, - contents: data.content, - subject: data.title - }); - } catch (e) { - yapi.commons.log('邮件发送失败:' + e, 'error'); - } -} + try { + yapi.commons.sendMail({ + to: emails, + contents: data.content, + subject: data.title + }); + } catch (e) { + yapi.commons.log('邮件发送失败:' + e, 'error'); + } +}; function arrUnique(arr1, arr2) { - let arr = arr1.concat(arr2); - let res = arr.filter(function (item, index, arr) { + let res = arr.filter(function(item, index, arr) { return arr.indexOf(item) === index; - }) + }); return res; - } - diff --git a/ykit.config.js b/ykit.config.js index bbe59d02..9f67e0b8 100755 --- a/ykit.config.js +++ b/ykit.config.js @@ -1,98 +1,103 @@ var path = require('path'); -var AssetsPlugin = require('assets-webpack-plugin') -var CompressionPlugin = require('compression-webpack-plugin') +var AssetsPlugin = require('assets-webpack-plugin'); +var CompressionPlugin = require('compression-webpack-plugin'); var commonLib = require('./common/plugin.js'); var assetsPluginInstance = new AssetsPlugin({ filename: 'static/prd/assets.js', - processOutput: function (assets) { + processOutput: function(assets) { return 'window.WEBPACK_ASSETS = ' + JSON.stringify(assets); } -}) +}); var fs = require('fs'); -var package = require('./package.json') -var yapi = require('./server/yapi') +var package = require('./package.json'); +var yapi = require('./server/yapi'); var compressPlugin = new CompressionPlugin({ - asset: "[path].gz[query]", - algorithm: "gzip", + asset: '[path].gz[query]', + algorithm: 'gzip', test: /\.(js|css)$/, threshold: 10240, minRatio: 0.8 }); -function createScript(plugin, pathAlias){ - let options = plugin.options ? JSON.stringify(plugin.options) : null - if(pathAlias === 'node_modules'){ - return `"${plugin.name}" : {module: require('yapi-plugin-${plugin.name}/client.js'),options: ${options}}` +function createScript(plugin, pathAlias) { + let options = plugin.options ? JSON.stringify(plugin.options) : null; + if (pathAlias === 'node_modules') { + return `"${plugin.name}" : {module: require('yapi-plugin-${ + plugin.name + }/client.js'),options: ${options}}`; } - return `"${plugin.name}" : {module: require('${pathAlias}/yapi-plugin-${plugin.name}/client.js'),options: ${options}}` + return `"${plugin.name}" : {module: require('${pathAlias}/yapi-plugin-${ + plugin.name + }/client.js'),options: ${options}}`; } -function initPlugins(configPlugin){ +function initPlugins(configPlugin) { configPlugin = require('../config.json').plugins; var systemConfigPlugin = require('./common/config.js').exts; - var scripts = [] ; - if(configPlugin && Array.isArray(configPlugin) && configPlugin.length){ + var scripts = []; + if (configPlugin && Array.isArray(configPlugin) && configPlugin.length) { configPlugin = commonLib.initPlugins(configPlugin, 'plugin'); - configPlugin.forEach((plugin)=>{ - if(plugin.client && plugin.enable){ - scripts.push(createScript(plugin, 'node_modules')) + configPlugin.forEach(plugin => { + if (plugin.client && plugin.enable) { + scripts.push(createScript(plugin, 'node_modules')); } - - }) - + }); } - - systemConfigPlugin = commonLib.initPlugins(systemConfigPlugin, 'ext'); - systemConfigPlugin.forEach(plugin=>{ - if(plugin.client && plugin.enable){ - scripts.push(createScript(plugin, 'exts')) - } - - }) - scripts = "module.exports = {" + scripts.join(",") + "}"; + systemConfigPlugin = commonLib.initPlugins(systemConfigPlugin, 'ext'); + systemConfigPlugin.forEach(plugin => { + if (plugin.client && plugin.enable) { + scripts.push(createScript(plugin, 'exts')); + } + }); + + scripts = 'module.exports = {' + scripts.join(',') + '}'; fs.writeFileSync('client/plugin-module.js', scripts); } initPlugins(); module.exports = { - plugins: [{ - name: 'antd', - options: { - modifyQuery: function (defaultQuery) { // 可查看和编辑 defaultQuery - defaultQuery.plugins = []; - defaultQuery.plugins.push(["transform-runtime", { - "polyfill": false, - "regenerator": true - }]); - defaultQuery.plugins.push('transform-decorators-legacy'); - defaultQuery.plugins.push(["import", { libraryName: "antd"}]) - return defaultQuery; - }, - exclude: /node_modules\/(?!_?(yapi-plugin|json-schema-editor-visual))/ - } - }], - devtool: 'cheap-source-map', - config: function (ykit) { + plugins: [ + { + name: 'antd', + options: { + modifyQuery: function(defaultQuery) { + // 可查看和编辑 defaultQuery + defaultQuery.plugins = []; + defaultQuery.plugins.push([ + 'transform-runtime', + { + polyfill: false, + regenerator: true + } + ]); + defaultQuery.plugins.push('transform-decorators-legacy'); + defaultQuery.plugins.push(['import', { libraryName: 'antd' }]); + return defaultQuery; + }, + exclude: /node_modules\/(?!_?(yapi-plugin|json-schema-editor-visual))/ + } + } + ], + devtool: 'cheap-source-map', + config: function(ykit) { return { - exports: [ - './index.js' - ], + exports: ['./index.js'], commonsChunk: { vendors: { lib: [ // 'anujs', - 'react', + 'react', 'react-dom', 'redux', 'redux-thunk', 'redux-promise', 'react-router', 'react-router-dom', - 'prop-types', + 'prop-types', 'react-dnd-html5-backend', 'react-dnd', 'reactabular-table', @@ -100,15 +105,8 @@ module.exports = { 'table-resolver', 'recharts' ], - lib2: [ - 'brace', - 'mockjs', - 'json5', - 'url', - 'axios', - 'moment' - ], - lib3: [ + lib2: ['brace', 'mockjs', 'json5', 'url', 'axios', 'moment'], + lib3: [ // 'codemirror', // "highlight.js", // "jquery", @@ -123,7 +121,7 @@ module.exports = { ] } }, - modifyWebpackConfig: function (baseConfig) { + modifyWebpackConfig: function(baseConfig) { var ENV_PARAMS = {}; switch (this.env) { case 'local': @@ -138,14 +136,16 @@ module.exports = { default: } - baseConfig.plugins.push(new this.webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify(ENV_PARAMS), - 'process.env.version' : JSON.stringify(package.version), - 'process.env.versionNotify' : yapi.WEBCONFIG.versionNotify - })) + baseConfig.plugins.push( + new this.webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(ENV_PARAMS), + 'process.env.version': JSON.stringify(package.version), + 'process.env.versionNotify': yapi.WEBCONFIG.versionNotify + }) + ); //初始化配置 - baseConfig.devtool = 'cheap-module-eval-source-map' + baseConfig.devtool = 'cheap-module-eval-source-map'; baseConfig.context = path.resolve(__dirname, './client'); baseConfig.resolve.alias.client = '/client'; baseConfig.resolve.alias.common = '/common'; @@ -157,45 +157,47 @@ module.exports = { baseConfig.output.prd.path = 'static/prd'; baseConfig.output.prd.publicPath = ''; - baseConfig.output.prd.filename = '[name]@[chunkhash][ext]' + baseConfig.output.prd.filename = '[name]@[chunkhash][ext]'; - baseConfig.module.noParse = /node_modules\/jsondiffpatch\/public\/build\/.*js/, - baseConfig.module.loaders.push({ - test: /\.less$/, - loader: ykit.ExtractTextPlugin.extract( - require.resolve('style-loader'), - require.resolve('css-loader') - + '?sourceMap!' - + require.resolve('less-loader') + '?sourceMap' - ) - }) + (baseConfig.module.noParse = /node_modules\/jsondiffpatch\/public\/build\/.*js/), + baseConfig.module.loaders.push({ + test: /\.less$/, + loader: ykit.ExtractTextPlugin.extract( + require.resolve('style-loader'), + require.resolve('css-loader') + + '?sourceMap!' + + require.resolve('less-loader') + + '?sourceMap' + ) + }); baseConfig.module.loaders.push({ test: /\.(sass|scss)$/, loader: ykit.ExtractTextPlugin.extract( - require.resolve('css-loader') - + '?sourceMap!' - + require.resolve('sass-loader') + '?sourceMap' + require.resolve('css-loader') + + '?sourceMap!' + + require.resolve('sass-loader') + + '?sourceMap' ) - }) + }); baseConfig.module.preLoaders.push({ test: /\.(js|jsx)$/, exclude: /node_modules|google-diff.js/, - loader: "eslint-loader" + loader: 'eslint-loader' }); baseConfig.module.preLoaders.push({ test: /\.json$/, loader: 'json-loader' - }) + }); if (this.env == 'prd') { - baseConfig.plugins.push(assetsPluginInstance) - baseConfig.plugins.push(compressPlugin) + baseConfig.plugins.push(assetsPluginInstance); + baseConfig.plugins.push(compressPlugin); } return baseConfig; } - } + }; }, server: { // true/false,默认 false,效果相当于 ykit server --hot