t-comm
Version:
专业、稳定、纯粹的工具库
111 lines (106 loc) • 3.5 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var node_nodeCommand = require('../node/node-command.js');
var wecomRobot_base = require('../wecom-robot/base.js');
var versionTip_genVersion = require('./gen-version.js');
var versionTip_genVersionTip = require('./gen-version-tip.js');
require('@babel/runtime/helpers/typeof');
require('../tslib.es6-01322ba9.js');
require('../wecom-robot/helper.js');
require('axios');
require('../time/time.js');
require('./config.js');
require('../git/git.js');
require('../wecom-robot/optimize-robot-content.js');
require('../string/replace-all.js');
/* 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 = versionTip_genVersion.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 ...');
node_nodeCommand.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 = versionTip_genVersionTip.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 ...');
wecomRobot_base.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);
});
});
}
exports.genVersionAndSendChangeLog = genVersionAndSendChangeLog;