"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/semver/bin/semver" (11 Apr 2017, 4092 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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