um-react/scripts/write-version.mjs

15 lines
615 B
JavaScript
Raw Permalink Normal View History

2023-12-28 20:36:29 +00:00
/* eslint-env node */
import { readFileSync, writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { execSync } from 'node:child_process';
2023-12-28 20:36:29 +00:00
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const commitHash = execSync('git rev-parse --short HEAD').toString('utf-8').trim();
2023-12-28 20:36:29 +00:00
const pkgJson = JSON.parse(readFileSync(__dirname + '/../package.json', 'utf-8'));
const pkgVer = `${pkgJson.version ?? 'unknown'}-${commitHash ?? 'unknown'}` + '\n';
2023-12-28 20:36:29 +00:00
writeFileSync(__dirname + '/../dist/version.txt', pkgVer, 'utf-8');