提交subgame插件

This commit is contained in:
Kirito
2025-07-11 14:49:28 +08:00
commit b225060f0f
1240 changed files with 257564 additions and 0 deletions

173
dist/build/handler/FeishuHandler.js vendored Normal file
View File

@@ -0,0 +1,173 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ProcessUtils_1 = __importDefault(require("../../utils/ProcessUtils"));
const RobotFeishu_1 = __importDefault(require("../robot/RobotFeishu"));
const Handler_1 = __importStar(require("./Handler"));
const HEAD_TEMPLATE = ['blue', 'wathet', 'turquoise', 'green', 'yellow', 'orange', 'red', 'carmine', 'violet', 'purple', 'indigo', 'grey'];
class FeishuHandler extends Handler_1.default {
gitHistroyToMD(logs) {
let logString = '';
for (let index = 0, length = Math.min(logs.length, Handler_1.BUILD_HISTROY_LIMIT); index < length; index++) {
const { name, title } = logs[index];
if (index !== 0)
logString += '\n';
const fixTitle = title.replace(new RegExp('\\#', 'gm'), '\\#').replace(new RegExp('\\*', 'gm'), '\\*');
;
logString += `**${name}** - ${fixTitle}`;
}
if (logs.length > Handler_1.BUILD_HISTROY_LIMIT) {
logString += '\n';
logString += `......`;
}
return logString;
}
onExceBegin() {
return __awaiter(this, void 0, void 0, function* () {
const customData = this.getCustomData();
if (customData && customData.length) {
const data = {
config: { wide_screen_mode: true },
header: {
title: { tag: 'plain_text', content: `${this.taskName} 开始构建` },
template: 'grey'
},
elements: []
};
const fields = [];
customData.forEach(item => {
if (typeof item === 'string')
fields.push({ is_short: false, text: { tag: 'lark_md', content: item } });
else
fields.push({ is_short: true, text: { tag: 'lark_md', content: `${item.key}: **${item.value}**` } });
});
data.elements.push({ tag: 'div', fields });
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
}
else {
RobotFeishu_1.default.send(this.robotKey, 'text', { text: `${this.taskName} 开始构建` });
}
});
}
onExceEnd(buildInfo) {
return __awaiter(this, void 0, void 0, function* () {
const data = {
config: { wide_screen_mode: true },
header: {
title: { tag: 'plain_text', content: `${this.taskName} 构建完成` },
template: 'grey'
},
elements: []
};
const customData = this.getCustomData();
if (customData && customData.length) {
data.elements.length && data.elements.push({ tag: 'hr' });
const fields = [];
customData.forEach(item => {
if (typeof item === 'string')
fields.push({ is_short: false, text: { tag: 'lark_md', content: item } });
else
fields.push({ is_short: true, text: { tag: 'lark_md', content: `${item.key}: **${item.value}**` } });
});
data.elements.push({ tag: 'div', fields });
}
if (buildInfo && buildInfo.logs && buildInfo.logs.length) {
data.elements.length && data.elements.push({ tag: 'hr' });
const gitHistroyString = this.gitHistroyToMD(buildInfo.logs);
data.elements.push({ tag: 'markdown', content: gitHistroyString });
}
const url = ProcessUtils_1.default.getArg('--url', value => value && value.startsWith('http'));
if (url) {
data.elements.push({
tag: 'div', text: { tag: 'lark_md', content: '' },
extra: { tag: 'button', text: { tag: 'lark_md', content: '查看/下载' }, type: 'primary', url }
});
}
if (buildInfo) {
data.elements.push({ tag: 'note', elements: [{ tag: 'plain_text', content: `构建耗时: ${this.timeFormat(buildInfo.time)}` }] });
}
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
});
}
beforeExceSleep(continueUrl) {
return __awaiter(this, void 0, void 0, function* () {
const data = {
config: { wide_screen_mode: true },
header: {
title: { tag: 'plain_text', content: `${this.taskName} 构建暂停` },
template: 'grey'
},
elements: []
};
const customData = this.getCustomData();
if (customData && customData.length) {
data.elements.length && data.elements.push({ tag: 'hr' });
const fields = [];
customData.forEach(item => {
if (typeof item === 'string')
fields.push({ is_short: false, text: { tag: 'lark_md', content: item } });
else
fields.push({ is_short: true, text: { tag: 'lark_md', content: `${item.key}: **${item.value}**` } });
});
data.elements.push({ tag: 'div', fields });
}
data.elements.push({
tag: 'div', text: { tag: 'lark_md', content: '' },
extra: { tag: 'button', text: { tag: 'lark_md', content: '继续构建' }, type: 'primary', url: continueUrl }
});
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
});
}
afterExceSleep() {
return __awaiter(this, void 0, void 0, function* () {
yield RobotFeishu_1.default.send(this.robotKey, 'text', { text: `${this.taskName} 构建恢复` });
});
}
timeFormat(time) {
let ms = time;
let s = Math.floor(time / 1000);
if (s <= 0)
return `${ms}毫秒`;
ms -= s * 1000;
const min = Math.floor(s / 60);
if (min <= 0)
return `${s}${ms}毫秒`;
s -= min * 60;
return `${min}${s}${ms}毫秒`;
}
}
exports.default = FeishuHandler;

