source: trip-planner-front/node_modules/semver/bin/semver.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[6a3a178]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
6const argv = process.argv.slice(2)
7
8let versions = []
9
10const range = []
11
12let inc = null
13
14const version = require('../package.json').version
15
16let loose = false
17
18let includePrerelease = false
19
20let coerce = false
21
22let rtl = false
23
24let identifier
25
26const semver = require('../')
27
28let reverse = false
29
30const options = {}
31
32const main = () => {
33 if (!argv.length) return help()
34 while (argv.length) {
35 let a = argv.shift()
36 const indexOfEqualSign = a.indexOf('=')
37 if (indexOfEqualSign !== -1) {
38 a = a.slice(0, indexOfEqualSign)
39 argv.unshift(a.slice(indexOfEqualSign + 1))
40 }
41 switch (a) {
42 case '-rv': case '-rev': case '--rev': case '--reverse':
43 reverse = true
44 break
45 case '-l': case '--loose':
46 loose = true
47 break
48 case '-p': case '--include-prerelease':
49 includePrerelease = true
50 break
51 case '-v': case '--version':
52 versions.push(argv.shift())
53 break
54 case '-i': case '--inc': case '--increment':
55 switch (argv[0]) {
56 case 'major': case 'minor': case 'patch': case 'prerelease':
57 case 'premajor': case 'preminor': case 'prepatch':
58 inc = argv.shift()
59 break
60 default:
61 inc = 'patch'
62 break
63 }
64 break
65 case '--preid':
66 identifier = argv.shift()
67 break
68 case '-r': case '--range':
69 range.push(argv.shift())
70 break
71 case '-c': case '--coerce':
72 coerce = true
73 break
74 case '--rtl':
75 rtl = true
76 break
77 case '--ltr':
78 rtl = false
79 break
80 case '-h': case '--help': case '-?':
81 return help()
82 default:
83 versions.push(a)
84 break
85 }
86 }
87
88 const options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
89
90 versions = versions.map((v) => {
91 return coerce ? (semver.coerce(v, options) || { version: v }).version : v
92 }).filter((v) => {
93 return semver.valid(v)
94 })
95 if (!versions.length) return fail()
96 if (inc && (versions.length !== 1 || range.length)) { return failInc() }
97
98 for (let i = 0, l = range.length; i < l; i++) {
99 versions = versions.filter((v) => {
100 return semver.satisfies(v, range[i], options)
101 })
102 if (!versions.length) return fail()
103 }
104 return success(versions)
105}
106
107
108const failInc = () => {
109 console.error('--inc can only be used on a single version with no range')
110 fail()
111}
112
113const fail = () => process.exit(1)
114
115const success = () => {
116 const compare = reverse ? 'rcompare' : 'compare'
117 versions.sort((a, b) => {
118 return semver[compare](a, b, options)
119 }).map((v) => {
120 return semver.clean(v, options)
121 }).map((v) => {
122 return inc ? semver.inc(v, inc, options, identifier) : v
123 }).forEach((v, i, _) => { console.log(v) })
124}
125
126const help = () => console.log(
127`SemVer ${version}
128
129A JavaScript implementation of the https://semver.org/ specification
130Copyright Isaac Z. Schlueter
131
132Usage: semver [options] <version> [<version> [...]]
133Prints valid versions sorted by SemVer precedence
134
135Options:
136-r --range <range>
137 Print versions that match the specified range.
138
139-i --increment [<level>]
140 Increment a version by the specified level. Level can
141 be one of: major, minor, patch, premajor, preminor,
142 prepatch, or prerelease. Default level is 'patch'.
143 Only one version may be specified.
144
145--preid <identifier>
146 Identifier to be used to prefix premajor, preminor,
147 prepatch or prerelease version increments.
148
149-l --loose
150 Interpret versions and ranges loosely
151
152-p --include-prerelease
153 Always include prerelease versions in range matching
154
155-c --coerce
156 Coerce a string into SemVer if possible
157 (does not imply --loose)
158
159--rtl
160 Coerce version strings right to left
161
162--ltr
163 Coerce version strings left to right (default)
164
165Program exits successfully if any valid version satisfies
166all supplied ranges, and prints all satisfying versions.
167
168If no satisfying versions are found, then exits failure.
169
170Versions are printed in ascending order, so supplying
171multiple versions to the utility will just sort them.`)
172
173main()
Note: See TracBrowser for help on using the repository browser.