UNPKG

t-comm

Version:

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

109 lines (106 loc) 3.31 kB
import { execCommand } from '../node/node-command.mjs'; import { sendWxRobotMarkdown } from '../wecom-robot/base.mjs'; import { genVersion } from './gen-version.mjs'; import { genVersionTip } from './gen-version-tip.mjs'; import '@babel/runtime/helpers/typeof'; import '../tslib.es6-096fffdd.js'; import '../wecom-robot/helper.mjs'; import 'axios'; import 'fs'; import 'path'; import '../git/git.mjs'; import '../time/time.mjs'; import './config.mjs'; import '../string/replace-all.mjs'; import '../wecom-robot/optimize-robot-content.mjs'; /* eslint-disable @typescript-eslint/no-require-imports */ /** * 运行standard-version,并且发送changelog到机器人 * @param {object} options 配置 * @param {object} config.appInfo package.json信息 * @param {string} config.root 项目根路径 * @param {string} config.changeLogFilePath changelog文件地址 * @param {string} config.webhookUrl 机器人hook地址 * @param {string} config.chatId 会话id */ function genVersionAndSendChangeLog(_a) { var root = _a.root, changeLogFilePath = _a.changeLogFilePath, webhookUrl = _a.webhookUrl, chatId = _a.chatId, forceGenVersion = _a.forceGenVersion, _b = _a.pushRemote, pushRemote = _b === void 0 ? true : _b; return new Promise(function (resolve, reject) { if (!root) { reject('ERROR: root不可以为空'); return; } if (!changeLogFilePath) { changeLogFilePath = "".concat(root, "/CHANGELOG.md"); } var hasGenVersion = genVersion({ root: root, forceGenVersion: forceGenVersion }); if (!hasGenVersion) { resolve({ hasGenVersion: false }); return; } if (pushRemote) { try { console.log('[GEN SEND VERSION] Doing git push --follow-tags origin ...'); execCommand('git push --follow-tags origin', root, 'inherit'); console.log('[GEN SEND VERSION] Done git push --follow-tags origin.'); } catch (err) { reject(err); return; } } // appInfo 不要用传入的参数,因此传入是旧的,新的还未生成 var appInfo = require("".concat(root, "/package.json")); sendVersionTip({ appInfo: appInfo, changeLogFilePath: changeLogFilePath, webhookUrl: webhookUrl, chatId: chatId }).then(resolve)["catch"](reject); }); } function sendVersionTip(_a) { var appInfo = _a.appInfo, changeLogFilePath = _a.changeLogFilePath, webhookUrl = _a.webhookUrl, chatId = _a.chatId; return new Promise(function (resolve, reject) { var content = genVersionTip({ readmeFilePath: changeLogFilePath, appInfo: appInfo }); if (!content) { resolve({ hasGenVersion: true, hasSendChangeLog: false, sendChangeLogError: 'empty changelog content' }); return; } console.log('[GEN SEND VERSION] Doing send wecom robot markdown ...'); sendWxRobotMarkdown({ chatId: chatId, content: content, webhookUrl: webhookUrl }).then(function () { resolve({ hasGenVersion: true, hasSendChangeLog: true }); console.log('[GEN SEND VERSION] Done send wecom robot markdown.'); })["catch"](function (err) { reject(err); }); }); } export { genVersionAndSendChangeLog };