update-build-info.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* eslint-disable no-console */
  2. import { exec } from 'child_process';
  3. import fs from 'fs';
  4. import path from 'path';
  5. getLastCommitHash()
  6. .then(hash => writeBuildInfo(hash))
  7. .then(() => {
  8. console.log('Updated build info');
  9. process.exit(0);
  10. })
  11. .catch(err => {
  12. console.error(err);
  13. process.exit(1);
  14. });
  15. function writeBuildInfo(commitHash: string) {
  16. const corePackageJson = require('../../packages/core/package');
  17. const content = {
  18. version: corePackageJson.version,
  19. commit: commitHash,
  20. };
  21. return new Promise<void>((resolve, reject) => {
  22. fs.writeFile(
  23. path.join(__dirname, '../../docs/data/build.json'),
  24. JSON.stringify(content, null, 2),
  25. err => {
  26. if (err) {
  27. reject(err);
  28. }
  29. resolve();
  30. },
  31. );
  32. });
  33. }
  34. function getLastCommitHash() {
  35. return new Promise<string>((resolve, reject) => {
  36. exec(`git log --pretty=format:'%h' -n 1`, (err, out) => {
  37. if (err) {
  38. reject(err);
  39. }
  40. resolve(out.replace(/'/g, ''));
  41. });
  42. });
  43. }