@tarojs/plugin-mini-ci
Version:
Taro 小程序端构建后支持CI(持续集成)的插件
108 lines • 4.59 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-console */
const node_path_1 = require("node:path");
const BaseCi_1 = require("./BaseCi");
const npm_1 = require("./utils/npm");
const qrcode_1 = require("./utils/qrcode");
class JdCI extends BaseCi_1.default {
init() {
if (this.pluginOpts.jd == null) {
throw new Error('请为"@tarojs/plugin-mini-ci"插件配置 "jd" 选项');
}
try {
this.jdCi = (0, npm_1.getNpmPkgSync)('jd-miniprogram-ci', process.cwd());
}
catch (error) {
throw new Error('请安装依赖:jd-miniprogram-ci');
}
}
async open() {
const { printLog, processTypeEnum } = this.ctx.helper;
printLog("warning" /* processTypeEnum.WARNING */, '京东小程序不支持 "--open" 参数打开开发者工具');
}
async preview() {
const { privateKey, ignores } = this.pluginOpts.jd;
const { chalk, printLog, processTypeEnum } = this.ctx.helper;
const previewQrcodePath = (0, node_path_1.join)(this.projectPath, 'preview.jpg');
try {
printLog("remind" /* processTypeEnum.REMIND */, `本次上传版本号为:"${this.version}",上传描述为:“${this.desc}”`);
// 返回 图片 base64转换效果
const result = await this.jdCi.preview({
desc: this.desc,
privateKey,
projectPath: this.projectPath,
uv: this.version,
qrcodeFormat: 'image',
ignores,
});
const qrcodeContent = await (0, qrcode_1.readQrcodeImageContent)(result.imgUrl);
await (0, qrcode_1.generateQrcodeImageFile)(previewQrcodePath, qrcodeContent);
await (0, qrcode_1.printQrcode2Terminal)(qrcodeContent);
printLog("remind" /* processTypeEnum.REMIND */, `预览二维码已生成,存储在:"${previewQrcodePath}",二维码内容是:"${qrcodeContent}"`);
this.triggerPreviewHooks({
success: true,
data: {
platform: 'jd',
qrCodeContent: qrcodeContent,
qrCodeLocalPath: previewQrcodePath
},
});
}
catch (error) {
console.log(chalk.red(`预览失败 ${new Date().toLocaleString()} \n${error.message}`));
this.triggerPreviewHooks({
success: false,
data: {
platform: 'jd',
qrCodeContent: '',
qrCodeLocalPath: ''
},
error
});
}
}
async upload() {
const { privateKey, robot, ignores } = this.pluginOpts.jd;
const { chalk, printLog, processTypeEnum } = this.ctx.helper;
const uploadQrcodePath = (0, node_path_1.join)(this.projectPath, 'upload.jpg');
try {
printLog("remind" /* processTypeEnum.REMIND */, `本次上传版本号为:"${this.version}",上传描述为:“${this.desc}”`);
const result = await this.jdCi.upload({
desc: this.desc,
privateKey,
projectPath: this.projectPath,
uv: this.version,
qrcodeFormat: 'image',
robot,
ignores,
});
const qrcodeContent = await (0, qrcode_1.readQrcodeImageContent)(result.imgUrl);
await (0, qrcode_1.generateQrcodeImageFile)(uploadQrcodePath, qrcodeContent);
await (0, qrcode_1.printQrcode2Terminal)(qrcodeContent);
printLog("remind" /* processTypeEnum.REMIND */, `体验版二维码已生成,存储在:"${uploadQrcodePath}",二维码内容是:"${qrcodeContent}"`);
this.triggerUploadHooks({
success: true,
data: {
platform: 'jd',
qrCodeContent: qrcodeContent,
qrCodeLocalPath: uploadQrcodePath
},
});
}
catch (error) {
console.log(chalk.red(`上传失败 ${new Date().toLocaleString()} \n${error.message}`));
this.triggerUploadHooks({
success: false,
data: {
platform: 'jd',
qrCodeContent: '',
qrCodeLocalPath: ''
},
error
});
}
}
}
exports.default = JdCI;
//# sourceMappingURL=JdCI.js.map