Skip to content

Commit

Permalink
Helper "withPackageOf" now also supports github-ssh-urls in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed May 21, 2017
1 parent 134ac29 commit a3405c5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions handlebars/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ function transformTree (object, fn) {
function github (filePath) {
// Build url to correct version and file in githubs
const packageJson = findPackage(path.resolve(filePath), true)
const url = packageJson && packageJson.repository && packageJson.repository.url
const url = repoWebUrl(packageJson && packageJson.repository && packageJson.repository.url)
if (url && url.match(/github.com/)) {
const version = packageJson.version
// path within the package
const relativePath = path.relative(path.dirname(packageJson.paths.absolute), filePath)
return url.replace(/^git\+/, '').replace(/\.git$/, '') + '/blob/v' + version + '/' + relativePath
return `${url}/blob/v${version}/${relativePath}`
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/github-ssh-repo-url/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "github-ssh-repo-url",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/nknapp/thought-plugin-jsdoc.git"
},
"keywords": [],
"author": "",
"license": "ISC"
}
1 change: 1 addition & 0 deletions test/fixtures/include/withPackageOf.ssh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/nknapp/thought-plugin-jsdoc/blob/v1.0.0/package.json - github-ssh-repo-url
8 changes: 8 additions & 0 deletions test/helper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ describe('thought-helpers:', function () {
.to.eventually.equal(versions(fixture('include/withPackageOf.default.md')))
})

it('should create a url and package.json for file on github (with a git-ssh-url)', function () {
return expectHbs(
'{{#withPackageOf file}} {{@url}} - {{@package.name}} {{/withPackageOf}}',
{file: 'test/fixtures/github-ssh-repo-url/package.json'}
)
.to.eventually.equal(versions(fixture('include/withPackageOf.ssh.md')))
})

it('should create a url and package.json for files in dependency projects (based on the their current package version)', function () {
return expectHbs(
'{{#withPackageOf file}} {{@url}} - {{@package.name}} {{/withPackageOf}}',
Expand Down

0 comments on commit a3405c5

Please sign in to comment.