98
dist/build/handler/Handler.js vendored Normal file
View File

@@ -0,0 +1,98 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BUILD_HISTROY_LIMIT = void 0;
const crypto_1 = __importDefault(require("crypto"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const BuildUtils_1 = __importDefault(require("../../utils/BuildUtils"));
const FileUtils_1 = __importDefault(require("../../utils/FileUtils"));
exports.BUILD_HISTROY_LIMIT = 20;
class Handler {
constructor(robotKey, taskName, projectDir, data) {
this.robotKey = robotKey;
this.taskName = taskName;
this.projectDir = projectDir;
this.data = data;
const hash = crypto_1.default.createHash('md5');
hash.update(projectDir, 'utf8');
const hex = hash.digest('hex');
console.log(`Project Hex: ${hex}`);
this.configFilePath = path_1.default.join(__dirname, '..', '..', '.__build_start_mark', `${hex}.json`);
FileUtils_1.default.mkdir(path_1.default.dirname(this.configFilePath));
}
markBuildStart() {
return __awaiter(this, void 0, void 0, function* () {
let config;
if (fs_1.default.existsSync(this.configFilePath)) {
const configString = fs_1.default.readFileSync(this.configFilePath).toString();
config = JSON.parse(configString);
console.log(`Read Cache Git Version: ${config.version} From ${this.configFilePath}`);
}
else {
config = {};
config.version = yield BuildUtils_1.default.readGitVersion(this.projectDir);
console.log(`Get Git Version: ${config.version}`);
}
config.timestamp = Date.now();
fs_1.default.writeFileSync(this.configFilePath, JSON.stringify(config));
});
}
getBuildInfo() {
return __awaiter(this, void 0, void 0, function* () {
if (!fs_1.default.existsSync(this.configFilePath)) {
console.log(`Config File Not Exist`);
return null;
}
const configString = fs_1.default.readFileSync(this.configFilePath).toString();
const config = JSON.parse(configString);
FileUtils_1.default.rm(this.configFilePath);
const logs = config.version ? yield BuildUtils_1.default.readGitLog(this.projectDir, config.version) : [];
const time = config.timestamp ? (Date.now() - config.timestamp) : 0;
return { logs, time };
});
}
getCustomData() {
const customData = [];
if (!this.data)
return customData;
const customDataArray = this.data.split(';');
if (!customDataArray)
return customData;
customDataArray.forEach(item => {
if (!item || !item.length)
return;
item = item.replace('==', '|||||');
const data = item.split('=').map(value => value.replace('|||||', '='));
if (data.length === 1)
customData.push(data[0]);
else if (data.length === 2)
customData.push({ key: data[0], value: data[1] });
});
return customData;
}
begin() {
return __awaiter(this, void 0, void 0, function* () {
yield this.markBuildStart();
yield this.onExceBegin();
});
}
end() {
return __awaiter(this, void 0, void 0, function* () {
const buildInfo = yield this.getBuildInfo();
yield this.onExceEnd(buildInfo);
});
}
}
exports.default = Handler;

93
dist/build/handler/WechatHandler.js vendored Normal file
View File

@@ -0,0 +1,93 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RobotFeishu_1 = __importDefault(require("../robot/RobotFeishu"));
const RobotWechat_1 = __importDefault(require("../robot/RobotWechat"));
const Handler_1 = __importStar(require("./Handler"));
class WechatHandler extends Handler_1.default {
sendTextMessage(text) {
const data = {
config: { wide_screen_mode: true },
header: {
title: { tag: 'plain_text', content: this.taskName },
template: 'grey'
},
elements: [{ tag: 'markdown', content: text }]
};
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
}
onExceBegin() {
return __awaiter(this, void 0, void 0, function* () {
this.sendTextMessage(`开始构建`);
});
}
onExceEnd(buildInfo) {
return __awaiter(this, void 0, void 0, function* () {
let message = `${this.taskName}构建完成`;
const customData = this.getCustomData();
if (customData && customData.length) {
customData.forEach(item => {
message += '\n';
if (typeof item === 'string')
message += item;
else
message += `${item.key}:: **${item.value}**`;
});
}
if (buildInfo && buildInfo.logs && buildInfo.logs.length) {
for (let index = 0, length = Math.min(buildInfo.logs.length, Handler_1.BUILD_HISTROY_LIMIT); index < length; index++) {
const { name, title } = buildInfo.logs[index];
if (index !== 0)
message += '\n';
const fixTitle = title.replace(new RegExp('\\#', 'gm'), '\\#').replace(new RegExp('\\*', 'gm'), '\\*');
;
message += `>**${name}** - ${fixTitle}`;
}
if (buildInfo.logs.length > Handler_1.BUILD_HISTROY_LIMIT)
message += `\n>......`;
}
RobotWechat_1.default.send(this.robotKey, 'markdown', message);
});
}
beforeExceSleep(continueUrl) {
return __awaiter(this, void 0, void 0, function* () { });
}
afterExceSleep() {
return __awaiter(this, void 0, void 0, function* () { });
}
}
exports.default = WechatHandler;

28
dist/build/robot/RobotFeishu.js vendored Normal file
View File

@@ -0,0 +1,28 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const request_1 = __importDefault(require("request"));
var RobotFeishu;
(function (RobotFeishu) {
const WEBHOOK_URL = 'https://open.larksuite.com/open-apis/bot/v2/hook/';
function send(key, messageType, content) {
const promise = new Promise(resolve => {
const messageData = { msg_type: messageType };
if (messageType === 'interactive')
messageData.card = content;
else
messageData.content = content;
const body = JSON.stringify(messageData);
request_1.default.post({
url: WEBHOOK_URL + key, method: "POST",
headers: { "content-type": "application/json", },
body
}, (error, response, body) => resolve({ error, response, body }));
});
return promise;
}
RobotFeishu.send = send;
})(RobotFeishu || (RobotFeishu = {}));
exports.default = RobotFeishu;

24
dist/build/robot/RobotWechat.js vendored Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const request_1 = __importDefault(require("request"));
var RobotWechat;
(function (RobotWechat) {
const WEBHOOK_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=';
RobotWechat.send = (key, messageType, message) => {
let messageData = { msgtype: messageType };
messageData[messageType] = { content: message };
let messageString = JSON.stringify(messageData);
(0, request_1.default)({
url: WEBHOOK_URL + key,
method: "POST",
headers: {
"content-type": "application/json",
},
body: messageString
});
};
})(RobotWechat || (RobotWechat = {}));
exports.default = RobotWechat;