This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit-tags.js
67 lines (58 loc) · 1.8 KB
/
git-tags.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
/**
* This code is adapted from https://github.com/bfricka/node-git-tags/blob/master/src/git-tags.js
* That package is not maintained.
*/
const _ = require('lodash');
const path = require('path');
const semver = require('semver');
const git = require('./utilities/git');
const parseTags = data => {
return _.compact(data.split('\n'))
.filter(semver.valid)
.sort(semver.compare)
.reverse();
}
const filterTags = repo => {
return git.getTags(repo).then(tags => {
return git.getRepoConfig(repo).then(config => {
let gitFlowConfigs = Object.keys(config).filter(item => item.indexOf('gitflow') === 0);
if (gitFlowConfigs.length > 0) {
let releasePrefix = config['gitflow.prefix.release'];
let gitFlowTags = tags.split('\n').filter(tag => tag.indexOf(releasePrefix) === 0).map(tag => tag.substring(releasePrefix.length)).join('\n');
return parseTags(gitFlowTags);
} else {
return parseTags(tags);
}
});
});
}
const normalizeFn = fn => {
return repo => {
return new Promise((resolve, reject) => {
if (!repo) {
repo = process.cwd();
}
if (repo.charAt(0) === '.') {
repo = path.resolve(repo);
}
filterTags(repo).then(tags => {
resolve(fn(tags));
}).catch(error => {
reject(error);
})
});
};
}
const ret = arg => {
return arg;
}
module.exports = {
get: normalizeFn(ret),
latest: normalizeFn(_.first),
oldest: normalizeFn(_.last),
parse: semver.parse,
mmp: function (tag) {
var p = semver.parse(tag);
return [p.major, p.minor, p.patch].join('.');
}
};