Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cli.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env node
  2. var fs = require('fs')
  3. var browserslist = require('./')
  4. var updateDb = require('./update-db')
  5. var pkg = require('./package.json')
  6. var args = process.argv.slice(2)
  7. var USAGE = 'Usage:\n' +
  8. ' npx browserslist\n' +
  9. ' npx browserslist "QUERIES"\n' +
  10. ' npx browserslist --json "QUERIES"\n' +
  11. ' npx browserslist --config="path/to/browserlist/file"\n' +
  12. ' npx browserslist --coverage "QUERIES"\n' +
  13. ' npx browserslist --coverage=US "QUERIES"\n' +
  14. ' npx browserslist --coverage=US,RU,global "QUERIES"\n' +
  15. ' npx browserslist --env="environment name defined in config"\n' +
  16. ' npx browserslist --stats="path/to/browserlist/stats/file"\n' +
  17. ' npx browserslist --mobile-to-desktop\n' +
  18. ' npx browserslist --update-db'
  19. function isArg (arg) {
  20. return args.some(function (str) {
  21. return str === arg || str.indexOf(arg + '=') === 0
  22. })
  23. }
  24. function error (msg) {
  25. process.stderr.write('browserslist: ' + msg + '\n')
  26. process.exit(1)
  27. }
  28. if (isArg('--help') || isArg('-h')) {
  29. process.stdout.write(pkg.description + '.\n\n' + USAGE + '\n')
  30. } else if (isArg('--version') || isArg('-v')) {
  31. process.stdout.write('browserslist ' + pkg.version + '\n')
  32. } else if (isArg('--update-db')) {
  33. updateDb(function (str) {
  34. process.stdout.write(str)
  35. })
  36. } else {
  37. var mode = 'browsers'
  38. var opts = { }
  39. var queries
  40. var areas
  41. for (var i = 0; i < args.length; i++) {
  42. if (args[i][0] !== '-') {
  43. queries = args[i].replace(/^["']|["']$/g, '')
  44. continue
  45. }
  46. var arg = args[i].split('=')
  47. var name = arg[0]
  48. var value = arg[1]
  49. if (value) value = value.replace(/^["']|["']$/g, '')
  50. if (name === '--config' || name === '-b') {
  51. opts.config = value
  52. } else if (name === '--env' || name === '-e') {
  53. opts.env = value
  54. } else if (name === '--stats' || name === '-s') {
  55. opts.stats = value
  56. } else if (name === '--coverage' || name === '-c') {
  57. if (mode !== 'json') mode = 'coverage'
  58. if (value) {
  59. areas = value.split(',')
  60. } else {
  61. areas = ['global']
  62. }
  63. } else if (name === '--json') {
  64. mode = 'json'
  65. } else if (name === '--mobile-to-desktop') {
  66. opts.mobileToDesktop = true
  67. } else {
  68. error('Unknown arguments ' + args[i] + '.\n\n' + USAGE)
  69. }
  70. }
  71. var browsers
  72. try {
  73. browsers = browserslist(queries, opts)
  74. } catch (e) {
  75. if (e.name === 'BrowserslistError') {
  76. error(e.message)
  77. } else {
  78. throw e
  79. }
  80. }
  81. var coverage
  82. if (mode === 'browsers') {
  83. browsers.forEach(function (browser) {
  84. process.stdout.write(browser + '\n')
  85. })
  86. } else if (areas) {
  87. coverage = areas.map(function (area) {
  88. var stats
  89. if (area !== 'global') {
  90. stats = area
  91. } else if (opts.stats) {
  92. stats = JSON.parse(fs.readFileSync(opts.stats))
  93. }
  94. var result = browserslist.coverage(browsers, stats)
  95. var round = Math.round(result * 100) / 100.0
  96. return [area, round]
  97. })
  98. if (mode === 'coverage') {
  99. var prefix = 'These browsers account for '
  100. process.stdout.write(prefix)
  101. coverage.forEach(function (data, index) {
  102. var area = data[0]
  103. var round = data[1]
  104. var end = 'globally'
  105. if (area && area !== 'global') {
  106. end = 'in the ' + area.toUpperCase()
  107. } else if (opts.stats) {
  108. end = 'in custom statistics'
  109. }
  110. if (index !== 0) {
  111. process.stdout.write(prefix.replace(/./g, ' '))
  112. }
  113. process.stdout.write(round + '% of all users ' + end + '\n')
  114. })
  115. }
  116. }
  117. if (mode === 'json') {
  118. var data = { browsers: browsers }
  119. if (coverage) {
  120. data.coverage = coverage.reduce(function (object, j) {
  121. object[j[0]] = j[1]
  122. return object
  123. }, { })
  124. }
  125. process.stdout.write(JSON.stringify(data, null, ' ') + '\n')
  126. }
  127. }