Skip to content

Commit

Permalink
增加一键安装一键更新脚本、以及修复小bug
Browse files Browse the repository at this point in the history
  • Loading branch information
54sword committed Sep 16, 2018
1 parent 4b37921 commit 748f820
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": ["react", "es2015", "stage-2"],
"presets": ["react", "es2015", "stage-0"],
"env": {
"server": {
"plugins": ["transform-decorators-legacy","syntax-dynamic-import", "dynamic-import-node"]
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ dist
package-lock.json
config/index.js
config/index_*.js
/install-and-startup.sh
/update.sh
8 changes: 4 additions & 4 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { Provider } from 'react-redux'
// import runtime from 'serviceworker-webpack-plugin/lib/runtime'

// import '../src/pages/mobi.min.css'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'jquery'
import 'popper.js'
import 'bootstrap/dist/js/bootstrap.min.js'
// import 'bootstrap/dist/css/bootstrap.min.css'
// import 'jquery'
// import 'popper.js'
// import 'bootstrap/dist/js/bootstrap.min.js'


import configureStore from '../src/store'
Expand Down
4 changes: 2 additions & 2 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ if (process.env.NODE_ENV == 'development') {
config.port = 5000
config.class_scoped_name = '[name]_[local]__[hash:base64:5]'
config.public_path = '//localhost:5000'
config.api_url = 'http://localhost:3000'
// config.api_url = 'http://localhost:3000'
// config.api_url = 'http://admin.xiaoduyu.com'
config.graphql_url = 'http://localhost:3000/graphql'
// config.graphql_url = 'http://localhost:3000/graphql'
}

module.exports = config
36 changes: 36 additions & 0 deletions install-and-startup-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

echo "开始执行安装脚本..."

# 登陆的服务器
SERVER='root@你的服务器ip地址'

# 本地项目需要上传的文件
LOCAL_DIR=`
find $(pwd)/* \( -path $(pwd)/node_modules -prune \) -o \( -path $(pwd)/.git -prune \) -o \( -type d -maxdepth 0 -print \);
find $(pwd)/* -type f -maxdepth 0 -print;
find $(pwd)/.babelrc;
`
# 项目端口号
PM2_NAME="admin.xiaoduyu.com"

# 上传到服务器的目录地址
UPLOAD_TO_SERVER_DIR="/home/app/$PM2_NAME"

# 服务器运行命令
COMMAND="
cd $UPLOAD_TO_SERVER_DIR && npm install && NODE_ENV=production __NODE__=true BABEL_ENV=server pm2 start src/server --name '$PM2_NAME' --max-memory-restart 400M;
"

####################

echo "创建项目文件夹"
ssh ${SERVER} "mkdir $UPLOAD_TO_SERVER_DIR"

echo "脚本开始执行,上传项目文件中..."
scp -r ${LOCAL_DIR} ${SERVER}:${UPLOAD_TO_SERVER_DIR}

echo "安装依赖,并启动项目中..."
ssh ${SERVER} ${COMMAND}

echo "完成"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "NODE_ENV=development __NODE__=false BABEL_ENV=client webpack --progress --colors --config webpack.development.config.js && NODE_ENV=development __NODE__=true BABEL_ENV=server node server",
"pro": "NODE_ENV=production __NODE__=false BABEL_ENV=client webpack --progress --colors --config webpack.production.config.js && NODE_ENV=production __NODE__=true BABEL_ENV=server node server",
"dist": "NODE_ENV=production __NODE__=false BABEL_ENV=client webpack --progress --colors --config webpack.production.config.js",
"server": "NODE_ENV=production __NODE__=true BABEL_ENV=server node server"
"server": "NODE_ENV=production __NODE__=true BABEL_ENV=server node server",
"update-to-server": "NODE_ENV=production __NODE__=false BABEL_ENV=client webpack --progress --colors --config webpack.production.config.js && ./update.sh"
},
"engines": {
"node": ">=8.6.0"
Expand Down
6 changes: 5 additions & 1 deletion src/components/user-notification/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,18 @@ export class NotificationList extends Component {
break

case 'like-reply':

let commentId = notice.comment_id.parent_id ? notice.comment_id.parent_id._id : notice.comment_id._id;

content = (<div>
<div styleName="header">
<Link to={`/people/${notice.sender_id._id}`}>{avatar}{notice.sender_id.nickname}</Link>
{DateDiff(notice.create_at)} 赞了你的
<Link to={`/comment/${notice.comment_id.parent_id._id}`}>{notice.comment_id.content_trim}</Link>
<Link to={`/comment/${commentId}`}>{notice.comment_id.content_trim}</Link>
回复
</div>
</div>)

break

case 'like-comment':
Expand Down
29 changes: 29 additions & 0 deletions update-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

echo "开始执行更新脚本..."

# 登陆的服务器
SERVER='root@你的服务器ip地址'

# 本地项目需要上传的文件
LOCAL_DIR=`
find $(pwd)/* \( -path $(pwd)/node_modules -prune \) -o \( -path $(pwd)/.git -prune \) -o \( -type d -maxdepth 0 -print \);
find $(pwd)/* -type f -maxdepth 0 -print;
find $(pwd)/.babelrc;
`

PM2_NAME="admin.xiaoduyu.com"

# 上传到服务器的目录地址
UPLOAD_TO_SERVER_DIR="/home/app/$PM2_NAME"

# 服务器运行命令
COMMAND="pm2 restart $PM2_NAME"

echo "上传项目文件中..."
scp -r ${LOCAL_DIR} ${SERVER}:${UPLOAD_TO_SERVER_DIR}

echo "重启项目中..."
ssh ${SERVER} ${COMMAND}

echo "完成"
13 changes: 9 additions & 4 deletions webpack.development.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ var config = require('./config')

const extractSass = new ExtractTextPlugin({
filename: "[name].css",
disable: true
disable: true,
allChunks: true,
ignoreOrder: true
})

module.exports = {
Expand All @@ -20,6 +22,7 @@ module.exports = {
app: [
// 让客户端支持 async 和 await
'babel-polyfill',
'bootstrap/dist/css/bootstrap.min.css',
'./client/index',
// 热更新
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true'
Expand All @@ -28,11 +31,13 @@ module.exports = {
'react',
'react-dom',
'react-router',
'babel-polyfill',
'redux',
'react-redux',
'react-document-meta',
'axios'
'axios',
'jquery',
'popper.js',
'bootstrap/dist/js/bootstrap.min.js'
]
},

Expand Down Expand Up @@ -65,7 +70,7 @@ module.exports = {
presets: ['es2015', 'react', 'stage-0']
}
},

{
test: /\.scss$/,
use: extractSass.extract({
Expand Down
2 changes: 2 additions & 0 deletions webpack.production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = {

entry: {
app: [
'babel-polyfill',
'bootstrap/dist/css/bootstrap.min.css',
'./client/index'
],
vendors: [
Expand Down

0 comments on commit 748f820

Please sign in to comment.