Skip to content

Commit

Permalink
fix(node5): testing on node 4 and 5, fixed get, closes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 2, 2016
1 parent a00ed3e commit 0ffdc31
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
npm-debug.log
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ cache:
notifications:
email: false
node_js:
- '4'
- '4.2.2'
- '5'
before_install:
- npm i -g npm@^2.0.0
before_script:
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,25 @@
"check-more-types": "2.2.0",
"debug": "2.2.0",
"get-package-readme": "1.1.0",
"github-readme": "1.0.0",
"lazy-ass": "1.1.0",
"lodash": "3.10.1",
"marked": "0.3.5",
"marked-terminal": "https://github.com/mikaelbr/marked-terminal.git#35f6ddac9d9f32b11e85ceb6bc5f42642f06e456",
"marked-to-md": "1.0.1",
"really-need": "1.7.2",
"package-json": "2.3.0",
"simple-bin-help": "1.5.0",
"simple-get": "1.4.3",
"update-notifier": "0.5.0"
},
"preferGlobal": true,
"release": {
"verifyConditions": {
"path": "condition-node-version",
"node": "4.2.2",
"verbose": true
}
},
"config": {
"pre-git": {
"commit-msg": "simple",
Expand All @@ -87,6 +95,7 @@
},
"devDependencies": {
"ban-sensitive-files": "1.4.0",
"condition-node-version": "1.2.0",
"eslint": "1.10.1",
"exact-semver": "1.2.0",
"git-issues": "1.2.0",
Expand Down
45 changes: 18 additions & 27 deletions src/get-readme.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
var log = require('debug')('manpm');
var la = require('lazy-ass');
var check = require('check-more-types');
var parseGithubRepoUrl = require('@bahmutov/parse-github-repo-url');
var utils = require('./utils');

// working around github-url-to-object used inside get-package-readme
// that cannot handle www.github.com urls
// this does NOT work on npm2 where it cannot find github-url-to-object
// due to multi level folder
/* eslint no-undef:0 */
try {
require = require('really-need');
require('github-url-to-object', {
post: function () {
return function gh(url) {
log('parsing github url %s ourselves', url);
var parsed = parseGithubRepoUrl(url);
return {
user: parsed[0],
repo: parsed[1]
};
};
}
});
} catch (err) {
// ignore
}

var Promise = require('bluebird');
var getReadmeFile = Promise.promisify(require('get-package-readme'));
var packageJson = require('package-json');
var simpleGet = require('simple-get');

function get(url) {
Expand Down Expand Up @@ -77,6 +53,12 @@ function getReadmeFromGithub(name) {
log('fetching url from', fullUrl);

return get(fullUrl)
.catch(function () {
// probably not found
fullUrl = formGithubUrl(parsed, 'readme.md');
log('fetching url from', fullUrl);
return get(fullUrl);
})
.catch(function () {
// probably not found
fullUrl = formGithubUrl(parsed, 'readme.markdown');
Expand Down Expand Up @@ -115,8 +97,17 @@ function getReadme(name) {
return getReadmeFromGithub(name);
}

log('fetching README for package', name);
return getReadmeFile(name);
log('fetching README for NPM package', name);
return packageJson(name, 'latest')
.then(function (json) {
console.log('repository', json.repository);
if (!json.repository) {
throw new Error('Cannot find repository for ' + name);
}
la(check.unemptyString(json.repository.url),
'missing url', json.repository);
return getReadmeFromGithub(json.repository.url);
});
}

module.exports = getReadme;

0 comments on commit 0ffdc31

Please sign in to comment.