12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- const fs = require('fs')
- const buildPath = process.env.npm_package_remote_local
- const execSync = require('child_process').execSync
- const date = new Date()
- 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 versionStr = `git:${commit}<${branch}>\n作者:${name}<${email}>\n日期:${getDate('-', ':')}\n说明:${message}\n`
- fs.writeFile(`${buildPath}/version.txt`, versionStr, (err) => {
- if (err) console.err('写入失败', err)
- })
- const distName = `打包命名:${buildPath}_${getDate('', '')}_git_${commit}`
- console.info(
- '\x1B[32m%s\x1b[0m',
- [
- distName,
- versionStr,
- '██████╗ ███████╗██████╗ ███████╗ █████╗ ██████╗██╗ ██╗',
- '██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝',
- '██████╔╝█████╗ ██████╔╝███████╗███████║██║ ███╗╚████╔╝ ',
- '██╔═══╝ ██╔══╝ ██╔══██╗╚════██║██╔══██║██║ ██║ ╚██╔╝ ',
- '██║ ███████╗██║ ██║███████║██║ ██║╚██████╔╝ ██║ ',
- '╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ',
- ].join('\n')
- )
|