Commit 560a68ba authored by 前端-许佳敏's avatar 前端-许佳敏

chore: 优化构建方式, 所有构建环境变量均由env.js控制

parent 0f455ea1
......@@ -2,29 +2,6 @@
const path = require('path')
module.exports = {
all: {
SITE_ID: '1',
BACK_GATEWAY: 'http://lingxi-all.wg.shushangyun.com',
USE_ROUTE_CONFIG: false,
SOCKET_URL: 'ws://lingxi-all.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/all/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
})
},
scm: {
SITE_ID: '1',
BACK_GATEWAY: 'http://lingxi-scm.wg.shushangyun.com',
......@@ -48,29 +25,6 @@ module.exports = {
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
})
},
25: {
SITE_ID: '352',
BACK_GATEWAY: 'http://10.0.0.25:8100',
......@@ -122,6 +76,8 @@ module.exports = {
BACK_GATEWAY: 'http://10.0.0.17:8100',
USE_ROUTE_CONFIG: true,
SOCKET_URL: 'ws://10.0.0.17:8100',
YAPI_URL: 'http://10.0.0.25:4000/',
// 注 交付中心同事可不使用下面的ssh配置
ssh: JSON.stringify({
user: "root",
// Password optional, prompted if none given
......
......@@ -2,14 +2,14 @@
"name": "lingxi-business-paltform",
"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",
"upload:25": "cross-env local=25 taskName=upload yarn scripts:build",
"upload:study": "cross-env local=study taskName=upload yarn scripts:build",
"upload:v2": "cross-env local=v2 taskName=upload yarn scripts:build",
"upload:v2Preview": "cross-env local=v2Preview taskName=upload yarn scripts:build",
"upload:v2scm": "cross-env local=v2scm taskName=upload yarn scripts:build",
"upload:v2Test": "cross-env local=v2Test taskName=upload yarn scripts:build",
"upload:scm": "cross-env PRO_ENV=scm taskName=upload yarn scripts:build",
"upload:10": "cross-env PRO_ENV=10 taskName=upload yarn scripts:build",
"upload:25": "cross-env PRO_ENV=25 taskName=upload yarn scripts:build",
"upload:study": "cross-env PRO_ENV=study taskName=upload yarn scripts:build",
"upload:v2": "cross-env PRO_ENV=v2 taskName=upload yarn scripts:build",
"upload:v2Preview": "cross-env PRO_ENV=v2Preview taskName=upload yarn scripts:build",
"upload:v2scm": "cross-env PRO_ENV=v2scm taskName=upload yarn scripts:build",
"upload:v2Test": "cross-env PRO_ENV=v2Test 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",
......@@ -26,7 +26,7 @@
"build:all": "cross-env SITE_ID=1 BACK_GATEWAY=http://lingxi-all.wg.shushangyun.com USE_ROUTE_CONFIG=false SOCKET_URL=ws://lingxi-all.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:9400 yarn build",
"build:study": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.1.207:8100 USE_ROUTE_CONFIG=false SOCKET_URL=ws://10.0.1.207:9400 yarn build",
"build:v2": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.0.17:8100 USE_ROUTE_CONFIG=false SOCKET_URL=ws://10.0.0.17:9880 yarn build",
"build:v2": "cross-env PRO_ENV=v2 yarn build",
"build:v2Preview": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.1.220:8100 USE_ROUTE_CONFIG=false SOCKET_URL=ws://10.0.1.220:9400 yarn build",
"build:v2scm": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.1.220:8100 USE_ROUTE_CONFIG=false SOCKET_URL=ws://10.0.1.220:9400 yarn build",
"build:v2Test": "cross-env SITE_ID=1 BACK_GATEWAY=http://lx-pre-gateway.shushangyun.com USE_ROUTE_CONFIG=false SOCKET_URL=ws://lx-pre-gateway.shushangyun.com yarn build",
......
......@@ -7,46 +7,9 @@ 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('pull code success!', 'success')
// // installPackage(done)
// connectSSH(done)
// })
// }
// 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
}
Logs.stop('构建终于成功了!', 'success')
connectSSH(done)
})
}
const connectSSH = (done) => {
const sshInfo = JSON.parse(process.env.ssh)
scpRun(sshInfo, process.env.local, done)
scpRun(sshInfo, process.env.PRO_ENV, done)
}
const initUpload = (done) => {
......@@ -56,4 +19,4 @@ const initUpload = (done) => {
module.exports = {
initUpload
}
\ No newline at end of file
}
......@@ -3,6 +3,8 @@ const envValue = require('../env')
const path = require('path')
const fs = require('fs')
const isProduction = process.env.NODE_ENV === 'production'
// @todo
const taskName = process.env.taskName || 'start'
......@@ -32,14 +34,14 @@ function genarateConfig() {
})
}
// 本地构建时带上的环境变量
const local = process.env.local
if (local) {
process.env.SITE_ID = envValue[local].SITE_ID
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
// 构建时带上的环境变量
const PRO_ENV = process.env.PRO_ENV
if (PRO_ENV) {
process.env.SITE_ID = envValue[PRO_ENV].SITE_ID
process.env.BACK_GATEWAY = envValue[PRO_ENV].BACK_GATEWAY
process.env.USE_ROUTE_CONFIG = envValue[PRO_ENV].USE_ROUTE_CONFIG
process.env.SOCKET_URL = envValue[PRO_ENV].SOCKET_URL
process.env.ssh = envValue[PRO_ENV].ssh
}
function runTask(toRun) {
......
const YAPI_URL = require('./env.js')[process.env.PRO_ENV]
if (!YAPI_URL) {
throw 'yapi链接不存在'
}
const tokenList = [
{ name: 'LogisticsV2', token: '732fb8e33970ff5dee830423a630e8e85c3ef3293abba7581b16749dfce8608b', categoryIds: [0], }, // 物流服务
{ name: 'ProductV2', token: 'df37f2a0e3829c4288708ae211920bdbdee55e5e2f48b1e8cf7d1925ac618d9a', categoryIds: [0], }, // 商品服务V2
......@@ -20,7 +25,7 @@ const tokenList = [
]
const getConfigMap = (tokens) => tokens.map(v => ({
serverUrl: 'http://10.0.0.25:4000/',
serverUrl: YAPI_URL,
typesOnly: false,
reactHooks: {
enabled: false,
......
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