Skip to content

Commit

Permalink
Use terminal-link module
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 29, 2018
1 parent 370ef63 commit 6a86102
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 6 additions & 7 deletions lib/util.js
@@ -1,8 +1,7 @@
'use strict';
const readPkgUp = require('read-pkg-up');
const issueRegex = require('issue-regex');
const hyperlinker = require('hyperlinker');
const supportsHyperlinks = require('supports-hyperlinks');
const terminalLink = require('terminal-link');

exports.readPkg = () => {
const pkg = readPkgUp.sync().pkg;
Expand All @@ -15,25 +14,25 @@ exports.readPkg = () => {
};

exports.linkifyIssues = (url, message) => {
if (!url || !supportsHyperlinks.stdout) {
if (!(url && terminalLink.isSupported)) {
return message;
}

return message.replace(issueRegex(), issue => {
const issuePart = issue.replace('#', '/issues/');

if (issue.startsWith('#')) {
return hyperlinker(issue, `${url}${issuePart}`);
return terminalLink(issue, `${url}${issuePart}`);
}

return hyperlinker(issue, `https://github.com/${issuePart}`);
return terminalLink(issue, `https://github.com/${issuePart}`);
});
};

exports.linkifyCommit = (url, commit) => {
if (!url || !supportsHyperlinks.stdout) {
if (!(url && terminalLink.isSupported)) {
return commit;
}

return hyperlinker(commit, `${url}/commit/${commit}`);
return terminalLink(commit, `${url}/commit/${commit}`);
};
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -34,7 +34,6 @@
"execa": "^0.8.0",
"github-url-from-git": "^1.5.0",
"has-yarn": "^1.0.0",
"hyperlinker": "^1.0.0",
"inquirer": "^3.0.6",
"issue-regex": "^1.0.0",
"listr": "^0.12.0",
Expand All @@ -47,7 +46,7 @@
"semver": "^5.2.0",
"split": "^1.0.0",
"stream-to-observable": "^0.2.0",
"supports-hyperlinks": "^1.0.1",
"terminal-link": "^1.1.0",
"update-notifier": "^2.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit 6a86102

Please sign in to comment.