cli.js 912 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env node
  2. let { readFileSync } = require('fs')
  3. let { join } = require('path')
  4. require('./check-npm-version')
  5. let updateDb = require('./')
  6. const ROOT = __dirname
  7. function getPackage() {
  8. return JSON.parse(readFileSync(join(ROOT, 'package.json')))
  9. }
  10. let args = process.argv.slice(2)
  11. let USAGE = 'Usage:\n npx update-browserslist-db\n'
  12. function isArg(arg) {
  13. return args.some(i => i === arg)
  14. }
  15. function error(msg) {
  16. process.stderr.write('update-browserslist-db: ' + msg + '\n')
  17. process.exit(1)
  18. }
  19. if (isArg('--help') || isArg('-h')) {
  20. process.stdout.write(getPackage().description + '.\n\n' + USAGE + '\n')
  21. } else if (isArg('--version') || isArg('-v')) {
  22. process.stdout.write('browserslist-lint ' + getPackage().version + '\n')
  23. } else {
  24. try {
  25. updateDb()
  26. } catch (e) {
  27. if (e.name === 'BrowserslistUpdateError') {
  28. error(e.message)
  29. } else {
  30. throw e
  31. }
  32. }
  33. }