MMDeJeVS3GtMVLeu
2023-07-04 14:40:12 +08:00
react 就 taro ,另外小程序支持 ci
// 自动将代码上传到小程序
const ci = require('miniprogram-ci')
const path = require('path')
const mainfest = require('../src/manifest.json')
const slog = require('single-line-log').stdout
const robot = Number(process.env.ROBOT) || 1
const buildVersion = process.env.npm_config_build_version || mainfest.versionName
function getUploadDesc() {
// dev
if (robot === 1) {
return 'build by robot --dev'
}
// test
if (robot === 2) {
return 'build by robot --test'
}
// release
if (robot === 3) {
return 'build by robot --release'
}
// uat
if (robot === 4) {
return 'build by robot --uat'
}
return mainfest.description
}
async function main() {
const project = new ci.Project({
appid: mainfest['mp-weixin'].appid, //appid
type: 'miniProgram',
projectPath: path.resolve(__dirname, '../dist/build/mp-weixin'), //项目路径
privateKeyPath: path.resolve(__dirname, `./private.${mainfest['mp-weixin'].appid}.key`), //小程序后台的上传密匙
ignores: ['node_modules/**/*']
})
let slogIndex = 0
try {
await ci.upload({
project,
version: buildVersion,
desc: getUploadDesc(),
setting: mainfest['mp-weixin'].setting,
robot,
onProgressUpdate: () => {
slog('上传中' + (slogIndex === 0 ? '.' : slogIndex === 1 ? '..' : '...') + '\n')
slogIndex++
if (slogIndex === 3) {
slogIndex = 0
}
}
})
console.log(`上传成功 版本${buildVersion}`)
} catch (error) {
console.error(`上传失败 版本${buildVersion}`, error)
}
}
main()