From 1ef1db30ab308dd0c5fe3a478c8416956d145369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Thu, 28 Dec 2023 20:36:29 +0000 Subject: [PATCH] build: include version.txt in dist --- package.json | 2 +- scripts/write-version.mjs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 scripts/write-version.mjs diff --git a/package.json b/package.json index f4168d4..2771ae5 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "start": "vite", - "build": "tsc -p tsconfig.prod.json && vite build", + "build": "tsc -p tsconfig.prod.json && vite build && node scripts/write-version.mjs", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "format": "prettier -w .", "test": "vitest run", diff --git a/scripts/write-version.mjs b/scripts/write-version.mjs new file mode 100644 index 0000000..5efa414 --- /dev/null +++ b/scripts/write-version.mjs @@ -0,0 +1,11 @@ +/* eslint-env node */ +import { readFileSync, writeFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const pkgJson = JSON.parse(readFileSync(__dirname + '/../package.json', 'utf-8')); +const pkgVer = (pkgJson.version ?? 'unknown') + '\n'; +writeFileSync(__dirname + '/../dist/version.txt', pkgVer, 'utf-8');