-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f61c21
commit 2ca1288
Showing
2 changed files
with
47 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
'use strict' | ||
|
||
var child = require('child_process') | ||
|
||
function GitFn (version, options) { | ||
this._version = version | ||
this._options = { | ||
cwd: options.dir, | ||
env: process.env, | ||
setsid: false, | ||
stdio: [0, 1, 2] | ||
const child = require('child_process') | ||
const semver = require('semver') | ||
|
||
const assertVersionValid = version => { | ||
if (!semver.valid(version)) { | ||
throw new Error('version is invalid') | ||
} | ||
} | ||
module.exports = GitFn | ||
|
||
GitFn.prototype = { | ||
tag: function (cb) { | ||
var cmd = ['git', 'tag', 'v' + this._version].join(' ') | ||
this._exec(cmd, cb) | ||
}, | ||
untag: function (cb) { | ||
var cmd = ['git', 'tag', '-d', 'v' + this._version].join(' ') | ||
this._exec(cmd, cb) | ||
}, | ||
commit: function (cb) { | ||
var cmd = ['git', 'commit', '-am', '"' + this._version + '"'].join(' ') | ||
this._exec(cmd, cb) | ||
}, | ||
_exec: function (cmd, cb) { | ||
child.exec(cmd, this._options, cb) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters