write-version.mjs 615 B

123456789101112131415
  1. /* eslint-env node */
  2. import { readFileSync, writeFileSync } from 'node:fs';
  3. import { fileURLToPath } from 'node:url';
  4. import { dirname } from 'node:path';
  5. import { execSync } from 'node:child_process';
  6. const __filename = fileURLToPath(import.meta.url);
  7. const __dirname = dirname(__filename);
  8. const commitHash = execSync('git rev-parse --short HEAD').toString('utf-8').trim();
  9. const pkgJson = JSON.parse(readFileSync(__dirname + '/../package.json', 'utf-8'));
  10. const pkgVer = `${pkgJson.version ?? 'unknown'}-${commitHash ?? 'unknown'}` + '\n';
  11. writeFileSync(__dirname + '/../dist/version.txt', pkgVer, 'utf-8');