build: include version.txt in dist

This commit is contained in:
Jixun Wu 2023-12-28 20:36:29 +00:00
parent 8df421de64
commit 8f2d306835
2 changed files with 12 additions and 1 deletions

View File

@ -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",

11
scripts/write-version.mjs Normal file
View File

@ -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');