Skip to content

Commit

Permalink
Refactor: use find-githost
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Nov 14, 2021
1 parent 3876b0f commit 15e2fc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
27 changes: 16 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 15e2fc4

Please sign in to comment.