-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (20 loc) · 1.04 KB
/
index.js
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
#!/usr/bin/env node
const path = require('path')
const program = require('commander')
const extract = require('./extract')
program
.usage('[options] <version>')
.option('--major', 'Extract major version')
.option('--minor', 'Extract minor version')
.option('--patch', 'Extract minor version')
.option('--branch', 'Accept a branch name. Meaning that a string not coerced to a semver version will be returned as it is.')
.option('--pjson', 'Read the version number from ./package.json instead of the <version> argument')
.option('-x', 'Add "x" after truncated version')
.parse(process.argv)
if (!process.argv.slice(2).length) program.outputHelp();
// Input is either coming from the arguments or read in the local package.json file
let rawVersion = program.args[0]
if (program.pjson) rawVersion = require(path.resolve(process.cwd(), 'package.json')).version
// Better for input from GITHUB_REF env var
if (rawVersion.startsWith('refs/heads/')) rawVersion = rawVersion.replace('refs/heads/', '')
process.stdout.write(extract(rawVersion, program))