const https = require('https');
const packageInfo = require('../package.json'); // 从package.json文件中提取name、版本号
const config = {
name: packageInfo.name,
version: packageInfo.version,
};
// 从文件Changelog.md中获取更新内容
const fs = require("fs");
const buffer = fs.readFileSync('./Changelog.md', "utf-8");
const changelog = buffer.match(/```js\s*((.|\s)*?)\s*```/ig).pop().replace(/```js\s*((.|\s)*?)\s*```/ig, '$1');
const DEPLOYED_MESSAGE = `
${config.name} ${config.version} 发布成功!
更新内容:
${changelog}
查看链接:
http://47.114.119.218:4873/-/web/detail/${config.name}
`;
const data = { msgtype: 'text', text: { 'content': DEPLOYED_MESSAGE }};
const requestData = JSON.stringify(data);
const token = 'ee07bad1-74ec-4de5-b783-49d000c3fc19'; // 邻汇吧-FE前端 机器人id
const url = 'qyapi.weixin.qq.com';
const req = https.request({
hostname: url,
port: 443,
path: `/cgi-bin/webhook/send?key=${token}`,
method: 'POST',
json: true,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
});
req.write(requestData);
req.on('error', function(err) {
console.error(err);
});
req.end();
console.log('企业微信已通知成功');