Ohm-Management - Projektarbeit B-ME
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.

semver 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env node
  2. // Standalone semver comparison program.
  3. // Exits successfully and prints matching version(s) if
  4. // any supplied version is valid and passes all tests.
  5. var argv = process.argv.slice(2)
  6. , versions = []
  7. , range = []
  8. , gt = []
  9. , lt = []
  10. , eq = []
  11. , inc = null
  12. , version = require("../package.json").version
  13. , loose = false
  14. , includePrerelease = false
  15. , coerce = false
  16. , identifier = undefined
  17. , semver = require("../semver")
  18. , reverse = false
  19. , options = {}
  20. main()
  21. function main () {
  22. if (!argv.length) return help()
  23. while (argv.length) {
  24. var a = argv.shift()
  25. var i = a.indexOf('=')
  26. if (i !== -1) {
  27. a = a.slice(0, i)
  28. argv.unshift(a.slice(i + 1))
  29. }
  30. switch (a) {
  31. case "-rv": case "-rev": case "--rev": case "--reverse":
  32. reverse = true
  33. break
  34. case "-l": case "--loose":
  35. loose = true
  36. break
  37. case "-p": case "--include-prerelease":
  38. includePrerelease = true
  39. break
  40. case "-v": case "--version":
  41. versions.push(argv.shift())
  42. break
  43. case "-i": case "--inc": case "--increment":
  44. switch (argv[0]) {
  45. case "major": case "minor": case "patch": case "prerelease":
  46. case "premajor": case "preminor": case "prepatch":
  47. inc = argv.shift()
  48. break
  49. default:
  50. inc = "patch"
  51. break
  52. }
  53. break
  54. case "--preid":
  55. identifier = argv.shift()
  56. break
  57. case "-r": case "--range":
  58. range.push(argv.shift())
  59. break
  60. case "-c": case "--coerce":
  61. coerce = true
  62. break
  63. case "-h": case "--help": case "-?":
  64. return help()
  65. default:
  66. versions.push(a)
  67. break
  68. }
  69. }
  70. var options = { loose: loose, includePrerelease: includePrerelease }
  71. versions = versions.map(function (v) {
  72. return coerce ? (semver.coerce(v) || {version: v}).version : v
  73. }).filter(function (v) {
  74. return semver.valid(v)
  75. })
  76. if (!versions.length) return fail()
  77. if (inc && (versions.length !== 1 || range.length))
  78. return failInc()
  79. for (var i = 0, l = range.length; i < l ; i ++) {
  80. versions = versions.filter(function (v) {
  81. return semver.satisfies(v, range[i], options)
  82. })
  83. if (!versions.length) return fail()
  84. }
  85. return success(versions)
  86. }
  87. function failInc () {
  88. console.error("--inc can only be used on a single version with no range")
  89. fail()
  90. }
  91. function fail () { process.exit(1) }
  92. function success () {
  93. var compare = reverse ? "rcompare" : "compare"
  94. versions.sort(function (a, b) {
  95. return semver[compare](a, b, options)
  96. }).map(function (v) {
  97. return semver.clean(v, options)
  98. }).map(function (v) {
  99. return inc ? semver.inc(v, inc, options, identifier) : v
  100. }).forEach(function (v,i,_) { console.log(v) })
  101. }
  102. function help () {
  103. console.log(["SemVer " + version
  104. ,""
  105. ,"A JavaScript implementation of the http://semver.org/ specification"
  106. ,"Copyright Isaac Z. Schlueter"
  107. ,""
  108. ,"Usage: semver [options] <version> [<version> [...]]"
  109. ,"Prints valid versions sorted by SemVer precedence"
  110. ,""
  111. ,"Options:"
  112. ,"-r --range <range>"
  113. ," Print versions that match the specified range."
  114. ,""
  115. ,"-i --increment [<level>]"
  116. ," Increment a version by the specified level. Level can"
  117. ," be one of: major, minor, patch, premajor, preminor,"
  118. ," prepatch, or prerelease. Default level is 'patch'."
  119. ," Only one version may be specified."
  120. ,""
  121. ,"--preid <identifier>"
  122. ," Identifier to be used to prefix premajor, preminor,"
  123. ," prepatch or prerelease version increments."
  124. ,""
  125. ,"-l --loose"
  126. ," Interpret versions and ranges loosely"
  127. ,""
  128. ,"-p --include-prerelease"
  129. ," Always include prerelease versions in range matching"
  130. ,""
  131. ,"-c --coerce"
  132. ," Coerce a string into SemVer if possible"
  133. ," (does not imply --loose)"
  134. ,""
  135. ,"Program exits successfully if any valid version satisfies"
  136. ,"all supplied ranges, and prints all satisfying versions."
  137. ,""
  138. ,"If no satisfying versions are found, then exits failure."
  139. ,""
  140. ,"Versions are printed in ascending order, so supplying"
  141. ,"multiple versions to the utility will just sort them."
  142. ].join("\n"))
  143. }