import * as child_process from 'child_process' import * as fs from 'fs' import dayjs from 'dayjs' let commitId = child_process.execSync(`git log -n1 --format=format:"%H"`).toString(); let commitUser = child_process.execSync(`git log -n1 --format=format:"%an"`).toString(); let commitBranch = child_process.execSync(`git log -n1 --format=format:"%d"`).toString().trim(); let commitTime = child_process.execSync(`git log -n1 --pretty=format:"%ad" --date=iso`).toString().substring(0, 19); let buildUser = child_process.execSync(`git config user.name`).toString().trim(); // const txt = `提交ID:${commitId} // 提交用户:${commitUser} // 提交分支:${commitBranch} // 提交时间:${commitTime} // 打包用户:${buildUser} // 打包时间:${dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')} // ` const j = { '提交ID:': commitId, '提交用户:': commitUser, '提交分支:': commitBranch, '提交时间:': commitTime, '打包用户:': buildUser, '打包时间:': dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'), } fs.writeFileSync('./src/out/git_info.json', JSON.stringify(j)); console.log('========== Save git info done. ==========');