Browse Source

添加版本日志

pull/75/head
liwei 3 years ago
parent
commit
4cf59870ea
3 changed files with 56 additions and 2 deletions
  1. +2
    -2
      package.json
  2. +48
    -0
      version.js
  3. +6
    -0
      version.txt

+ 2
- 2
package.json View File

@ -6,8 +6,8 @@
"license": "MIT",
"scripts": {
"dev": "vue-cli-service serve --open",
"build:prod": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging",
"build:prod": "vue-cli-service build --mode production --dest dist&&node version.js",
"build:stage": "vue-cli-service build --mode staging --dest dist&&node version.js",
"preview": "node build/index.js --preview",
"lint": "eslint --ext .js,.vue src",
"test:unit": "jest --clearCache && vue-cli-service test:unit",


+ 48
- 0
version.js View File

@ -0,0 +1,48 @@
/**定义模块和变量**/
const exec = require('child_process').exec; //异步子进程
const execSync = require('child_process').execSync; //同步子进程
const fs = require('fs'); //文件读取模块
const versionPath = 'version.txt'; //version路径
const buildPath = 'dist'; //打包的路径
const autoPush = true; //写入版本信息之后是否自动提交git上
const commit = execSync('git show -s --format=%H').toString().trim(); //当前提交的版本号
/**程序开始**/
var versionStr = ""; //版本信息字符串
// 如果versionPath存在,将先读取里边的版本信息
if (fs.existsSync(versionPath)) {
versionStr = fs.readFileSync(versionPath).toString() + '\n';
}
// 根据版本信息是已存在commit,进行不同处理
if (versionStr.indexOf(commit) != -1) {
console.warn('\x1B[33m%s\x1b[0m', 'warming: 当前的git版本数据已经存在了!\n')
} else {
let name = execSync('git show -s --format=%cn').toString().trim(); //姓名
let email = execSync('git show -s --format=%ce').toString().trim(); //邮箱
let date = new Date(execSync('git show -s --format=%cd').toString()); //日期
let message = execSync('git show -s --format=%s').toString().trim(); //说明
versionStr = `git:${commit}\n作者:${name}<${email}>\n日期:${date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()}\n说明:${message}\n${new Array(80).join('*')}\n${versionStr}`;
fs.writeFileSync(versionPath, versionStr);
// 写入版本信息之后,自动将版本信息提交到当前分支的git上
if (autoPush) {
execSync(`git commit ${versionPath} -m 自动提交版本信息`);
execSync(`git push origin ${execSync('git rev-parse --abbrev-ref HEAD').toString().trim()}`);
}
}
// 将version文件移植到打包文件中
if (fs.existsSync(buildPath)) {
fs.writeFileSync(`${buildPath}/${versionPath}`, fs.readFileSync(versionPath));
}
// 程序执行结束
console.info('\x1B[32m%s\x1b[0m', [
"██████╗ ███████╗██████╗ ███████╗ █████╗ ██████╗██╗ ██╗",
"██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝",
"██████╔╝█████╗ ██████╔╝███████╗███████║██║ ███╗╚████╔╝ ",
"██╔═══╝ ██╔══╝ ██╔══██╗╚════██║██╔══██║██║ ██║ ╚██╔╝ ",
"██║ ███████╗██║ ██║███████║██║ ██║╚██████╔╝ ██║ ",
"╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ",
].join('\n'));

+ 6
- 0
version.txt View File

@ -0,0 +1,6 @@
git:1a68481bc33098f2a7f571c0730cb462c6a02ca3
作者:Liwei<wei.li@le-it.com.cn>
日期:2021-6-7 9:53
说明:Merge pull request '修改甘特图样式' (#68) from feature_supplier into develop
*******************************************************************************

Loading…
Cancel
Save