-
Notifications
You must be signed in to change notification settings - Fork 2
/
gitfn.js
44 lines (36 loc) · 980 Bytes
/
gitfn.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
'use strict'
const child = require('child_process')
const semver = require('semver')
const assertVersionValid = version => {
if (!semver.valid(version)) {
throw new Error('version is invalid')
}
}
const exec = (cmd, options, cb) => child.exec(cmd, options, cb)
class GitFn {
constructor (version, options) {
this._version = version
this._options = {
cwd: options.dir,
env: process.env,
setsid: false,
stdio: [0, 1, 2]
}
}
tag (cb) {
assertVersionValid(this._version)
const cmd = ['git', 'tag', 'v' + this._version].join(' ')
exec(cmd, this._options, cb)
}
untag (cb) {
assertVersionValid(this._version)
const cmd = ['git', 'tag', '-d', 'v' + this._version].join(' ')
exec(cmd, this._options, cb)
}
commit (cb) {
assertVersionValid(this._version)
const cmd = ['git', 'commit', '-am', '"' + this._version + '"'].join(' ')
exec(cmd, this._options, cb)
}
}
module.exports = GitFn