GAAS GFrame项目web前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
2.8 KiB

  1. /**定义模块和变量**/
  2. const execSync = require('child_process').execSync; //同步子进程
  3. const fs = require('fs'); //文件读取模块
  4. const versionPath = 'version.log.js'; //version路径
  5. const buildPath = 'dist'; //打包的路径
  6. const autoPush = false; //写入版本信息之后是否自动提交git上
  7. const commit = execSync('git show -s --format=%H').toString().trim(); //当前提交的版本号
  8. /**程序开始**/
  9. var versionStr = ""; //版本信息字符串
  10. // 如果versionPath存在,将先读取里边的版本信息
  11. if (fs.existsSync(versionPath)) {
  12. versionStr = fs.readFileSync(versionPath).toString() + '\n';
  13. }
  14. // 根据版本信息是已存在commit,进行不同处理
  15. if (versionStr.indexOf(commit) != -1) {
  16. console.warn('\x1B[33m%s\x1b[0m', 'warming: 当前的git版本数据已经存在了!\n')
  17. } else {
  18. let name = execSync('git show -s --format=%cn').toString().trim(); //姓名
  19. let email = execSync('git show -s --format=%ce').toString().trim(); //邮箱
  20. let date = new Date(execSync('git show -s --format=%cd').toString()); //日期
  21. versionStr = `console.log('git:${commit};作者:${name}<${email}>;日期:${date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()}')`;
  22. fs.writeFileSync(versionPath, versionStr);
  23. // 写入版本信息之后,自动将版本信息提交到当前分支的git上
  24. if (autoPush) {
  25. execSync(`git commit ${versionPath} -m 自动提交版本信息`);
  26. execSync(`git push origin ${execSync('git rev-parse --abbrev-ref HEAD').toString().trim()}`);
  27. }
  28. }
  29. // 将version文件移植到打包文件中
  30. if (fs.existsSync(buildPath)) {
  31. fs.writeFileSync(`${buildPath}/${versionPath}`, fs.readFileSync(versionPath));
  32. }
  33. // 程序执行结束
  34. console.info('\x1B[32m%s\x1b[0m', [
  35. "██████╗ ███████╗██████╗ ███████╗ █████╗ ██████╗██╗ ██╗",
  36. "██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝",
  37. "██████╔╝█████╗ ██████╔╝███████╗███████║██║ ███╗╚████╔╝ ",
  38. "██╔═══╝ ██╔══╝ ██╔══██╗╚════██║██╔══██║██║ ██║ ╚██╔╝ ",
  39. "██║ ███████╗██║ ██║███████║██║ ██║╚██████╔╝ ██║ ",
  40. "╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ",
  41. ].join('\n'));