From 4ff9d5fcec3ab649b163037ac236671760d05f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=BE=E5=B3=B0=E7=9A=84=E5=A4=8F=E5=A4=A9?= Date: Fri, 12 Aug 2022 17:50:36 +0800 Subject: [PATCH] feat: upgrade view config (#83) --- README.md | 2 +- cli/bin/reliable-cli-make.js | 67 ------------ config/config.default.js | 7 ++ config/plugin.js | 4 + database/config.js | 2 +- package.json | 3 - view/.gitignore | 1 + view/index.html | 4 +- view/package.json | 33 +++--- view/postcss.config.js | 1 - view/src/components/BuildsTable.js | 1 - view/src/components/Icon.js | 2 +- view/src/components/SiteSetting.js | 6 +- view/src/page/Setting.js | 4 - view/webpack.config.js | 169 +++++++++++++---------------- 15 files changed, 108 insertions(+), 198 deletions(-) delete mode 100755 cli/bin/reliable-cli-make.js diff --git a/README.md b/README.md index e966688..9027c92 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ | :---: | :---: | :---: | :---: | :---: | -This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Nov 01 2021 21:58:05 GMT+0800`. +This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Fri Aug 12 2022 11:07:28 GMT+0800`. diff --git a/cli/bin/reliable-cli-make.js b/cli/bin/reliable-cli-make.js deleted file mode 100755 index 978a801..0000000 --- a/cli/bin/reliable-cli-make.js +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env node - -'use strict'; - -const _ = require('../lib/helper'); -const childProcess = require('child_process'); - -const platformType = _.getPlatformType(); - -let cmd = ''; -const args = []; - -if (platformType === 'ios') { - console.log('executing make process for ios'); - console.log(process.argv); - - // args should be; [0]node, [1]js-file, [2]make-action....[3]configuration args - if (process.argv.length < 3) { - console.error('invalid arguments'); - process.exit(0); - } - - // check make action: 'build', 'release', 'test', 'pack' etc - if (process.argv[2].indexOf('=') > 0) { - console.error('invalid action'); - console.log(process.argv[2]); - process.exit(0); - } - - cmd = process.argv[2]; - args.push(cmd); - - // formalize extra args - if (process.argv.length > 3) { - args.push(`ARGS="--${process.argv.slice(3).join(' --')}"`); - } - - console.log(`make ${args}`); -} else if (platformType === 'android') { - -} else { - -} - -// execute cmd -const buildProcess = childProcess.spawn('make', args, { - stdio: [ - process.stdin, - process.stdout, - 2, - 'ipc', - ], -}); - -buildProcess.on('close', code => { - process.exit('process exited with code ' + code); -}); - -buildProcess.on('exit', code => { - process.exit(code); -}); - -buildProcess.on('message', e => { - if (e.signal === 'kill') { - buildProcess.kill(); - } -}); diff --git a/config/config.default.js b/config/config.default.js index dcfeda1..62b3ead 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -1,5 +1,6 @@ 'use strict'; +const path = require('path'); const dbConfig = require('../database/config'); module.exports = appInfo => { @@ -94,5 +95,11 @@ module.exports = appInfo => { config.sequelize = dbConfig.development; + const distDirName = 'dist'; + config.static = { + prefix: `/${distDirName}/`, + dir: path.resolve(__dirname, '..', 'view', distDirName), + }; + return config; }; diff --git a/config/plugin.js b/config/plugin.js index a1d3f9a..ce6a433 100644 --- a/config/plugin.js +++ b/config/plugin.js @@ -9,3 +9,7 @@ exports.validate = { enable: true, package: 'egg-validate', }; + +exports.static = { + enable: true, +}; diff --git a/database/config.js b/database/config.js index 2259bc4..9e9b9dd 100644 --- a/database/config.js +++ b/database/config.js @@ -2,7 +2,7 @@ const defaultConfig = { username: 'root', - password: 'reliable', + password: '', database: 'reliable_development', host: process.env.MYSQL_HOST || '127.0.0.1', port: process.env.MYSQL_PORT || '3306', diff --git a/package.json b/package.json index 484cb16..5ef1241 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,6 @@ "uuid": "^3.3.2", "vuepress": "^1.8.2" }, - "engines": { - "node": ">=8.9.0" - }, "scripts": { "start": "NODE_ENV=production npm run db:migrate && eggctl start --port=9900 --title=egg-server-reliable-web", "stop": "eggctl stop --title=egg-server-reliable-web", diff --git a/view/.gitignore b/view/.gitignore index c6218cd..9482f1f 100644 --- a/view/.gitignore +++ b/view/.gitignore @@ -2,3 +2,4 @@ screenshots reports logs coverage +dist diff --git a/view/index.html b/view/index.html index b41967c..8df44e0 100644 --- a/view/index.html +++ b/view/index.html @@ -22,11 +22,11 @@ var assetsUrl = window.pageConfig.assetsUrl || '//' + location.hostname + ':' + location.port; var script = document.createElement('script'); script.type = 'text/javascript'; - script.src = assetsUrl + '/public/reliable-view.js'; + script.src = assetsUrl + '/dist/reliable-view.js'; var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; - link.href = assetsUrl + '/public/reliable-view.css'; + link.href = assetsUrl + '/dist/reliable-view.css'; var head = document.getElementsByTagName('head')[0]; head.appendChild(link); head.appendChild(script); diff --git a/view/package.json b/view/package.json index 11170d0..354e7f5 100644 --- a/view/package.json +++ b/view/package.json @@ -11,20 +11,14 @@ "document": "https://macacajs.github.io/reliable" }, "scripts": { - "dev": "NODE_ENV=development webpack-dev-server --mode development", - "dev:test": "NODE_ENV=test webpack-dev-server --mode development", + "dev": "cross-env NODE_ENV=development webpack serve", + "dev:test": "NODE_ENV=test npm run dev", "serve": "npm run dev:test &", "test": "macaca run -d ./test", "lint": "eslint --fix . --ext jsx,js && stylelint --fix assets/**/*.less -s less", - "build": "NODE_ENV=production webpack -p --mode production", - "build:local": "DIST_DIR=./public npm run build", - "build:report": "npm run build --report", - "prepublishOnly": "npm run build:local", - "ci": "npm run lint && npm run build && npm run serve && npm test" + "build": "cross-env NODE_ENV=production webpack", + "prepublishOnly": "npm run build" }, - "precommit": [ - "lint" - ], "devDependencies": { "@ant-design/icons": "^4.7.0", "@babel/core": "^7.0.0", @@ -42,11 +36,14 @@ "babel-loader": "^8.0.0", "babel-plugin-import": "^1.2.1", "babel-plugin-istanbul": "^5.0.1", + "cross-env": "^7.0.3", "css-loader": "^0.28.11", + "dayjs": "^1.7.7", "eslint": "^4.5.0", "eslint-config-antife": "^1.0.2", "eslint-plugin-mocha": "^5.0.0", "eslint-plugin-react": "^7.2.1", + "husky": "^1.3.1", "less": "^2.7.2", "less-loader": "^4.1.0", "lodash.get": "^4.4.2", @@ -54,9 +51,8 @@ "macaca-cli": "2", "macaca-electron": "18", "macaca-wd": "3", - "mini-css-extract-plugin": "^0.4.0", + "mini-css-extract-plugin": "^2.5.3", "postcss-loader": "^2.1.6", - "pre-commit": "^1.2.2", "qrcode-react": "^0.1.16", "query-string": "^6.2.0", "react": "^16.6.0", @@ -74,14 +70,15 @@ "svgo-loader": "^3.0.0", "url-loader": "^1.1.2", "url-parse": "^1.4.3", - "webpack": "^4.10.0", - "webpack-bundle-analyzer": "^3.3.2", - "webpack-cli": "^3.0.1", - "webpack-dev-server": "^3.1.4", + "webpack": "^5.69.1", + "webpack-cli": "^4.9.0", + "webpack-dev-server": "^4.7.4", "whatwg-fetch": "^2.0.3", "xutil": "1" }, - "dependencies": { - "dayjs": "^1.7.7" + "husky": { + "hooks": { + "pre-commit": "npm run lint" + } } } diff --git a/view/postcss.config.js b/view/postcss.config.js index ccd5722..9819043 100644 --- a/view/postcss.config.js +++ b/view/postcss.config.js @@ -5,4 +5,3 @@ module.exports = { require('autoprefixer'), ], }; - diff --git a/view/src/components/BuildsTable.js b/view/src/components/BuildsTable.js index 08d64b0..4622f65 100644 --- a/view/src/components/BuildsTable.js +++ b/view/src/components/BuildsTable.js @@ -3,7 +3,6 @@ import React from 'react'; import dayjs from 'dayjs'; import { Link } from 'react-router-dom'; -import Clipboard from 'awesome-clipboard'; import { Table, } from 'antd'; diff --git a/view/src/components/Icon.js b/view/src/components/Icon.js index b3bfe51..c09e7e4 100644 --- a/view/src/components/Icon.js +++ b/view/src/components/Icon.js @@ -1,7 +1,7 @@ import React from 'react'; import classnames from 'classnames'; -function Icon(props) { +function Icon (props) { const { className, type, width, height, fill, radius, style = {} } = props; return ( { - const [form] = Form.useForm(); + const [form] = Form.useForm(); const [loading, setLoading] = useState(false); const fetchSite = async () => { @@ -38,7 +38,7 @@ const SiteSetting = () => { const assetsUrl = safeGet(res, 'data.site.assetsUrl'); form.setFieldsValue({ - assetsUrl + assetsUrl, }); }; @@ -91,7 +91,7 @@ const SiteSetting = () => { ); -} +}; export default SiteSetting; diff --git a/view/src/page/Setting.js b/view/src/page/Setting.js index 4c5c917..66cc703 100644 --- a/view/src/page/Setting.js +++ b/view/src/page/Setting.js @@ -4,8 +4,6 @@ import React from 'react'; import { Link } from 'react-router-dom'; import { FormattedMessage } from 'react-intl'; import { - Row, - Col, Card, Breadcrumb, } from 'antd'; @@ -14,8 +12,6 @@ import ReliableLayout from '../components/ReliableLayout'; import SiteSetting from '../components/SiteSetting'; import DingdingSetting from '../components/DingdingSetting'; -import pkg from '../../package.json'; - import './Setting.less'; export default class Setting extends React.Component { diff --git a/view/webpack.config.js b/view/webpack.config.js index bf2e51a..761ef5c 100644 --- a/view/webpack.config.js +++ b/view/webpack.config.js @@ -3,111 +3,88 @@ const path = require('path'); const webpack = require('webpack'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const traceFragment = require('macaca-ecosystem/lib/trace-fragment'); const pkg = require('./package'); +const distDirName = 'dist'; -const { - DIST_DIR, -} = process.env; +module.exports = { + entry: { + [pkg.name]: path.resolve('src'), + }, -module.exports = (env, argv) => { - const isProduction = argv.mode === 'production'; + output: { + path: path.resolve(__dirname, distDirName), + publicPath: `/${distDirName}`, + filename: '[name].js', + }, - const webpackConfig = { - stats: { - publicPath: true, - chunks: false, - modules: false, - children: false, - entrypoints: false, - chunkModules: false, - }, - - devtool: isProduction ? false : 'source-map', - - entry: { - [pkg.name]: path.resolve('src'), - }, - - output: { - path: DIST_DIR - ? path.resolve(DIST_DIR) - : path.join(__dirname, '..', 'app', 'public'), - publicPath: 'public', - filename: '[name].js', - }, - - resolve: { - extensions: [ - '.js', - '.jsx', - ], - }, + resolve: { + extensions: [ + '.js', + '.jsx', + ], + }, - module: { - rules: [ - { - test: /\.js[x]?$/, - exclude: /node_modules/, - use: 'babel-loader', - }, { - test: /\.less$/, - use: [ - MiniCssExtractPlugin.loader, - { - loader: 'css-loader', - }, - { - loader: 'postcss-loader', - }, - { - loader: 'less-loader', - }, - ], - }, { - test: /\.css$/, - use: [ - MiniCssExtractPlugin.loader, - 'css-loader', - ], - }, { - test: /\.svg$/, - use: [ - { - loader: 'svg-sprite-loader', - options: { - symbolId: '[name]', - }, + module: { + rules: [ + { + test: /\.js[x]?$/, + exclude: /node_modules/, + use: 'babel-loader', + }, { + test: /\.less$/, + use: [ + MiniCssExtractPlugin.loader, + { + loader: 'css-loader', + }, + { + loader: 'postcss-loader', + }, + { + loader: 'less-loader', + }, + ], + }, { + test: /\.css$/, + use: [ + MiniCssExtractPlugin.loader, + 'css-loader', + ], + }, { + test: /\.svg$/, + use: [ + { + loader: 'svg-sprite-loader', + options: { + symbolId: '[name]', }, - { - loader: 'svgo-loader', - }, - ], - include: [path.resolve(__dirname, 'src', 'assets')], - }, - ], - }, - plugins: [ - new MiniCssExtractPlugin({ - filename: '[name].css', - chunkFilename: '[id].css', - }), - new webpack.DefinePlugin({ - 'process.env.VERSION': JSON.stringify(pkg.version), - 'process.env.traceFragment': traceFragment, - }), + }, + { + loader: 'svgo-loader', + }, + ], + include: [path.resolve(__dirname, 'src', 'assets')], + }, ], - }; + }, - if (!isProduction) { - webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin()); - } + plugins: [ + new MiniCssExtractPlugin({ + filename: '[name].css', + chunkFilename: '[id].css', + }), + new webpack.DefinePlugin({ + 'process.env.VERSION': JSON.stringify(pkg.version), + 'process.env.traceFragment': traceFragment, + }), + ], - if (process.env.npm_config_report) { - webpackConfig.plugins.push(new BundleAnalyzerPlugin()); - } - - return webpackConfig; + devServer: { + hot: true, + static: { + directory: __dirname, + }, + }, };