Welcome to mirror list, hosted at ThFree Co, Russian Federation.

semver.js « bin - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5261de134fc44283c272161205a112a4bdf0271e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Standalone semver comparison program.
// Exits successfully and prints matching version(s) if
// any supplied version is valid and passes all tests.

var argv = process.argv.slice(2)
  , versions = []
  , range = []
  , gt = []
  , lt = []
  , eq = []
  , semver = require("../lib/utils/semver")

main()

function main () {
  if (!argv.length) return help()
  while (argv.length) {
    switch (argv.shift()) {
      case "-v": case "--version":
        versions.push(argv.shift())
        break
      case "-r" : case "--range":
        range.push(argv.shift())
        break
      default:
        return help()
    }
  }
  versions = versions.filter(semver.valid)
  for (var i = 0, l = range.length; i < l ; i ++) {
    versions = versions.filter(function (v) {
      return semver.satisfies(v, range[i])
    })
    if (!versions.length) return fail()
  }
  return success(versions)
}

function fail () { process.exit(1) }

function success () {
  versions.sort(semver.compare).forEach(function (v,i,_) { console.log(v) })
}

function help () {
  console.log(["Usage: semver -v <version> [-r <range>]"
              ,"Test if version(s) satisfy the supplied range(s),"
              ,"and sort them."
              ,""
              ,"Multiple versions or ranges may be supplied."
              ,""
              ,"Program exits successfully if all versions satisfy all"
              ,"ranges and are valid, and prints all satisfying versions."
              ,"If no versions are valid, or ranges are not satisfied,"
              ,"then exits failure."
              ,""
              ,"Versions are printed in ascending order, so supplying"
              ,"multiple versions to the utility will just sort them."
              ].join("\n"))
}