UNPKG

@tarojs/plugin-mini-ci

Version:

Taro 小程序端构建后支持CI(持续集成)的插件

146 lines 6.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable no-console */ const path = require("node:path"); const BaseCi_1 = require("./BaseCi"); // import { TTInstance } from './types' const npm_1 = require("./utils/npm"); const qrcode_1 = require("./utils/qrcode"); class TTCI extends BaseCi_1.default { init() { const { chalk, printLog, processTypeEnum } = this.ctx.helper; if (this.pluginOpts.tt == null) { printLog("error" /* processTypeEnum.ERROR */, chalk.red(('请为"@tarojs/plugin-mini-ci"插件配置 "tt" 选项'))); process.exit(1); } try { // 调试使用版本是: tt-ide-cli@0.1.20 this.tt = (0, npm_1.getNpmPkgSync)('tt-ide-cli', process.cwd()); } catch (error) { printLog("error" /* processTypeEnum.ERROR */, chalk.red('请安装依赖:tt-ide-cli')); process.exit(1); } } async _beforeCheck() { await this.tt.loginByEmail({ email: this.pluginOpts.tt.email, password: this.pluginOpts.tt.password, dontSaveCookie: false }); } async open() { const { chalk, printLog, processTypeEnum } = this.ctx.helper; printLog("start" /* processTypeEnum.START */, '启动抖音小程序开发者工具...', this.projectPath); try { await this.tt.open({ project: { path: this.projectPath } }); console.log(chalk.green('打开IDE成功')); } catch (error) { printLog("error" /* processTypeEnum.ERROR */, chalk.red('打开IDE失败', error)); } } async preview() { var _a, _b; await this._beforeCheck(); const { chalk, printLog, processTypeEnum } = this.ctx.helper; try { printLog("start" /* processTypeEnum.START */, '预览抖音小程序'); const previewQrcodePath = path.join(this.projectPath, 'preview.png'); const previewResult = await this.tt.preview({ project: { path: this.projectPath }, // @ts-ignore page: { path: '' }, qrcode: { format: 'imageFile', output: previewQrcodePath, }, copyToClipboard: true, cache: true, ideConfig: { skipDomainCheck: (_b = (_a = this.pluginOpts.tt) === null || _a === void 0 ? void 0 : _a.setting) === null || _b === void 0 ? void 0 : _b.skipDomainCheck, }, }); console.log(chalk.green(`开发版上传成功 ${new Date().toLocaleString()}\n`)); const qrContent = previewResult.shortUrl; await (0, qrcode_1.printQrcode2Terminal)(qrContent); printLog("remind" /* processTypeEnum.REMIND */, `预览二维码已生成,存储在:"${previewQrcodePath}",二维码内容是:${qrContent},过期时间:${new Date(previewResult.expireTime * 1000).toLocaleString()}`); this.triggerPreviewHooks({ success: true, data: { platform: 'tt', qrCodeContent: qrContent, qrCodeLocalPath: previewQrcodePath } }); } catch (error) { printLog("error" /* processTypeEnum.ERROR */, chalk.red(`上传失败 ${new Date().toLocaleString()} \n${error}`)); this.triggerPreviewHooks({ success: false, data: { platform: 'tt', qrCodeContent: '', qrCodeLocalPath: '' }, error: new Error(error) }); } } async upload() { await this._beforeCheck(); const { chalk, printLog, processTypeEnum } = this.ctx.helper; try { printLog("start" /* processTypeEnum.START */, '上传代码到抖音开放平台后台'); printLog("remind" /* processTypeEnum.REMIND */, `本次上传版本号为:"${this.version}",上传描述为:“${this.desc}”`); const uploadQrcodePath = path.join(this.projectPath, 'upload.png'); const uploadResult = await this.tt.upload({ project: { path: this.projectPath }, qrcode: { format: 'imageFile', output: uploadQrcodePath, }, version: this.version, changeLog: this.desc, needUploadSourcemap: true, copyToClipboard: false }); console.log(chalk.green(`体验版版上传成功 ${new Date().toLocaleString()}\n`)); const qrContent = uploadResult.shortUrl; await (0, qrcode_1.printQrcode2Terminal)(qrContent); printLog("remind" /* processTypeEnum.REMIND */, `体验版二维码已生成,存储在:"${uploadQrcodePath}",二维码内容是:"${qrContent}", 过期时间:${new Date(uploadResult.expireTime * 1000).toLocaleString()}`); this.triggerUploadHooks({ success: true, data: { platform: 'tt', qrCodeContent: qrContent, qrCodeLocalPath: uploadQrcodePath } }); } catch (error) { printLog("error" /* processTypeEnum.ERROR */, chalk.red(`上传失败 ${new Date().toLocaleString()} \n${error}`)); this.triggerUploadHooks({ success: false, data: { platform: 'tt', qrCodeContent: '', qrCodeLocalPath: '' }, error: new Error(error) }); } } } exports.default = TTCI; //# sourceMappingURL=TTCI.js.map