UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

186 lines (179 loc) 8.05 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib_es6 = require('../tslib.es6-01322ba9.js'); var path = require('path'); var bite_formatBite = require('../bite/format-bite.js'); var fs_fs = require('../fs/fs.js'); var git_git = require('../git/git.js'); var mp_pageTotal = require('../mp/page-total.js'); var time_time = require('../time/time.js'); var wecomRobot_batchSend = require('../wecom-robot/batch-send.js'); require('fs'); require('../node/node-command.js'); require('@babel/runtime/helpers/typeof'); require('../node/fs-util.js'); require('../wecom-robot/base.js'); require('../wecom-robot/helper.js'); require('axios'); require('../wecom-robot/send-img.js'); require('../node-img/img.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var path__default = /*#__PURE__*/_interopDefaultLegacy(path); function parsePreviewResult(subPackageInfo, maxSubPackageNum) { if (maxSubPackageNum === void 0) { maxSubPackageNum = 10; } var subPackagesList = []; try { subPackagesList = JSON.parse(subPackageInfo); } catch (err) {} var previewMap = subPackagesList.reduce(function (acc, item) { var _a; return tslib_es6.__assign(tslib_es6.__assign({}, acc), (_a = {}, _a[item.name] = item.size, _a)); }, {}); var keyList = Object.keys(previewMap).filter(function (item) { return !['__APP__', '__FULL__'].includes(item); }); keyList.sort(function (a, b) { return previewMap[b] - previewMap[a]; }); keyList = keyList.slice(0, maxSubPackageNum); var list = tslib_es6.__spreadArray(["\u4E3B\u5305: `".concat(bite_formatBite.formatBite(previewMap.__APP__), "`"), "\u603B\u5305: `".concat(bite_formatBite.formatBite(previewMap.__FULL__), "`")], keyList.map(function (key) { return "".concat(key.replace(/^\/|\/$/g, ''), ": `").concat(bite_formatBite.formatBite(previewMap[key]), "`"); }), true); return list.join(','); } var getRobotMessageItem = function getRobotMessageItem(key, value, isLight) { if (isLight === void 0) { isLight = false; } if (isLight) { return "".concat(key, "\uFF1A`").concat(value, "`"); } return "".concat(key, "\uFF1A").concat(value); }; function getDescMap(_a) { var robot = _a.robot, root = _a.root, env = _a.env, branch = _a.branch; return tslib_es6.__awaiter(this, void 0, void 0, function () { var commitInfo, version, time, descMap; return tslib_es6.__generator(this, function (_b) { commitInfo = git_git.getGitCommitInfo(root, false, false, false); version = ''; try { // eslint-disable-next-line @typescript-eslint/no-require-imports version = require(path__default["default"].resolve(root, './package.json')).version; } catch (err) {} time = time_time.timeStampFormat(Date.now(), 'yyyy-MM-dd hh:mm:ss'); descMap = { branch: { title: '分支', content: "".concat(branch || commitInfo.branch) }, env: { title: '环境', content: "".concat(env) }, robot: { title: '机器人', content: "".concat(robot) }, version: { title: '版本', content: "".concat(version) || '' }, lastCommit: { title: '最后提交', content: "".concat(commitInfo.author, " - ").concat(commitInfo.message, " - ").concat(commitInfo.hash || '') }, time: { title: '时间', content: "".concat(time) } }; console.log('[CI] descMap: ', descMap); return [2 /*return*/, descMap]; }); }); } function getDescList(_a) { var bundleResult = _a.bundleResult, subPackageInfo = _a.subPackageInfo, robot = _a.robot, root = _a.root, env = _a.env, branch = _a.branch; return tslib_es6.__awaiter(this, void 0, void 0, function () { var descMap, branchInfo, envInfo, robotInfo, versionInfo, lastCommitInfo, componentInfo, pageInfo, _b, componentTotal, _c, wxmlSizeTotal, _d, wxssSizeTotal, _e, jsSizeTotal, _f, vendorJsSize, _g, pageTotal, _h, subPackageTotal; return tslib_es6.__generator(this, function (_j) { switch (_j.label) { case 0: return [4 /*yield*/, getDescMap({ robot: robot, root: root, env: env, branch: branch })]; case 1: descMap = _j.sent(); branchInfo = descMap.branch, envInfo = descMap.env, robotInfo = descMap.robot, versionInfo = descMap.version, lastCommitInfo = descMap.lastCommit; componentInfo = mp_pageTotal.getComponentInfo(bundleResult); pageInfo = mp_pageTotal.getPageTotal(bundleResult); _b = componentInfo.componentTotal, componentTotal = _b === void 0 ? 0 : _b, _c = componentInfo.wxmlSizeTotal, wxmlSizeTotal = _c === void 0 ? 0 : _c, _d = componentInfo.wxssSizeTotal, wxssSizeTotal = _d === void 0 ? 0 : _d, _e = componentInfo.jsSizeTotal, jsSizeTotal = _e === void 0 ? 0 : _e, _f = componentInfo.vendorJsSize, vendorJsSize = _f === void 0 ? 0 : _f; _g = pageInfo.pageTotal, pageTotal = _g === void 0 ? 0 : _g, _h = pageInfo.subPackageTotal, subPackageTotal = _h === void 0 ? 0 : _h; return [2 /*return*/, [[getRobotMessageItem(branchInfo.title, branchInfo.content, true), getRobotMessageItem(envInfo.title, envInfo.content, true), getRobotMessageItem(robotInfo.title, robotInfo.content, true), getRobotMessageItem(versionInfo.title, versionInfo.content, true), "[\u6784\u5EFA\u5730\u5740](".concat(process.env.BK_CI_BUILD_URL || '', ")"), getRobotMessageItem(lastCommitInfo.title, lastCommitInfo.content, false)].join(','), "- ".concat([getRobotMessageItem('页面数', pageTotal, true), getRobotMessageItem('组件数', componentTotal, true), getRobotMessageItem('分包数', subPackageTotal, true)].join(',')), "- ".concat([getRobotMessageItem('JS总大小', bite_formatBite.formatBite(jsSizeTotal), true), getRobotMessageItem('Vendor大小', bite_formatBite.formatBite(vendorJsSize), true), getRobotMessageItem('样式总大小', bite_formatBite.formatBite(wxssSizeTotal), true), getRobotMessageItem('WXML总大小', bite_formatBite.formatBite(wxmlSizeTotal), true)].join(',')), "- ".concat(parsePreviewResult(subPackageInfo, 5))]]; } }); }); } function sendWxMpCIMessageAfterPlugin(_a) { var appName = _a.appName, webhookUrl = _a.webhookUrl, previewCodeBase64Path = _a.previewCodeBase64Path, bundleResult = _a.bundleResult, subPackageInfo = _a.subPackageInfo, robot = _a.robot, root = _a.root, env = _a.env, branch = _a.branch; return tslib_es6.__awaiter(this, void 0, void 0, function () { var descList, content, previewCodeBase64P; return tslib_es6.__generator(this, function (_b) { switch (_b.label) { case 0: if (!webhookUrl) return [2 /*return*/]; return [4 /*yield*/, getDescList({ bundleResult: bundleResult, subPackageInfo: subPackageInfo, robot: robot, root: root, env: env, branch: branch })]; case 1: descList = _b.sent(); content = "> \u2705\u3010".concat(appName, " WX MP\u3011").concat(descList.join('\n')); return [4 /*yield*/, wecomRobot_batchSend.batchSendWxRobotMarkdown({ webhookUrl: webhookUrl, chatId: 'ALL', content: content })]; case 2: _b.sent(); previewCodeBase64P = fs_fs.readFileSync(previewCodeBase64Path); if (!previewCodeBase64P) return [2 /*return*/]; return [4 /*yield*/, wecomRobot_batchSend.batchSendWxRobotBase64Img({ img: previewCodeBase64P, chatId: 'ALL', webhookUrl: webhookUrl })]; case 3: _b.sent(); return [2 /*return*/]; } }); }); } exports.sendWxMpCIMessageAfterPlugin = sendWxMpCIMessageAfterPlugin;