pushy发布热更新需要执行一系列的命令例如:
可以通过node的child_process
中的execSync
,可以针对测试环境,输入一下命令,即可实现一键发布
yarn build:dev
相关测试热更新脚本
const execSync = require('child_process').execSync;
const moment = require('moment')
const devSelectAppId = ... // 相关id
const devPackageId = ... // 相关id
async function selectApp() {
try {
console.log('测试环境开始构建:')
await execSync(`pushy selectApp --platform android --no-interactive ${devSelectAppId}`, { stdio: 'ignore' });
} catch (error) {
console.log('测试环境构建失败:', error)
}
}
async function bundle() {
try {
console.log('开始编译热更新包...')
const bundleInfo = await execSync(`pushy bundle --platform android --no-interactive`).toString();
const ppkPath = bundleInfo.split(':').pop().trim()
return ppkPath
} catch (error) {
console.log('测试环境构建失败:', error)
}
}
async function publish(ppkPath) {
const timeTag = `d${moment().format('YYYY/MM/DD/HH:mm')}`;
try {
const publishInfo = await execSync(`pushy publish ${ppkPath} --no-interactive --platform android --name "${timeTag}" --description "fix bugs auto" --metaInfo 'dev'`).toString();
const regNumber = /[0-9]*/g
// '已成功上传新热更包(id: 129958)\n'
// 截取 versionId
const versionId = publishInfo.match(regNumber).join('')
return versionId
} catch (error) {
console.log('发布构建失败:', error)
}
}
async function update(versionId) {
try {
return await execSync(`pushy update --platform android --versionId ${versionId} --packageId ${devPackageId}
`).toString();
} catch (error) {
console.log('发布构建失败:', error)
}
}
async function run () {
try {
await selectApp()
const ppkPath = await bundle()
const versionId = await publish(ppkPath)
await update(versionId)
console.log('发布成功!!!')
} catch (error) {
console.log('执行测试环境构建热更新失败:', error)
}
}
run()
后期可以扩展至生产环境,根据命令行输入的环境变量去区分即可