diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-06-11 21:02:02 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-06-11 21:02:02 +0300 |
| commit | e4020e8dfefc7df71114b14195e331fb7fb5bf83 (patch) | |
| tree | 48ef7b3d87b552bdcca966afaa6f5639eaf5e33d /build.js | |
| parent | 24187f28d3d8f5af06a56b89a74e4be7a7b0573d (diff) | |
| download | the-epube-e4020e8dfefc7df71114b14195e331fb7fb5bf83.tar.gz the-epube-e4020e8dfefc7df71114b14195e331fb7fb5bf83.tar.xz | |
add cosmetic git-based version to the UI, set on build
Diffstat (limited to 'build.js')
| -rw-r--r-- | build.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/build.js b/build.js index 624d71b..4c3b0da 100644 --- a/build.js +++ b/build.js @@ -6,6 +6,21 @@ import { writeFile } from 'fs/promises'; import less from 'less'; import chokidar from 'chokidar'; import path from 'path'; +import { execSync } from 'child_process'; + +function getBuildVersion() { + try { + const output = execSync('git --no-pager log --pretty=%ct-%h -n1 HEAD', { encoding: 'utf8' }).trim(); + const [ts, shortHash] = output.split('-'); + const commitTs = parseInt(ts, 10); + const date = new Date(commitTs * 1000); + const yy = date.getUTCFullYear().toString().slice(-2); + const mm = String(date.getUTCMonth() + 1).padStart(2, '0'); + return `v${yy}.${mm}-${shortHash}`; + } catch { + return 'v00.00-unknown'; + } +} const LIB_FILES = [ 'lib/bootstrap/v3/js/jquery.js', @@ -65,6 +80,9 @@ async function buildApp() { const content = JS_FILES.map(f => readFileSync(f, 'utf8')).join('\n'); const CACHE_VERSION = `v${Date.now()}`; + const BUILD_VERSION = getBuildVersion(); + + console.log(`build version: ${BUILD_VERSION}`); await esbuild.build({ stdin: { contents: content, resolveDir: process.cwd(), loader: 'js' }, @@ -73,6 +91,7 @@ async function buildApp() { outfile: 'dist/app.min.js', define: { 'BUILD_CACHE_VERSION': JSON.stringify(CACHE_VERSION), + 'BUILD_VERSION': JSON.stringify(BUILD_VERSION), } }); @@ -102,6 +121,7 @@ async function buildApp() { define: { 'BUILD_CACHE_VERSION': JSON.stringify(CACHE_VERSION), 'BUILD_MANIFEST_ASSETS': JSON.stringify(MANIFEST_ASSETS), + 'BUILD_VERSION': JSON.stringify(BUILD_VERSION), } }); |
