"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/semver/bin/semver" (16 Apr 2018, 4427 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   , coerce = false
   16   , identifier = undefined
   17   , semver = require("../semver")
   18   , reverse = false
   19 
   20 main()
   21 
   22 function main () {
   23   if (!argv.length) return help()
   24   while (argv.length) {
   25     var a = argv.shift()
   26     var i = a.indexOf('=')
   27     if (i !== -1) {
   28       a = a.slice(0, i)
   29       argv.unshift(a.slice(i + 1))
   30     }
   31     switch (a) {
   32       case "-rv": case "-rev": case "--rev": case "--reverse":
   33         reverse = true
   34         break
   35       case "-l": case "--loose":
   36         loose = true
   37         break
   38       case "-v": case "--version":
   39         versions.push(argv.shift())
   40         break
   41       case "-i": case "--inc": case "--increment":
   42         switch (argv[0]) {
   43           case "major": case "minor": case "patch": case "prerelease":
   44           case "premajor": case "preminor": case "prepatch":
   45             inc = argv.shift()
   46             break
   47           default:
   48             inc = "patch"
   49             break
   50         }
   51         break
   52       case "--preid":
   53         identifier = argv.shift()
   54         break
   55       case "-r": case "--range":
   56         range.push(argv.shift())
   57         break
   58       case "-c": case "--coerce":
   59         coerce = true
   60         break
   61       case "-h": case "--help": case "-?":
   62         return help()
   63       default:
   64         versions.push(a)
   65         break
   66     }
   67   }
   68 
   69   versions = versions.map(function (v) {
   70     return coerce ? (semver.coerce(v) || {version: v}).version : v
   71   }).filter(function (v) {
   72     return semver.valid(v)
   73   })
   74   if (!versions.length) return fail()
   75   if (inc && (versions.length !== 1 || range.length))
   76     return failInc()
   77 
   78   for (var i = 0, l = range.length; i < l ; i ++) {
   79     versions = versions.filter(function (v) {
   80       return semver.satisfies(v, range[i], loose)
   81     })
   82     if (!versions.length) return fail()
   83   }
   84   return success(versions)
   85 }
   86 
   87 function failInc () {
   88   console.error("--inc can only be used on a single version with no range")
   89   fail()
   90 }
   91 
   92 function fail () { process.exit(1) }
   93 
   94 function success () {
   95   var compare = reverse ? "rcompare" : "compare"
   96   versions.sort(function (a, b) {
   97     return semver[compare](a, b, loose)
   98   }).map(function (v) {
   99     return semver.clean(v, loose)
  100   }).map(function (v) {
  101     return inc ? semver.inc(v, inc, loose, identifier) : v
  102   }).forEach(function (v,i,_) { console.log(v) })
  103 }
  104 
  105 function help () {
  106   console.log(["SemVer " + version
  107               ,""
  108               ,"A JavaScript implementation of the http://semver.org/ specification"
  109               ,"Copyright Isaac Z. Schlueter"
  110               ,""
  111               ,"Usage: semver [options] <version> [<version> [...]]"
  112               ,"Prints valid versions sorted by SemVer precedence"
  113               ,""
  114               ,"Options:"
  115               ,"-r --range <range>"
  116               ,"        Print versions that match the specified range."
  117               ,""
  118               ,"-i --increment [<level>]"
  119               ,"        Increment a version by the specified level.  Level can"
  120               ,"        be one of: major, minor, patch, premajor, preminor,"
  121               ,"        prepatch, or prerelease.  Default level is 'patch'."
  122               ,"        Only one version may be specified."
  123               ,""
  124               ,"--preid <identifier>"
  125               ,"        Identifier to be used to prefix premajor, preminor,"
  126               ,"        prepatch or prerelease version increments."
  127               ,""
  128               ,"-l --loose"
  129               ,"        Interpret versions and ranges loosely"
  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 }