-
Notifications
You must be signed in to change notification settings - Fork 3
/
packagesdeps.coffee
executable file
·61 lines (47 loc) · 1.76 KB
/
packagesdeps.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env coffee
fs = require 'fs'
npm = require 'npm'
props = ['name', 'description', 'maintainers', 'author', 'version', 'keywords', 'homepage', 'contributors', 'dependencies']
deps = []
cache = {}
write = (name, firstletter)->
console.log 'Processing package: ' + name
npm.commands.view [name], true, (err, pkg)->
return if not typeof pkg is 'object' or !pkg
latest = pkg[Object.keys(pkg)[0]]
return if typeof latest is 'undefined'
pkgobj = {}
props.map (prop)->
if latest.hasOwnProperty prop
pkgobj[prop] = latest[prop]
# package dependencies
adjlist = [pkgobj.name]
if pkgobj.dependencies and typeof pkgobj.dependencies is 'object'
pkgdeps = Object.keys(pkgobj.dependencies)
adjlist = adjlist.concat pkgdeps if pkgdeps.length
deps.push adjlist.join ';'
cache[firstletter][name] = pkgobj
fs.writeFile 'packages/' + firstletter + '.json', JSON.stringify(cache[firstletter]), (err)->
console.log err if err
fs.writeFile 'packagesdeps.csv', deps.join('\n'), (err)->
console.log err if err
procpkgs = (pkgs)->
for name, data of pkgs
firstletter = name.charAt 0
if !(cache.hasOwnProperty firstletter)
cache[firstletter] = {}
write name, firstletter
npm.load { outfd : null }, ()->
fs.readFile 'packages.json', 'utf8', (err, content)->
procpkgs JSON.parse(content)
test = ()->
testpkgs = {
'databinding': {name: 'databinding'},
'avconv': {name: 'avconv'},
'd3': {name: 'd3'},
'd3-browser': {name: 'd3-browser'},
'zzz': {name: 'zzz'}
}
npm.load { outfd : null }, ()->
procpkgs testpkgs
#test()