-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate links to changes, if possible.
- Loading branch information
Showing
6 changed files
with
152 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import { dedent } from './utils' | ||
import cool from 'cool-ascii-faces'; | ||
|
||
|
||
export default ({ name, version, description, author = {}, publisher = {}, homepage = 'n/a', repository = 'Not found.' }) => { | ||
export default ({ name, version, description, author = {}, publisher = {}, homepage = 'n/a', repo = 'n/a', changes = '' }) => { | ||
|
||
let { name: authorName = 'anonymous', email: authorEmail = '' } = author; | ||
let { name: publisherName = 'anonymous', email: publisherEmail = '' } = publisher; | ||
|
||
return dedent` | ||
Module: ${name} | ||
Version: ${version} | ||
Author: ${authorName}${authorEmail && ` <${authorEmail}>`} | ||
Published By: ${publisherName}${publisherEmail && ` <${publisherEmail}>`} | ||
Homepage: ${homepage} | ||
Repository: ${repository} | ||
Description: ${description} | ||
`; | ||
} | ||
return ` | ||
${name} ${version} | ||
${description} | ||
Author: ${authorName}${authorEmail && ` <${authorEmail}>`} | ||
Publisher: ${publisherName}${publisherEmail && ` <${publisherEmail}>`} | ||
Homepage: ${homepage} | ||
Repository: ${repo} | ||
${changes} | ||
${cool()}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,45 @@ | ||
import Url from 'url'; | ||
|
||
// From: https://gist.github.com/zenparsing/5dffde82d9acef19e43c | ||
function dedent(callsite, ...args) { | ||
|
||
function format(str) { | ||
let size = -1; | ||
|
||
return str.replace(/\n(\s+)/g, (m, m1) => { | ||
if (size < 0) { | ||
size = m1.replace(/\t/g, ' ').length; | ||
} | ||
|
||
return '\n' + m1.slice(Math.min(m1.length, size)); | ||
}); | ||
function git2http(url) { | ||
// Discard non-strings | ||
if (typeof url !== 'string') { | ||
return undefined; | ||
} | ||
|
||
if (typeof callsite === 'string') { | ||
return format(callsite); | ||
// Try parsing the URL, if that fails one symptom is | ||
// a missing protocol. If the protocol is missing, | ||
// prepend one and try again. That way we don't have to | ||
// try to write url parsing rules here, we just test | ||
// for what we need. | ||
let parsed = Url.parse(url); | ||
if (!parsed.protocol && !parsed.hostname) { | ||
// If there's no protocol, we assume the parse failed. Will | ||
// happen, for example, on [email protected]:org/repository.git. | ||
parsed = Url.parse('https://' + url); | ||
if (!parsed.protocol && !parsed.hostname) { | ||
// Adding a protocol didn't help, so not a valid uri for our needs. | ||
return undefined; | ||
} | ||
} | ||
|
||
if (typeof callsite === 'function') { | ||
return (...args) => format(callsite(...args)); | ||
} | ||
|
||
let output = callsite | ||
.slice(0, args.length + 1) | ||
.map((text, i) => (i === 0 ? '' : args[i - 1]) + text) | ||
.join(''); | ||
|
||
return format(output); | ||
// Git paths like github.com:org/repo produce the pathname | ||
// '/:org/repo', so the colon needs to be removed. Also, | ||
// remove the optional `.git` extension. | ||
parsed.pathname = parsed.pathname.replace(/^\/\:/, '/'); | ||
parsed.protocol = 'https:'; | ||
parsed.slashes = true; | ||
parsed.auth = null; | ||
parsed.host = null; | ||
parsed.path = null; | ||
parsed.search = null; | ||
parsed.hash = null; | ||
parsed.query = null; | ||
return Url.format(parsed); | ||
} | ||
|
||
export default { | ||
|
||
dedent | ||
git2http | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import tape from 'tape'; | ||
import glob from 'glob'; | ||
import Path from 'path'; | ||
|
||
// Kick things off, but only after the module has completed loading, | ||
// hence the setImmediate. If the load the modules synchronously, | ||
// the exported object isn't yet available (since tests import this | ||
// module) and we get into a weird state. | ||
setImmediate(() => { | ||
// All this mess for npm < 2. With 2.x this can be removed | ||
// and npm script argument globbing can be used. | ||
process.argv.slice(2).forEach(arg => { | ||
glob.sync(arg).forEach(file => { | ||
require(Path.resolve(process.cwd(), file)); | ||
}); | ||
}); | ||
|
||
// Get a handle on the root test harness so we | ||
// can forcefull kill the process (THANKS TIMERS!) | ||
//tape().on('end', function () { setImmediate(process.exit, 0) }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import test from 'tape' | ||
import Path from 'path'; | ||
import { git2http } from '../dist/lib/utils'; | ||
|
||
|
||
test('git2http', function (t) { | ||
|
||
let uris = [ | ||
['https://github.com/org/repository', 'https://github.com/org/repository'], | ||
['https://github.com/org/repository.git', 'https://github.com/org/repository.git'], | ||
['git://github.com/org/repository.git', 'https://github.com/org/repository.git'], | ||
['git://github.com:org/repository.git', 'https://github.com/org/repository.git'], | ||
['[email protected]:org/repository', 'https://github.com/org/repository'], | ||
['[email protected]:org/repository.git', 'https://github.com/org/repository.git'], | ||
['[email protected]/org/repository', 'https://github.com/org/repository'], | ||
['[email protected]/org/repository.git', 'https://github.com/org/repository.git'], | ||
['git://[email protected]:org/repository', 'https://github.com/org/repository'], | ||
['git://[email protected]:org/repository.git', 'https://github.com/org/repository.git'], | ||
['git://[email protected]/org/repository', 'https://github.com/org/repository'], | ||
['git://[email protected]/org/repository.git', 'https://github.com/org/repository.git'], | ||
['git+ssh://[email protected]:org/repository', 'https://github.com/org/repository'], | ||
['git+ssh://[email protected]:org/repository.git', 'https://github.com/org/repository.git'], | ||
['git+ssh://[email protected]/org/repository', 'https://github.com/org/repository'], | ||
['git+ssh://[email protected]/org/repository.git', 'https://github.com/org/repository.git'] | ||
]; | ||
|
||
t.test('uri', function () { | ||
//let expected = 'https://github.com/org/repository'; | ||
|
||
for (let [uri, expected] of uris) { | ||
t.equal(git2http(uri), expected); | ||
} | ||
|
||
t.end(); | ||
}); | ||
|
||
}); |