Append commit information at build time

This commit is contained in:
Pig Fang 2019-05-04 22:01:08 +08:00
parent 4e5276ca87
commit 7d37bc6cb1
5 changed files with 19 additions and 1 deletions

View File

@ -31,6 +31,7 @@ class AppServiceProvider extends ServiceProvider
Event::listen(Events\RenderingHeader::class, function ($event) { Event::listen(Events\RenderingHeader::class, function ($event) {
$blessing = [ $blessing = [
'version' => config('app.version'), 'version' => config('app.version'),
'commit' => app('webpack')->commit,
'locale' => config('app.locale'), 'locale' => config('app.locale'),
'fallback_locale' => config('app.fallback_locale'), 'fallback_locale' => config('app.fallback_locale'),
'base_url' => url('/'), 'base_url' => url('/'),

View File

@ -11,7 +11,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "webpack-dev-server", "dev": "webpack-dev-server",
"build": "rimraf public/app && webpack --mode=production -p", "build": "rimraf public/app && webpack --mode=production -p && node --experimental-modules scripts/commitish.mjs",
"lint": "eslint --ext=.js,.vue,.ts -f=beauty .", "lint": "eslint --ext=.js,.vue,.ts -f=beauty .",
"test": "tsc -p . && jest", "test": "tsc -p . && jest",
"codecov": "codecov -F js" "codecov": "codecov -F js"

View File

@ -5,6 +5,7 @@
## Tweaked ## Tweaked
- Tweaked UI text. - Tweaked UI text.
- Appended commit information at build time.
## Fixed ## Fixed

View File

@ -5,6 +5,7 @@
## 调整 ## 调整
- 调整部分 UI 文本 - 调整部分 UI 文本
- 构建时附加 commit 信息
## 修复 ## 修复

15
scripts/commitish.mjs Normal file
View File

@ -0,0 +1,15 @@
import childProcess from 'child_process'
import util from 'util'
import fs from 'fs'
(async () => {
const [manifest, commit] = await Promise.all([
util
.promisify(fs.readFile)('./public/app/manifest.json', 'utf8')
.then(JSON.parse),
util.promisify(childProcess.exec)('git log --pretty=%H -1').then(value => value.stdout.trim()),
])
manifest.commit = commit
await util.promisify(fs.writeFile)('./public/app/manifest.json', JSON.stringify(manifest, null, 2))
})()