Explorar o código

修改环境变量文件目录

yunxing %!s(int64=4) %!d(string=hai) anos
pai
achega
c88bcc23b6
Modificáronse 7 ficheiros con 53 adicións e 49 borrados
  1. 0 0
      .env.development
  2. 0 0
      .env.production
  3. 0 0
      .env.test
  4. 1 1
      .gitignore
  5. 1 1
      package.json
  6. 51 47
      version.js
  7. 0 0
      version.txt

src/.env.development → .env.development


src/.env.production → .env.production


src/.env.test → .env.test


+ 1 - 1
.gitignore

@@ -2,7 +2,7 @@
 node_modules
 /wandaBmGuideH5
 /dist
-version.txt
+
 
 # local env files
 .env.local

+ 1 - 1
package.json

@@ -4,7 +4,7 @@
   "private": true,
   "scripts": {
     "serve": "vue-cli-service serve",
-    "build": "vue-cli-service build --mode production & node version",
+    "build": "vue-cli-service build --mode production",
     "test":"vue-cli-service build --mode test"
   },
   "dependencies": {

+ 51 - 47
version.js

@@ -1,51 +1,55 @@
-/**定义模块和变量**/
-const exec = require('child_process').exec; //异步子进程
-const execSync = require('child_process').execSync; //同步子进程
-const fs = require('fs'); //文件读取模块
-const versionPath = 'version.txt'; //version路径
-const buildPath = 'wandaBmGuideH5'; //打包的路径
-const autoPush = true; //写入版本信息之后是否自动提交git上
-const autoText = "node自动提交的版本信息"; //自动提交时的说明
-const commit = execSync('git show -s --format=%H').toString().trim(); //当前提交的版本号
+/** 自动记录版本信息**/
+const fs = require('fs')
+const buildPath = 'wandaBmGuideH5' //放置 version.txt的路径
+const execSync = require('child_process').execSync //同步子进程
+const date = new Date() // Date对象
 
-/**程序开始**/
-var versionStr = ""; //版本信息字符串
-
-// 如果versionPath存在,将先读取里边的版本信息
-if (fs.existsSync(versionPath)) {
-    versionStr = fs.readFileSync(versionPath).toString() + '\n';
-}
-
-// 根据版本信息是已存在commit,进行不同处理
-if (!autoPush && versionStr.indexOf(commit) != -1) {
-    console.warn('\x1B[33m%s\x1b[0m', 'warming: 当前的git版本数据已经存在了!\n')
-} else if (execSync('git show -s --format=%s').toString().trim() == autoText) {
-    console.warn('\x1B[33m%s\x1b[0m', `warming: 读取最新的git说明为(${autoText})!\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 "${autoText}"`);
-        execSync(`git push origin ${execSync('git rev-parse --abbrev-ref HEAD').toString().trim()}`);
-    }
+// 获取时间函数
+const getDate = (df, tf) => {
+    const dArr = [
+        date.getFullYear(),
+        date.getMonth() > 9 ? String(date.getMonth() + 1) : String('0' + (date.getMonth() + 1)),
+        date.getDate() > 9 ? String(date.getDate()) : String('0' + date.getDate()),
+    ]
+    const tArr = [date.getHours(), date.getMinutes() > 9 ? String(date.getMinutes() + 1) : String('0' + date.getMinutes())]
+    return `${dArr.join(df)}${tf ? ' ' : ''}${tArr.join(tf)}`
 }
+//写入最新的版本信息
+const branch = execSync('git symbolic-ref --short -q HEAD')
+    .toString()
+    .trim() // 分支
+const commit = execSync('git show -s --format=%h')
+    .toString()
+    .trim() //版本号
+const message = execSync('git show -s --format=%s')
+    .toString()
+    .trim() //说明
+const name = execSync('git show -s --format=%cn')
+    .toString()
+    .trim() //姓名
+const email = execSync('git show -s --format=%ce')
+    .toString()
+    .trim() //邮箱
+//const date = execSync('git show -s --format=%cd').toString().trim(); //日期
+const versionStr = `git:${commit}<${branch}>\n作者:${name}<${email}>\n日期:${getDate('-', ':')}\n说明:${message}\n`
+fs.writeFile(`${buildPath}/version.txt`, versionStr, (err) => {
+    if (err) console.err('写入失败', err)
+})
 
-// 将version文件移植到打包文件中
-if (fs.existsSync(buildPath)) {
-    fs.writeFileSync(`${buildPath}/${versionPath}`, fs.readFileSync(versionPath));
-}
+// 打包文件命名
+const distName = `打包命名:${buildPath}_${getDate('', '')}_git_${commit}`
 
-// 程序执行结束
-console.info('\x1B[32m%s\x1b[0m', [
-    "██████╗ ███████╗██████╗ ███████╗ █████╗  ██████╗██╗   ██╗",
-    "██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝",
-    "██████╔╝█████╗  ██████╔╝███████╗███████║██║  ███╗╚████╔╝ ",
-    "██╔═══╝ ██╔══╝  ██╔══██╗╚════██║██╔══██║██║   ██║ ╚██╔╝  ",
-    "██║     ███████╗██║  ██║███████║██║  ██║╚██████╔╝  ██║   ",
-    "╚═╝     ╚══════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝ ╚═════╝   ╚═╝   ",
-].join('\n'));
+// 程序运行结束
+console.info(
+    '\x1B[32m%s\x1b[0m',
+    [
+        distName,
+        versionStr,
+        '██████╗ ███████╗██████╗ ███████╗ █████╗  ██████╗██╗   ██╗',
+        '██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝',
+        '██████╔╝█████╗  ██████╔╝███████╗███████║██║  ███╗╚████╔╝ ',
+        '██╔═══╝ ██╔══╝  ██╔══██╗╚════██║██╔══██║██║   ██║ ╚██╔╝  ',
+        '██║     ███████╗██║  ██║███████║██║  ██║╚██████╔╝  ██║   ',
+        '╚═╝     ╚══════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝ ╚═════╝   ╚═╝   ',
+    ].join('\n')
+)

+ 0 - 0
version.txt