/
ls.js
39 lines (28 loc) · 1.02 KB
/
ls.js
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
var fs = require('fs'),
path = require('path'),
homePath = path.normalize(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']) + '/.npm_lazy',
meta = require(homePath + '/meta.json');
var Cache = require('../lib/cache.js');
var cache = new Cache({ path: homePath });
var files = fs.readdirSync(homePath);
var entries = [];
Object.keys(meta).forEach(function(uri) {
var ipath = meta[uri].taskResults.GET.path;
entries.push({ size: fs.statSync(ipath).size, uri: uri, path: ipath });
var index = files.indexOf(path.basename(ipath));
if (index > -1) {
files.splice(index, 1);
}
console.log('Cache check', uri, cache.lookup(uri, 'GET').path);
});
files.forEach(function(name) {
var ipath = homePath + '/' + name;
entries.push({ size: fs.statSync(ipath).size, path: ipath, uri: 'N/A' });
});
entries.sort(function(a, b) {
return b.size - a.size;
});
var bytes = require('bytes');
entries.forEach(function(line) {
console.log(bytes(line.size) + ' ' + line.uri + ' ' + line.path);
});