-
Notifications
You must be signed in to change notification settings - Fork 10
/
apv.js
executable file
·79 lines (69 loc) · 1.66 KB
/
apv.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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env node
/*
* Project: appversion
* Version: 1.7.1
* Author: delvedor
* Twitter: @delvedor
* License: MIT
* GitHub: https://github.com/delvedor/appversion
*/
'use strict'
// Modules
const minimist = require('minimist')
const chalk = require('chalk')
// apv parameters and functions
const update = require('./lib/update').update
const setVersion = require('./lib/set').setVersion
const setStatus = require('./lib/set').setStatus
const createBadge = require('./lib/badge').createBadge
const init = require('./lib/init').init
const addGitTag = require('./lib/git').addGitTag
const checkUpdate = require('./lib/updater').checkUpdate
const apvVersion = require('./lib/parameters').apvVersion
const help = require('./lib/help').help
// arguments parser
const args = minimist(process.argv.slice(2))
// if the flag -v|--version is passed
if (args.v || args.version) {
console.log(chalk.cyan(apvVersion))
process.exit(1)
}
// if the flag -h|--help is passed
if (args.h || args.help) {
help()
process.exit(1)
}
// if there are not arguments
if (!args._.length) {
help()
process.exit(1)
}
if (args._.length > 2) console.log(chalk.yellow('AppVersion accepts only one command per time'))
const cmd = args._[0]
const param = args._[1] || null
switch (cmd) {
case 'update':
update(param)
if (args.tag) addGitTag()
break
case 'set-version':
setVersion(param)
if (args.tag) addGitTag()
break
case 'set-status':
setStatus(param)
break
case 'generate-badge':
createBadge(param)
break
case 'add-git-tag':
addGitTag()
break
case 'init':
init()
break
default:
help()
}
// Checks for an update
checkUpdate()