diff --git a/index.js b/index.js index 2480019..fe587a3 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const deglob = require('deglob') const find = require('find-file-up') +const Githost = require('find-githost') const engine = require('unified-engine') const color = require('supports-color').stdout const fromCallback = require('catering').fromCallback @@ -17,7 +18,7 @@ function hallmark (options, callback) { const pkg = read('package.json', cwd) || {} const rc = Object.assign({}, read('.hallmarkrc', cwd), pkg.hallmark) const files = first('files', options, rc) || ['*.md'] - const repository = repo(first('repository', options, rc, pkg)) || originRepo(cwd) || '' + const repository = repo(cwd, options, rc, pkg) const ignore = concat('ignore', rc, options) deglob(files, { usePackageJson: false, cwd, ignore }, function (err, files) { @@ -178,8 +179,20 @@ function first (key, ...sources) { } } -function repo (repository) { - return repository ? repository.url || repository : null +function repo (cwd, options, rc, pkg) { + const override = options.repository || rc.repository + const committish = false + + if (override) { + return Githost.fromUrl(override, { committish }).https() + } + + const host = ( + Githost.fromPkg(pkg, { committish, optional: true }) || + Githost.fromGit(cwd, { committish }) + ) + + return host.https() } function concat (key, rc, options) { @@ -192,11 +205,3 @@ function collapseToc () { summary: 'Click to expand' } } - -function originRepo (cwd) { - // Don't pass cwd for now (jonschlinkert/parse-git-config#13) - const origin = require('remote-origin-url').sync(/* cwd */) - const ghurl = require('github-url-from-git') - - return origin ? ghurl(origin) : null -} diff --git a/package.json b/package.json index 2db1a8c..76cf6fa 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "catering": "^2.0.0", "deglob": "^4.0.0", "find-file-up": "^2.0.1", - "github-url-from-git": "^1.5.0", + "find-githost": "^1.0.0", "remark": "^12.0.1", "remark-autolink-references": "^1.0.0", "remark-collapse": "~0.1.2", @@ -50,7 +50,6 @@ "remark-lint-table-pipes": "^2.0.1", "remark-toc": "^7.0.0", "remark-validate-links": "^10.0.2", - "remote-origin-url": "^2.0.0", "subarg": "^1.0.0", "supports-color": "^7.1.0", "unified-engine": "^8.0.0",