-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathutil.js
65 lines (51 loc) · 1.5 KB
/
util.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
'use strict';
const readPkgUp = require('read-pkg-up');
const issueRegex = require('issue-regex');
const terminalLink = require('terminal-link');
const execa = require('execa');
const pMemoize = require('p-memoize');
const ow = require('ow');
exports.readPkg = () => {
const {package: pkg} = readPkgUp.sync();
if (!pkg) {
throw new Error('No package.json found. Make sure you\'re in the correct project.');
}
return pkg;
};
exports.linkifyIssues = (url, message) => {
if (!(url && terminalLink.isSupported)) {
return message;
}
return message.replace(issueRegex(), issue => {
const issuePart = issue.replace('#', '/issues/');
if (issue.startsWith('#')) {
return terminalLink(issue, `${url}${issuePart}`);
}
return terminalLink(issue, `https://github.com/${issuePart}`);
});
};
exports.linkifyCommit = (url, commit) => {
if (!(url && terminalLink.isSupported)) {
return commit;
}
return terminalLink(commit, `${url}/commit/${commit}`);
};
exports.linkifyCommitRange = (url, commitRange) => {
if (!(url && terminalLink.isSupported)) {
return commitRange;
}
return terminalLink(commitRange, `${url}/compare/${commitRange}`);
};
exports.getTagVersionPrefix = pMemoize(async options => {
ow(options, ow.object.hasKeys('yarn'));
try {
if (options.yarn) {
const {stdout} = await execa('yarn', ['config', 'get', 'version-tag-prefix']);
return stdout;
}
const {stdout} = await execa('npm', ['config', 'get', 'tag-version-prefix']);
return stdout;
} catch (_) {
return 'v';
}
});