const fs = require("fs"); const child_process = require('child_process'); module.exports = (path) => { try { const gitHEAD = fs.readFileSync(path + '/.git/HEAD', 'utf-8').trim(); // ref: refs/heads/develop const ref = gitHEAD.split(': ')[1];// refs/heads/develop const branch = gitHEAD.split('/')[2];// 环境:develop const buildVersion = fs.readFileSync(path + '/.git/' + ref, 'utf-8').trim(); // git版本号,例如:6ceb0ab5059d01fd444cf4e78467cc2dd1184a66 const buildUserName = child_process.execSync('git config user.name').toString().trim(); const buildUserMail = child_process.execSync('git config user.email').toString().trim(); const nowDate = new Date(); const buildDate = `${nowDate.getFullYear() + '-' + (nowDate.getMonth() + 1) + '-' + nowDate.getDate() + ' ' + nowDate.getHours() + ':' + nowDate.getMinutes()}`; return { branch, buildVersion, buildUserName, buildUserMail, buildDate }; } catch (e) { return {} } };