From 7d37bc6cb1a859b2d1ea643eea1ad22f72b2658b Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sat, 4 May 2019 22:01:08 +0800 Subject: [PATCH] Append commit information at build time --- app/Providers/AppServiceProvider.php | 1 + package.json | 2 +- resources/misc/changelogs/en/4.1.4.md | 1 + resources/misc/changelogs/zh_CN/4.1.4.md | 1 + scripts/commitish.mjs | 15 +++++++++++++++ 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 scripts/commitish.mjs diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index d473dbbb..51417a35 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -31,6 +31,7 @@ class AppServiceProvider extends ServiceProvider Event::listen(Events\RenderingHeader::class, function ($event) { $blessing = [ 'version' => config('app.version'), + 'commit' => app('webpack')->commit, 'locale' => config('app.locale'), 'fallback_locale' => config('app.fallback_locale'), 'base_url' => url('/'), diff --git a/package.json b/package.json index 4eca7776..5b465b26 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "private": true, "scripts": { "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 .", "test": "tsc -p . && jest", "codecov": "codecov -F js" diff --git a/resources/misc/changelogs/en/4.1.4.md b/resources/misc/changelogs/en/4.1.4.md index 87c0a8b4..66dd5757 100644 --- a/resources/misc/changelogs/en/4.1.4.md +++ b/resources/misc/changelogs/en/4.1.4.md @@ -5,6 +5,7 @@ ## Tweaked - Tweaked UI text. +- Appended commit information at build time. ## Fixed diff --git a/resources/misc/changelogs/zh_CN/4.1.4.md b/resources/misc/changelogs/zh_CN/4.1.4.md index 08d197cf..fce69523 100644 --- a/resources/misc/changelogs/zh_CN/4.1.4.md +++ b/resources/misc/changelogs/zh_CN/4.1.4.md @@ -5,6 +5,7 @@ ## 调整 - 调整部分 UI 文本 +- 构建时附加 commit 信息 ## 修复 diff --git a/scripts/commitish.mjs b/scripts/commitish.mjs new file mode 100644 index 00000000..546b3782 --- /dev/null +++ b/scripts/commitish.mjs @@ -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)) +})()