update-contributors.js 1.1 KB

12345678910111213141516171819202122232425
  1. // From https://github.com/karma-runner/karma/blob/master/tools/update-contributors.js
  2. // When modifying this file also modify upstream.
  3. const { execSync } = require('child_process')
  4. const { readFileSync, writeFileSync } = require('fs')
  5. const { resolve } = require('path')
  6. const prepare = async (pluginConfig, { logger }) => {
  7. // Example output:
  8. // 1042 Vojta Jina <vojta.jina@gmail.com>
  9. // 412 Friedel Ziegelmayer <friedel.ziegelmayer@gmail.com>
  10. // 206 dignifiedquire <friedel.ziegelmayer@gmail.com>
  11. // 139 johnjbarton <johnjbarton@johnjbarton.com>
  12. const stdout = execSync('git log --pretty=short | git shortlog -nse', { encoding: 'utf8' })
  13. const pkgPath = resolve(__dirname, '..', 'package.json')
  14. const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
  15. // First line is already included as author field. Last line is dropped as it is an empty line.
  16. pkg.contributors = stdout.split('\n').slice(1, -1).map((line) => line.replace(/^[\W\d]+/, ''))
  17. writeFileSync(pkgPath, JSON.stringify(pkg, undefined, ' ') + '\n', 'utf8')
  18. logger.info('Updated contributors list.')
  19. }
  20. module.exports = { prepare }