Comparing version 0.1.0 to 0.1.1
@@ -121,2 +121,9 @@ #!/usr/bin/env node | ||
readRemoteFile(url); | ||
} else if (options.npm) { | ||
if (options.npm === true) { | ||
console.log('NPM flag requries a repo as an argument, e.g. ' + style.codespan(' mdr -n somepackage')); | ||
process.exit(); | ||
} | ||
getNPMFile(options.npm); | ||
} else { | ||
@@ -139,2 +146,57 @@ fs.stat(options.file, function (err, stat) { | ||
/** | ||
* Get readme from an NPM package name. | ||
* | ||
* @param {String} package Name of package | ||
*/ | ||
function getNPMFile(package_name) { | ||
var npm = require('npm'); | ||
var url = require('url'); | ||
npm.load({}, function () { | ||
npm.commands.view( | ||
[package_name, 'readmeFilename', 'repository.url'], | ||
true, | ||
function (error, data) { | ||
var raw_url, | ||
file_name, | ||
readme_url; | ||
if (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
var datum = getFirst(data); | ||
if (!datum) { | ||
console.log('Could not get readme URL.'); | ||
return false; | ||
} | ||
raw_url = datum['repository.url']; | ||
file_name = datum['readmeFilename']; | ||
var repo_url = url.parse(raw_url); | ||
switch (repo_url.hostname) { | ||
case 'github.com': | ||
readme_url = raw_url.replace('github.com', 'raw.githubusercontent.com') + | ||
'/master/' + file_name; | ||
break; | ||
case 'bitbucket.org': | ||
readme_url = 'https://bitbucket.org/' + repo_url.pathname + | ||
'/raw/master/' + file_name; | ||
break; | ||
default: | ||
console.log('I don\'t know how to find that readme file. Sorry. Please raise an issue at github.com/mrchimp/mdr'); | ||
return false; | ||
} | ||
readRemoteFile(readme_url); | ||
} | ||
); | ||
}); | ||
} | ||
/** | ||
* Repeat a string | ||
@@ -255,2 +317,14 @@ * | ||
/** | ||
* Get the first element from an object | ||
*/ | ||
function getFirst(obj) { | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i) && typeof i !== 'function') { | ||
return obj[i]; | ||
} | ||
} | ||
} | ||
/* | ||
@@ -257,0 +331,0 @@ * Block Item Renderers |
{ | ||
"name": "mdr", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Read markdown files in the terminal in color", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
# mdr # | ||
[![NPM version](https://badge.fury.io/js/mdr.svg)](http://badge.fury.io/js/mdr) | ||
Markdown reader with color | ||
@@ -28,3 +30,3 @@ | ||
mdr -g mrchimp/mdr # Show README.md from Github repo | ||
mdr foo.md -g bar/bar # Show foo.md from Bitbucket repo | ||
mdr foo.md -b bar/bar # Show foo.md from Bitbucket repo | ||
@@ -77,3 +79,2 @@ `mdr -h` for more help. | ||
* Syntax highlighting for code blocks | ||
* Make paginatable - output content to `less -r` or something? Why doesn't this work? Colours get lost. | ||
* Detect italic support? | ||
@@ -80,0 +81,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20079
383
83