t-comm
Version:
专业、稳定、纯粹的工具库
125 lines (122 loc) • 3.92 kB
JavaScript
import { readFileSync } from '../fs/fs.mjs';
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 '../nodejs/crypto.mjs';
import '../nodejs/fs.mjs';
import '../nodejs/os.mjs';
import '@babel/runtime/helpers/typeof';
import '../nodejs/child_process.mjs';
import '@babel/runtime/regenerator';
import '../tslib.es6-848120af.js';
import '../wecom-robot/helper.mjs';
import 'axios';
import '@babel/runtime/helpers/slicedToArray';
import '../nodejs/path.mjs';
import '../git/git.mjs';
import '../validate/validate.mjs';
import '../time/time.mjs';
import './config.mjs';
import '../string/replace-all.mjs';
import '../bite/format-bite.mjs';
import '../wecom-robot/optimize-robot-content.mjs';
/**
* 运行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
* @example
* ```ts
* await genVersionAndSendChangeLog({
* root: process.cwd(),
* changeLogFilePath: `${process.cwd()}/CHANGELOG.md`,
* webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx',
* chatId: 'group-chat-id',
* });
* ```
*/
function genVersionAndSendChangeLog(_ref) {
var root = _ref.root,
changeLogFilePath = _ref.changeLogFilePath,
webhookUrl = _ref.webhookUrl,
chatId = _ref.chatId,
forceGenVersion = _ref.forceGenVersion,
_ref$pushRemote = _ref.pushRemote,
pushRemote = _ref$pushRemote === void 0 ? true : _ref$pushRemote;
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 = readFileSync("".concat(root, "/package.json"), true);
sendVersionTip({
appInfo: appInfo,
changeLogFilePath: changeLogFilePath,
webhookUrl: webhookUrl,
chatId: chatId
}).then(resolve)["catch"](reject);
});
}
function sendVersionTip(_ref2) {
var appInfo = _ref2.appInfo,
changeLogFilePath = _ref2.changeLogFilePath,
webhookUrl = _ref2.webhookUrl,
chatId = _ref2.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 };