Commit 89e89a19 authored by 前端-许佳敏's avatar 前端-许佳敏

chore: 调整构建前脚本,引入国际化

parent d4faf550
......@@ -14,7 +14,7 @@
"start:analyze": "ANALYZE=1 umi dev",
"scripts:build": "node scripts/run",
"scripts:init": "node scripts/init",
"scripts:build-yxc": "node scripts/run http://yxc-web-demo.shushangyun.com/api",
"scripts:build-test": "cross-env PRO_ENV=v2 node scripts/run",
"start": "yarn scripts:init && yarn api && yarn scripts:build && umi dev",
"start:dev": "umi dev",
"build": "yarn api && yarn scripts:build && yarn build:clean",
......
const Axios = require('axios').default;
const deepClone = require('clone')
const { prefixServiceConfig, serviceConfig} = require('./server')
const BACK_GATEWAY = process.env.BACK_GATEWAY
const demoFetch = require('../../demo').fetchConfig
const isDemo = true
const remoteUrl = BACK_GATEWAY || process.argv[2] || 'http://10.0.0.25:8100'
console.log(`\n当前访问的后端url是${remoteUrl}!!!!!!`)
const axios = Axios.create({
baseURL: remoteUrl,
responseType: 'json',
headers: {
"source": "1"
}
})
async function prefixHttp() {
try {
const { data } = await axios(prefixServiceConfig.global)
if (data.code === 1000) {
return data.data
} else {
return {}
}
} catch (error) {
console.log(error)
}
}
// 批量组装接口
async function batchAxiosHttps(requestConfig) {
const asyncHttpQueue = deepClone(serviceConfig)
const httpErrorQueue = []
const serverErrorQueue = []
console.log('\n')
for (const item in serviceConfig) {
if (JSON.stringify(item) !== '{}') {
for (const subItem in serviceConfig[item]) {
try {
axios.interceptors.request.use(config => {
config.headers = Object.assign({}, config.headers, requestConfig.headers)
return config
})
const data = await axios(serviceConfig[item][subItem])
// 当接口出错时 不写入json文件
if (data.data.code === 1000) {
asyncHttpQueue[item][subItem] = data.data.data
} else {
serverErrorQueue.push({ ...asyncHttpQueue[item][subItem], ...data.data })
// 默认置为null
asyncHttpQueue[item][subItem] = null
}
} catch (err) {
console.log(err)
httpErrorQueue.push({ ...serviceConfig[item][subItem], ...err.response.data })
}
}
}
}
if (httpErrorQueue.length > 0) {
console.log('\n网络错误\n')
// 可在此做日志收集
console.log(httpErrorQueue)
}
if (serverErrorQueue.length > 0) {
console.log('\n接口服务错误\n')
// 可在此做日志收集
console.log(serverErrorQueue)
}
if (httpErrorQueue.length > 0 || serverErrorQueue.length > 0) {
// 退出构建
console.log('\n脚本构建失败!!!!!!')
// 终止当前进程
process.exit(1)
}
return isDemo ? Object.assign(asyncHttpQueue, await demoFetch()) : asyncHttpQueue
}
module.exports = {
prefixHttp,
batchAxiosHttps,
}
/*
* @Author: LeeJiancong
* @Date: 2020-08-10 14:41:27
* @Date: 2020-07-17 18:01:43
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-11 10:01:27
* @Copyright: 1549414730@qq.com
* @LastEditTime: 2021-08-07 11:08:07
*/
/**
* 用于在项目开始前获取所有的配置
......@@ -12,16 +13,11 @@
*/
const Axios = require('axios').default;
const deepClone = require('clone')
const demoFetch = require('../../demo').fetchConfig
const { prefixHttp, batchAxiosHttps } = require('./batchAxiosHttps')
const isDemo = true
const SITE_ID = Number(process.env.SITE_ID)
const BACK_GATEWAY = process.env.BACK_GATEWAY
const remoteUrl = BACK_GATEWAY || process.argv[2] || 'http://10.0.0.25:8100'
console.log(`\n当前访问的后端url是${remoteUrl}!!!!!!`)
if (!SITE_ID) {
console.log('\n构建失败!!!!!!')
......@@ -29,92 +25,16 @@ if (!SITE_ID) {
process.exit(1)
}
const axios = Axios.create({
baseURL: remoteUrl,
responseType: 'json',
})
const serviceConfig = {
//初始化会员支付策略配置
// payConfig: {
// payInitializeConfig: {
// url: '/pay/initialize/config',
// method: 'get'
// },
// payPlatformPayConfig: {
// url: '/pay/platform/pay/config',
// method: 'get'
// }
// },
web: {
shopInfo: {
url: '/manage/shop/findShopsBySiteId',
params: {
siteId: SITE_ID,
},
method: 'get'
},
orderMode: {
url: '/system/rule/getOrderMode',
method: 'get'
}
},
global: {
siteInfo: {
url: '/manage/paas/site/details',
params: {
id: SITE_ID
},
method: 'get'
}
}
}
// 批量组装接口
async function batchAxiosHttps() {
const asyncHttpQueue = deepClone(serviceConfig)
const httpErrorQueue = []
const serverErrorQueue = []
console.log('\n')
for (const item in serviceConfig) {
if (JSON.stringify(item) !== '{}') {
for (const subItem in serviceConfig[item]) {
try {
const data = await axios(serviceConfig[item][subItem])
// 当接口出错时 不写入json文件
if (data.data.code === 1000) {
asyncHttpQueue[item][subItem] = data.data.data
} else {
serverErrorQueue.push({ ...asyncHttpQueue[item][subItem], ...data.data })
// 默认置为null
asyncHttpQueue[item][subItem] = null
}
} catch (err) {
httpErrorQueue.push({ ...serviceConfig[item][subItem], ...err.response.data })
}
}
async function pullConfigHttp() {
const data = await prefixHttp()
const { language = 'zh' } = data
console.log(`当前站点语言为${language}`)
const result = await batchAxiosHttps({
headers: {
'Accept-Language': language
}
}
if (httpErrorQueue.length > 0) {
console.log('\n网络错误\n')
// 可在此做日志收集
console.log(httpErrorQueue)
}
if (serverErrorQueue.length > 0) {
console.log('接口服务错误\n')
// 可在此做日志收集
console.log(serverErrorQueue)
}
if (httpErrorQueue.length > 0 || serverErrorQueue.length > 0) {
// 退出构建
console.log('\n脚本构建失败!!!!!!')
// 终止当前进程
process.exit(1)
}
return isDemo ? Object.assign(asyncHttpQueue, await demoFetch()) : asyncHttpQueue
})
return result
}
exports.fetchConfig = batchAxiosHttps
exports.fetchConfig = pullConfigHttp
const SITE_ID = Number(process.env.SITE_ID)
/**
* 前置接口 用于后续配置接口的信息获取
*/
const prefixServiceConfig = {
global: {
url: '/manage/paas/site/details',
params: {
id: SITE_ID
},
method: 'get'
}
}
const serviceConfig = {
web: {
shopInfo: {
url: '/manage/shop/findShopsBySiteId',
params: {
siteId: SITE_ID,
},
method: 'get'
},
orderMode: {
url: '/system/rule/getOrderMode',
method: 'get'
}
},
global: {
siteInfo: {
url: '/manage/paas/site/details',
params: {
id: SITE_ID
},
method: 'get'
}
}
}
module.exports = {
serviceConfig,
prefixServiceConfig
}
......@@ -33,6 +33,7 @@ export interface SiteInfo {
logo: string;
siteUrl: string;
symbol?: any;
language: string;
}
export interface Global {
......
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