# bash deploy.sh dev 使用命名
node ./merge/$1.js # 即 node ./merge/dev.js
echo "merge complete"
npm run build
echo "build complete"
pm2 start npm -- run start
echo "pm2 complete"
pm2 save
echo "save complete"
pm2 startup
pm2 save
echo "running complete"
# if [ $1 = "dev"]; then
# echo '$111' $1
# Run $1
# fi #ifend
const fs = require('fs')
const path = require('path')
const _assign = require('lodash/assign')
/**
* merge file
* @param filepath json配置文件路径名
* @param options json需要修改的字段
* @returns {undefined}
*/
function mergeJSON(filepath, options) {
filepath = path.join(__dirname, filepath)
let config = require(filepath)
config = _assign({}, config, options)
fs.writeFileSync(filepath, JSON.stringify(config, null, 2))
}
module.exports = mergeJSON
// dev.js
const mergeJSON = require('./merge')
const merchantConfig = {
HOST_API: '',
SHOP_API: '',
WS_API: '',
DB_HOST: '',
DB_USER: '',
DB_PASS: ''
}
mergeJSON('./default.json', merchantConfig)
{
"HOST_API": "",
"SHOP_API": "",
"WS_API": "",
"DB_HOST": "",
"DB_USER": "",
"DB_PASS": ""
}