Skip to content

Commit

Permalink
feat(readme): manpm can show and search README.md in the current fold…
Browse files Browse the repository at this point in the history
…er, closes #20
  • Loading branch information
bahmutov committed Dec 11, 2015
1 parent 7c79ea8 commit dfe848f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for both variants: words or unicode symbols

npm install -g manpm

## Show entire package or github readme
## Show the entire README from a package or github repo

You can give NPM package name (like `manpm`), GitHub user / repo pair (like `bahmutov/manpm`) or
full GitHub url (like `https://github.com/bahmutov/object-fitter` or `[email protected]:bahmutov/object-fitter.git`).
Expand Down Expand Up @@ -64,6 +64,12 @@ The following search features are implemented
I am still looking for a library capable of fuzzy text search.
Maybe [lunr](https://github.com/olivernn/lunr.js)?

## Show and search local README

Sometimes you just want to find a section in the local README file, right in the current directory.

manpm . [optional search text]

## Example: showing ES6 docs

There is a great GitHub repo [ES6 Overview in 350 Bullet Points](https://github.com/bevacqua/es6)
Expand Down
26 changes: 22 additions & 4 deletions src/get-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,37 @@ function getReadmeFromGithub(name) {
.then(toString);
}

function getLocalReadmeFile() {
var fs = require('fs');
var join = require('path').join;
var filename = join(process.cwd(), 'README.md');
return new Promise(function (resolve, reject) {
if (!fs.existsSync(filename)) {
return reject(new Error('Cannot find local file ' + filename));
}
return resolve(fs.readFileSync(filename, 'utf8'));
});
}

function getReadme(name) {
la(check.unemptyString(name), 'missing name');

if (name === '.') {
log('fetching README in the current working folder');
return getLocalReadmeFile();
}

if (utils.maybeGithubRepoName(name)) {
log('fetching README for github repo', name);
return getReadmeFromGithub(name);
} else if (utils.maybeGithubRepoUrl(name)) {
}
if (utils.maybeGithubRepoUrl(name)) {
log('fetching README for github url', name);
return getReadmeFromGithub(name);
} else {
log('fetching README for package', name);
return getReadmeFile(name);
}

log('fetching README for package', name);
return getReadmeFile(name);
}

module.exports = getReadme;

0 comments on commit dfe848f

Please sign in to comment.