// 导入fs模块
const fs = require('fs')
// 导入环境变量配置文件
const ENV_CONFIG = require('./config/env.js');
const manifestPath = ${__dirname}/manifest.json
;
let Manifest = fs.readFileSync(manifestPath, {
encoding: 'utf-8'
})
function replaceManifest(path, value) {
const arr = path.split('.')
const len = arr.length
const lastItem = arr[len - 1]
let i = 0
let ManifestArr = Manifest.split(/\n/)
for (let index = 0; index < ManifestArr.length; index++) {
const item = ManifestArr[index]
if (new RegExp(`"${arr[i]}"`).test(item)) ++i
if (i === len) {
const hasComma = /,/.test(item)
ManifestArr[index] = item.replace(
new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`),
`"${lastItem}": ${value}${hasComma ? ',' : ''}`
)
break
}
}
Manifest = ManifestArr.join('\n')
}
if(process.env.NODE_ENV=='development'){
process.env.UNI_APP_NAME=process.env.UNI_SCRIPT
}
//测试发布功能
// console.log(ENV_CONFIG)
// console.log("-----------------------")
// console.log(process.env)
// console.log("-----------------------")
// console.log(process.env)
// console.log("-----------------------")
// console.log(ENV_CONFIG.profiles)
console.log(process.env)
console.log(process.env.UNI_APP_NAME)
console.log("-----------------------")
// const appid = ENV_CONFIG[process.env.UNI_APP_NAME].appid
//测试测试
// process.env.UNI_APP_NAME='baosimai'
//process.env.UNI_APP_NAM
const appid = ENV_CONFIG[ENV_CONFIG.profiles.active].appid
console.log(appid)
if (appid) {
// #ifdef MP-WEIXIN
replaceManifest('mp-weixin.appid', "${appid}"
)
// #endif
// #ifdef MP-ALIPAY
replaceManifest('mp-alipay.appid', "${appid}"
)
// #endif
}
fs.writeFileSync(manifestPath, Manifest, {
flag: 'w'
})