make-new-versions-table 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env node
  2. /**
  3. * Generate a version table from the most recent "Release" commit,
  4. * for use in changelogs.
  5. *
  6. * Usage:
  7. * $ ./bin/make-new-versions-table
  8. */
  9. const { execSync } = require('child_process')
  10. const logStdout = execSync('git log --grep \'Release$\' -1 --pretty=oneline --no-decorate')
  11. let match = /^([0-9a-f]+) .*?$/m.exec(logStdout.toString())
  12. if (!match) {
  13. console.error('Could not read Release commit')
  14. process.exit(1)
  15. }
  16. const commit = match[1]
  17. const tagStdout = execSync(`git tag --list --contains ${commit}`)
  18. const tags = tagStdout.toString()
  19. const rx = /([@/\w-]+)@(\d+\.\d+\.\d+)/g
  20. const versions = []
  21. let m
  22. while ((m = rx.exec(tags))) {
  23. const [, pkg, version] = m
  24. versions.push({ pkg, version })
  25. }
  26. const mid = Math.ceil(versions.length / 2)
  27. let table = [
  28. '| Package | Version | Package | Version |',
  29. '|-|-|-|-|'
  30. ]
  31. for (let i = 0; i < mid; i++) {
  32. const left = versions[i] || { pkg: '-', version: '-' }
  33. const right = versions[i + mid] || { pkg: '-', version: '-' }
  34. table.push(`| ${left.pkg} | ${left.version} | ${right.pkg} | ${right.version} |`)
  35. }
  36. console.log(table.join('\n'))