preBuild.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import * as child_process from 'child_process'
  2. import * as fs from 'fs'
  3. import dayjs from 'dayjs'
  4. let commitId = child_process.execSync(`git log -n1 --format=format:"%H"`).toString();
  5. let commitUser = child_process.execSync(`git log -n1 --format=format:"%an"`).toString();
  6. let commitBranch = child_process.execSync(`git log -n1 --format=format:"%d"`).toString().trim();
  7. let commitTime = child_process.execSync(`git log -n1 --pretty=format:"%ad" --date=iso`).toString().substring(0, 19);
  8. let buildUser = child_process.execSync(`git config user.name`).toString().trim();
  9. // const txt = `提交ID:${commitId}
  10. // 提交用户:${commitUser}
  11. // 提交分支:${commitBranch}
  12. // 提交时间:${commitTime}
  13. // 打包用户:${buildUser}
  14. // 打包时间:${dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')}
  15. // `
  16. const j = {
  17. '提交ID:': commitId,
  18. '提交用户:': commitUser,
  19. '提交分支:': commitBranch,
  20. '提交时间:': commitTime,
  21. '打包用户:': buildUser,
  22. '打包时间:': dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'),
  23. }
  24. fs.writeFileSync('./src/out/git_info.json', JSON.stringify(j));
  25. console.log('========== Save git info done. ==========');