-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
49 lines (39 loc) · 1.19 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import execa from 'execa';
import isGit from 'is-git-repository';
import { platform } from 'os';
import makepath from 'path';
import pathIsAbsolute from 'path-is-absolute';
const cwd = process.cwd();
const countGitTags = ({ path, local } = {}) => {
let countOfTags = 0;
let thisPath = path || cwd;
thisPath = pathIsAbsolute(thisPath) ? thisPath : makepath.join(cwd, thisPath);
const thisLocal = local === undefined ? true : local;
if (!isGit(thisPath)) {
return 0;
}
try {
let getTagsExec;
let getTags;
if (thisLocal) {
if (platform() === 'win32') {
getTagsExec = `pushd ${thisPath} & git tag`;
} else {
getTagsExec = `(cd ${thisPath} ; git tag)`;
}
getTags = execa.shellSync(getTagsExec).stdout;
} else {
if (platform() === 'win32') {
getTagsExec = `pushd ${thisPath} & git ls-remote --tags`;
} else {
getTagsExec = `(cd ${thisPath} ; git ls-remote --tags)`;
}
getTags = execa.shellSync(getTagsExec).stdout;
}
countOfTags = getTags.length === 0 ? getTags.length : getTags.split('\n').length;
return countOfTags;
} catch (e) {
return 0;
}
};
export default countGitTags;