Commit 8451a890 authored by 前端-许佳敏's avatar 前端-许佳敏

feat:自动化构建

parent a8192e54
// 这里的env只有对本地起效, 线上构建不用
const path = require('path')
module.exports = {
scm: {
SITE_ID: '1',
BACK_GATEWAY: 'http://lingxi-scm.wg.shushangyun.com',
USE_ROUTE_CONFIG: false,
SOCKET_URL: 'ws://lingxi-scm.wg.shushangyun.com'
SOCKET_URL: 'ws://lingxi-scm.wg.shushangyun.com',
ssh: JSON.stringify({
user: "www",
// Password optional, prompted if none given
password: "!@#project_$%^231(1)wwwuser3",
host: "119.23.219.65",
port: 8122,
localRoot: path.resolve('./dist/'),
remoteRoot: "/usr/local/nginx/html/lingxi/yanshi/api/scm/web/dist/",
// include: ["*", "**/*"], // this would upload everything except dot files
include: ["*"],
// e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
// exclude: ["dist/**/*.map", "node_modules/**", "node_modules/**/.*", ".git/**"],
// delete ALL existing files at destination before uploading, if true
deleteRemote: true,
// Passive mode is forced (EPSV command is not sent)
forcePasv: true
})
},
10: {
SITE_ID: '1',
BACK_GATEWAY: 'http://10.0.0.10:8100',
USE_ROUTE_CONFIG: true,
SOCKET_URL: 'ws://10.0.0.10:8100',
ssh: JSON.stringify({
user: "root",
// Password optional, prompted if none given
password: "123456",
host: "10.0.0.10",
port: 22,
localRoot: path.resolve('./dist/'),
remoteRoot: "/home/www/lingxi/lingxi-business-platform/dist/",
// include: ["*", "**/*"], // this would upload everything except dot files
include: ["*"],
// e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
// exclude: ["dist/**/*.map", "node_modules/**", "node_modules/**/.*", ".git/**"],
// delete ALL existing files at destination before uploading, if true
deleteRemote: true,
// Passive mode is forced (EPSV command is not sent)
forcePasv: true
})
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
"version": "1.0.4",
"scripts": {
"upload:scm": "cross-env local=scm taskName=upload yarn scripts:build",
"upload:10": "cross-env local=10 taskName=upload yarn scripts:build",
"api": "god-ytt",
"scripts:build": "node scripts/run",
"scripts:build-yxc": "node scripts/run http://yxc-web-demo.shushangyun.com/api",
......@@ -15,6 +16,8 @@
"build:analyze": "NODE_OPTIONS=--max_old_space_size=4096 ANALYZE=1 umi build",
"build:dev": "pm2 start scripts/devServer.js",
"build:clean": "NODE_OPTIONS=--max_old_space_size=4096 umi build",
"build:scm": "cross-env SITE_ID=1 BACK_GATEWAY=http://lingxi-scm.wg.shushangyun.com USE_ROUTE_CONFIG=false SOCKET_URL=ws://lingxi-scm.wg.shushangyun.com yarn build",
"build:10": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.0.10:8100 USE_ROUTE_CONFIG=false SOCKET_URL=ws://10.0.0.10:8100 yarn build",
"postinstall": "umi generate tmp",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
"test": "umi-test",
......@@ -78,19 +81,26 @@
},
"devDependencies": {
"@types/qrcode": "^1.3.4",
"async": "^3.2.0",
"axios": "^0.19.2",
"chalk": "^4.1.0",
"clone": "^2.1.2",
"connect-history-api-fallback": "^1.6.0",
"cross-env": "^7.0.2",
"events": "^3.2.0",
"express": "^4.17.1",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"god-upload-scp": "^1.2.0",
"god-yapi2ts": "^1.6.0",
"gulp": "^4.0.2",
"gulp-git": "^2.10.1",
"http-proxy-middleware": "^1.0.5",
"json2ts": "^0.0.7",
"node-cmd": "^4.0.0",
"ora": "^4.0.4"
"ora": "^4.0.4",
"scp2": "^0.1.0-b1",
"ssh2": "^0.8.9",
"util": "^0.12.3"
}
}
......@@ -5,39 +5,55 @@
const git = require('gulp-git')
const Logs = require('./utils/log')
const cmd = require('node-cmd')
const scpRun = require('god-upload-scp')
/**
* 获取远程代码
*/
const pullRemoteCode = (done) => {
git.pull('origin', ['dev', 'test'], function(err) {
if (err) {
throw err
}
Logs.stop()
installPackage(done)
})
}
// const pullRemoteCode = (done) => {
// git.pull('origin', ['dev', 'test'], function(err) {
// if (err) {
// throw err
// }
// Logs.stop('pull code success!', 'success')
// // installPackage(done)
// connectSSH(done)
// })
// }
const installPackage = (done) => {
Log.start('start install package')
cmd.run('yarn', function(err) {
// const installPackage = (done) => {
// Logs.start('start install package')
// cmd.run('yarn', function(err) {
// if (err) {
// throw err
// }
// Logs.stop('install package success!', 'success')
// runBuild(done)
// })
// }
const runBuild = (done) => {
Logs.start('构建开始, 这里时间有点长...')
cmd.run(`yarn build:${process.env.local}`, function(err) {
if (err) {
throw err
}
Log.stop()
runBuild(done)
Logs.stop('构建终于成功了!', 'success')
connectSSH(done)
})
}
const runBuild = (done) => {
done()
const connectSSH = (done) => {
const sshInfo = JSON.parse(process.env.ssh)
scpRun(sshInfo, process.env.local, done)
}
const initUpload = (done) => {
pullRemoteCode(done)
Logs.stop('开始上传到远程服务器!', 'success')
connectSSH(done)
}
module.exports = {
pullRemoteCode,
initUpload
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ const outputDts = path.resolve(__dirname, rootPath, 'src/global/config/global.d.
// Logs.start('gulp start')
gulp.task('start', gulp.series(done => {
// getAsyncConfig(done)
getAsyncConfig(done)
}))
gulp.task('upload', gulp.series(done => {
......
const gulp = require('gulp')
const envValue = require('../env')
// @todo
const taskName = process.env.taskName || 'start'
// 本地构建时带上的环境变量
......@@ -10,6 +11,7 @@ if (local) {
process.env.BACK_GATEWAY = envValue[local].BACK_GATEWAY
process.env.USE_ROUTE_CONFIG = envValue[local].USE_ROUTE_CONFIG
process.env.SOCKET_URL = envValue[local].SOCKET_URL
process.env.ssh = envValue[local].ssh
}
function runTask(toRun) {
......
......@@ -14,6 +14,7 @@ const Logs = {
start(msg) {
spinner.start(msg)
return spinner
},
stop(msg, type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment