From e99accc36b72c8198ee1f5bc801676017b89642e Mon Sep 17 00:00:00 2001 From: ch Date: Sat, 7 May 2022 10:54:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env.config.js | 27 +++++++++++---------------- package.json | 6 +++++- plugins/api/account.js | 6 ++++-- plugins/api/base.js | 6 ++++-- plugins/api/cart.js | 6 ++++-- plugins/api/goods.js | 6 ++++-- plugins/api/order.js | 6 ++++-- plugins/api/oss.js | 9 +++++++-- plugins/api/seckill.js | 5 +++-- 9 files changed, 46 insertions(+), 31 deletions(-) diff --git a/env.config.js b/env.config.js index 974ce59..22057c1 100644 --- a/env.config.js +++ b/env.config.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-05-05 14:40:00 * @LastEditors: ch - * @LastEditTime: 2022-05-07 10:09:54 + * @LastEditTime: 2022-05-07 10:51:53 * @Description: 根据git分支生成对应环境的环境变量 * 开发时如果环境变量换了,可以不用重启服务,直接运行node env.config.js即可 */ @@ -25,21 +25,16 @@ const envConfig = { } } const branch = getRepoInfo().branch; // 调用获取git信息 -let curEnvConfig = {}; -switch (branch){ - case 'msb_test': - curEnvConfig = envConfig.test; - break; - case 'msb_beta': - curEnvConfig = envConfig.beta; - break; - case 'msb_prod': - curEnvConfig = envConfig.prod; - break; - default: - curEnvConfig = envConfig.dev; - break; - +let curEnvConfig = null; +const argv = global.process.argv; +for(key in envConfig){ + if(argv.includes(`--ENV:${key}`)){ + curEnvConfig = envConfig[key]; + break; + } +} +if(!curEnvConfig){ + curEnvConfig = envConfig.dev; } fs.writeFileSync(`${path.resolve(__dirname, './plugins/config')}/env.js`, `const ENV = ${JSON.stringify(curEnvConfig)}; export default ENV;`); diff --git a/package.json b/package.json index 8f44512..675d315 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,11 @@ "private": true, "scripts": { "dev": "node env.config.js & nuxt", - "build": "node env.config.js & nuxt build", + "dev:beta": "node env.config.js --ENV:beta & nuxt", + "dev:prod": "node env.config.js --ENV:prod & nuxt", + "build:test": "node env.config.js --ENV:test & nuxt build", + "build:beta": "node env.config.js --ENV:beta & nuxt build", + "build:prod": "node env.config.js --ENV:prod & nuxt build", "start": "nuxt start", "generate": "nuxt generate", "test": "jest" diff --git a/plugins/api/account.js b/plugins/api/account.js index 47cbd85..fbdf0e9 100644 --- a/plugins/api/account.js +++ b/plugins/api/account.js @@ -2,14 +2,16 @@ * @Author: ch * @Date: 2022-05-04 18:24:03 * @LastEditors: ch - * @LastEditTime: 2022-05-04 22:43:19 + * @LastEditTime: 2022-05-07 10:27:01 * @Description: file content */ import {axiosTk} from "../axiosTk"; import {axios} from "../axios"; import { ToAsyncAwait } from "../utils"; +import ENV from '../config/env'; + +const BASE_URL = `${ENV.base_url}/uc`; -const BASE_URL = '/uc'; /** * 获取当前登录用户信息 */ diff --git a/plugins/api/base.js b/plugins/api/base.js index 651e7d4..30a1da0 100644 --- a/plugins/api/base.js +++ b/plugins/api/base.js @@ -2,14 +2,16 @@ * @Author: ch * @Date: 2022-05-04 18:24:03 * @LastEditors: ch - * @LastEditTime: 2022-05-04 22:42:08 + * @LastEditTime: 2022-05-07 10:28:22 * @Description: file content */ import {axiosTk} from "../axiosTk"; import { ToAsyncAwait } from "../utils"; +import ENV from '../config/env'; + +const BASE_URL = `${ENV.base_url}/mall/base`; -const BASE_URL = '/mall/base'; /** * 获取收货地址 */ diff --git a/plugins/api/cart.js b/plugins/api/cart.js index 54bd972..c0d894b 100644 --- a/plugins/api/cart.js +++ b/plugins/api/cart.js @@ -2,13 +2,15 @@ * @Author: ch * @Date: 2022-05-04 18:24:03 * @LastEditors: ch - * @LastEditTime: 2022-05-04 22:41:25 + * @LastEditTime: 2022-05-07 10:29:08 * @Description: file content */ import {axiosTk} from "../axiosTk"; import { ToAsyncAwait } from "../utils"; +import ENV from '../config/env'; + +const BASE_URL = `${ENV.base_url}/mall/product`; -const BASE_URL = '/mall/product'; /** * 设置购物车数量 diff --git a/plugins/api/goods.js b/plugins/api/goods.js index 7c1e930..5989bbc 100644 --- a/plugins/api/goods.js +++ b/plugins/api/goods.js @@ -2,13 +2,15 @@ * @Author: ch * @Date: 2022-05-04 18:24:03 * @LastEditors: ch - * @LastEditTime: 2022-05-04 22:40:26 + * @LastEditTime: 2022-05-07 10:29:22 * @Description: file content */ import {axios} from "../axios"; import { ToAsyncAwait } from "../utils"; +import ENV from '../config/env'; + +const BASE_URL = `${ENV.base_url}/mall/product`; -const BASE_URL = '/mall/product'; /** * 获取商品,瀑布流 * @param {*} params diff --git a/plugins/api/order.js b/plugins/api/order.js index aef6bbb..95ae5cb 100644 --- a/plugins/api/order.js +++ b/plugins/api/order.js @@ -4,12 +4,14 @@ * @Author: ch * @Date: 2022-05-04 18:17:25 * @LastEditors: ch - * @LastEditTime: 2022-05-04 22:46:02 + * @LastEditTime: 2022-05-07 10:29:48 * @Description: file content */ import {axiosTk} from "../axiosTk"; +import ENV from '../config/env'; + +const BASE_URL = `${ENV.base_url}/mall/trade`; -const BASE_URL = '/mall/trade'; const APPID = 'wx0643970a8e86d028'; /** diff --git a/plugins/api/oss.js b/plugins/api/oss.js index c75f57b..93b0579 100644 --- a/plugins/api/oss.js +++ b/plugins/api/oss.js @@ -2,14 +2,19 @@ * @Author: ch * @Date: 2022-05-04 18:24:03 * @LastEditors: ch - * @LastEditTime: 2022-05-04 22:40:06 + * @LastEditTime: 2022-05-07 10:30:17 * @Description: file content */ import {axiosTk} from "../axiosTk"; import { ToAsyncAwait } from "../utils"; +import ENV from '../config/env'; -const BASE_URL = '/oss/oss'; +const BASE_URL = `${ENV.base_url}/oss/oss`; +/** + * 获取OOS信息 + * @param {*} data + */ export const ApiPostGetOssConfig = (data) => ToAsyncAwait(axiosTk.post(`${BASE_URL}/generateOssSignature`, data)); diff --git a/plugins/api/seckill.js b/plugins/api/seckill.js index efd77ed..f21783b 100644 --- a/plugins/api/seckill.js +++ b/plugins/api/seckill.js @@ -2,13 +2,14 @@ * @Author: ch * @Date: 2022-05-04 18:24:03 * @LastEditors: ch - * @LastEditTime: 2022-05-04 22:44:12 + * @LastEditTime: 2022-05-07 10:30:28 * @Description: file content */ import {axios} from "../axios"; import { ToAsyncAwait } from "../utils"; +import ENV from '../config/env'; -const BASE_URL = '/mall/marketing'; +const BASE_URL = `${ENV.base_url}/mall/marketing`; export const ApiGetHomeSeckill = () => ToAsyncAwait(axios.get(`${BASE_URL}/app/activity/home`));