86 lines
3.8 KiB
TypeScript
86 lines
3.8 KiB
TypeScript
import child_process from 'child_process';
|
|
const LOG_SPLIT_SEPARATOR: string = '||||||';
|
|
|
|
const exec = (cmd: string): Promise<string> => {
|
|
const promise: Promise<string> = new Promise((resolve: (value: string) => void) => {
|
|
let result: string = '';
|
|
const stream = child_process.spawn(cmd, {});
|
|
stream.on('message', (message: child_process.Serializable, sendHandle: child_process.SendHandle) => {
|
|
console.log('stdout: ' + message.toString());
|
|
result !== null && (result += message.toString());
|
|
});
|
|
|
|
stream.once("exit", (code: number, signal: NodeJS.Signals) => resolve(result || ""));
|
|
|
|
});
|
|
return promise;
|
|
}
|
|
|
|
export const readSvnVersion = (dir: string): string => {
|
|
const svnInfoString = child_process.execSync(`cd "${dir}" & svn info`).toString();
|
|
const svnInfo = svnInfoString.split('\n');
|
|
let version: string;
|
|
for (let item of svnInfo) {
|
|
let info: string[] = item.split(': ');
|
|
if (info[0] === 'Revision') {
|
|
version = info[1];
|
|
break;
|
|
}
|
|
}
|
|
return version;
|
|
}
|
|
|
|
// export const readSvnLog = (dir: string, startVersion: number): string[] => {
|
|
|
|
// }
|
|
|
|
export const readGitVersion = (dir: string): string => {
|
|
const commit = child_process.execSync(`cd "${dir}" & git show -s --format=%H`).toString().trim();
|
|
return commit;
|
|
|
|
}
|
|
|
|
export const readGitLog = async (dir: string, startVersion: string): Promise<{ name: string; title: string; }[]> => {
|
|
let command = `cd "${dir}" & `;
|
|
command += startVersion ? `git log ${startVersion}.. ` : 'git log ';
|
|
command += `--pretty=format:"%an${LOG_SPLIT_SEPARATOR}%s${LOG_SPLIT_SEPARATOR}%H" --no-merges`;
|
|
const log = child_process.execSync(command).toString();
|
|
const logArray = log.split('\n');
|
|
|
|
const messageArray: { name: string, title: string }[] = [];
|
|
logArray.forEach((element: string) => {
|
|
if (!element || !element.length) return;
|
|
const data = element.split(LOG_SPLIT_SEPARATOR);
|
|
if (!data || data.length !== 3) return;
|
|
const [name, title, id] = data;
|
|
if (title === 'commit meta with etc1') return;
|
|
if (title.indexOf('from jenkins') >= 0) {
|
|
const jenkinsName = 'Jenkins';
|
|
const resourceLog = child_process.execSync(`cd "${dir}" & git diff-tree -r --no-commit-id --name-only ${id}`).toString();
|
|
if (resourceLog.indexOf('assets/resources/conf/allConf.json') >= 0)
|
|
messageArray.push({ name: jenkinsName, title: '数据表更新' });
|
|
if (resourceLog.indexOf('assets/resources/conf/allTrack.json') >= 0)
|
|
messageArray.push({ name: jenkinsName, title: 'Track表更新' });
|
|
if (resourceLog.indexOf('assets/resources/conf/path.json') >= 0)
|
|
messageArray.push({ name: jenkinsName, title: 'Path表更新' });
|
|
if (resourceLog.indexOf('assets/resources/audio') >= 0)
|
|
messageArray.push({ name: jenkinsName, title: '音效更新' });
|
|
if (resourceLog.indexOf('assets/res/anim/testure/fish') >= 0 || resourceLog.indexOf('assets/resources/anim/clip/fish') >= 0) {
|
|
const regExp = new RegExp('assets/((resources/anim/clip)|(res/anim/texture))/fish/([a-zA-Z0-9_]+)', 'g');
|
|
const result: string[] = [];
|
|
let matchArray: RegExpMatchArray;
|
|
while (matchArray = regExp.exec(resourceLog)) {
|
|
let fishName: string = matchArray[4];
|
|
if (result.indexOf(fishName) >= 0) continue;
|
|
result.push(fishName);
|
|
messageArray.push({ name: jenkinsName, title: `${fishName}鱼动画资源更新` });
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
messageArray.push({ name, title });
|
|
}
|
|
})
|
|
return messageArray;
|
|
|
|
} |