61 lines
2.1 KiB
JavaScript
61 lines
2.1 KiB
JavaScript
|
|
const ci = require('miniprogram-ci');
|
|||
|
|
const path = require('path');
|
|||
|
|
const fs = require('fs');
|
|||
|
|
|
|||
|
|
// 配置项(必须改!)
|
|||
|
|
const config = {
|
|||
|
|
appid: 'wx9393bde462d9805a', // 替换成你的正式小程序AppID
|
|||
|
|
// 替换成你的密钥文件路径(比如 private.wx9393bde462d9805a.key)
|
|||
|
|
privateKeyPath: path.resolve(__dirname, './private.wx9393bde462d9805a.key'),
|
|||
|
|
projectPath: path.resolve(__dirname, './unpackage/dist/dev/mp-weixin'),
|
|||
|
|
version: '1.0.0',
|
|||
|
|
desc: '自动化上传测试',
|
|||
|
|
// ci-script.js 中的 setting 配置
|
|||
|
|
setting: {
|
|||
|
|
es6: true,
|
|||
|
|
es7: true,
|
|||
|
|
minify: true, // 基础压缩
|
|||
|
|
minifyJS: true, // 压缩JS(移除注释、空格、变量名混淆)
|
|||
|
|
minifyWXSS: true, // 压缩样式(合并重复样式、移除空格)
|
|||
|
|
minifyXML: true, // 压缩配置文件(app.json/page.json)
|
|||
|
|
autoPrefixWXSS: true,
|
|||
|
|
codeProtect: false, // 关闭代码保护(保护会增加体积)
|
|||
|
|
ignoreUnusedFiles: true, // 自动忽略未引用的文件
|
|||
|
|
disableUseStrict: true, // 禁用"use strict"减少JS体积
|
|||
|
|
disableShowSourceMap: true // 关闭sourcemap(调试文件占体积)
|
|||
|
|
},
|
|||
|
|
previewQrOutputPath: path.resolve(__dirname, './preview-qr.png'),
|
|||
|
|
onProgressUpdate: (res) => {
|
|||
|
|
console.log(`进度:${res.progress}%,状态:${res.status}`);
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 上传代码方法
|
|||
|
|
async function uploadCode() {
|
|||
|
|
try {
|
|||
|
|
if (!fs.existsSync(config.privateKeyPath)) {
|
|||
|
|
throw new Error(`密钥文件不存在:${config.privateKeyPath}`);
|
|||
|
|
}
|
|||
|
|
const project = new ci.Project({
|
|||
|
|
appid: config.appid,
|
|||
|
|
type: 'miniProgram',
|
|||
|
|
projectPath: config.projectPath,
|
|||
|
|
privateKeyPath: config.privateKeyPath,
|
|||
|
|
ignores: ['node_modules/**/*'],
|
|||
|
|
});
|
|||
|
|
const uploadResult = await ci.upload({
|
|||
|
|
project,
|
|||
|
|
version: config.version,
|
|||
|
|
desc: config.desc,
|
|||
|
|
setting: config.setting,
|
|||
|
|
onProgressUpdate: config.onProgressUpdate,
|
|||
|
|
});
|
|||
|
|
console.log('✅ 代码上传成功:', uploadResult);
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 上传失败:', error.message);
|
|||
|
|
process.exit(1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 执行上传
|
|||
|
|
uploadCode();
|