Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

changed method of loading npm packages #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const fs = require('fs')
"allPackagesOutput" : "/path/to/allpackages.json"
, "repositoriesOutput" : "/path/to/repositories.json"
, "githubOutput" : "/path/to/githubusers.json"
, "aussieOutput" : "/path/to/aussieOutput.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? I don't think this is needed here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to as is used on line 87

, "githubAuthToken" : "yourgithubauthtoken"
}

Expand Down
79 changes: 53 additions & 26 deletions load-npm-data.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,75 @@
// if your GitHub location field matches this then we'll guess you're Aussie
const GITHUB_REPO_REGEX = /github.com[:\/]([\.\-\w]+)\/([^$\/\.]+)/

const npm = require('npm')
, NPM_ALL_PACKAGES_URL = 'https://skimdb.npmjs.com/registry/_all_docs'
, NPM_SINGLE_PACKAGE_URL = 'https://registry.npmjs.org/{packageId}/latest'
, request = require('request').defaults({json:true})
, async = require('async');

function matchGitHubRepo (npmPackage, repo) {
var match = repo
&& typeof repo.url == 'string'
&& repo.url.match(GITHUB_REPO_REGEX)
&& repo.url.match(GITHUB_REPO_REGEX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no semicolon


return match && {
githubUser : match[1]
, githubRepo : match[2]
, npmPackage : npmPackage
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no semi

}

// load the list of all npm libs with 'repo' pointing to GitHub
function loadNpmData (callback) {
var repositories = []
, allPackages = []
function getPackageData(repositories, allPackages, packageData, callback){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces both sides of the args parnens

request(NPM_SINGLE_PACKAGE_URL.replace('{packageId}', packageData.id), function (err, response, data) {
if (err) {
// log and continue usually just a timeout, possibly needs retry logic
console.log('error getting data for package: ' + packageData.id, err.message);
return callback();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semicolons previous 2 lines

}

// Bad maintainers property there are MANY just skip for much speed increase
if(!data.maintainers || !Array.isArray(data.maintainers)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces, after if, before {

return callback();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semi

}

var repo = matchGitHubRepo(data.name, data.repository);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semi


if (repo){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space beore {

repositories.push(repo);
}

npm.load(function (err) {
if (err) return callback(err)
allPackages.push({
name : data.name
, maintainers : (data.maintainers || []).map(function (m) { return m && m.name })
, githubUser : repo ? repo.githubUser : null
, githubRepo : repo ? repo.githubRepo : null
, description : data.description
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semis on the next few lines


callback();
});
}

function getAllPackages(callback){
var repositories = []
, allPackages = [];

npm.registry.get('/-/all', function (err, data) {
if (err) return callback(err)
// https://github.com/npm/npm-registry-couchapp/issues/162
request(NPM_ALL_PACKAGES_URL, function(err, response, body){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after function, before {

if (err) {
return callback(err);
}

Object.keys(data).forEach(function (k) {
var repo = matchGitHubRepo(data[k].name, data[k].repository)
if (repo)
repositories.push(repo)
if(!body || !body.rows){
body = { rows: [] };
}

allPackages.push({
name : data[k].name
, maintainers : (data[k].maintainers || []).map(function (m) { return m.name })
, githubUser : repo ? repo.githubUser : null
, githubRepo : repo ? repo.githubRepo : null
, description : data[k].description
})
})
async.mapLimit(body.rows, 10, getPackageData.bind(null, repositories, allPackages), function(err){
if (err) {
return callback(err);
}

callback(null, { repositories: repositories, allPackages: allPackages })
})
})
});
}

module.exports = loadNpmData
module.exports = getAllPackages
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"author": "",
"license": "MIT",
"dependencies": {
"npm": "~1.2.18",
"async": "~0.2.7",
"request": "~2.20.0",
"function-rate-limit": "0.0.1"
"async": "^1.5.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/^/~

"function-rate-limit": "0.0.1",
"request": "^2.67.0"
},
"private": true
}
}