1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00

Added listings

This commit is contained in:
Brian Peacock 2014-05-06 17:40:21 -05:00
parent bb129c1151
commit 34b631fa12
5 changed files with 81 additions and 9 deletions

@ -6,5 +6,15 @@
</head> </head>
<body> <body>
<h1>{{ name }}</h1> <h1>{{ name }}</h1>
<input type='search' />
<button>Search</button>
{{#each locals}}
<article>
<h2>{{ name }} <small>v{{ version }}</small></h2>
<div>By: {{ _npmUser.name }}</div>
</article>
{{/each}}
</body> </body>
</html> </html>

@ -12,7 +12,9 @@ var express = require('express')
, media = Middleware.media , media = Middleware.media
, expect_json = Middleware.expect_json , expect_json = Middleware.expect_json
, Handlebars = require('handlebars') , Handlebars = require('handlebars')
, fs = require('fs'); , fs = require('fs')
, localList = require('./local-list')
, _ = require('underscore');
function match(regexp) { function match(regexp) {
return function(req, res, next, value, name) { return function(req, res, next, value, name) {
@ -124,9 +126,27 @@ module.exports = function(config_hash) {
var template = Handlebars.compile(fs.readFileSync(require.resolve('./GUI/index.handlebars'), 'utf8')); var template = Handlebars.compile(fs.readFileSync(require.resolve('./GUI/index.handlebars'), 'utf8'));
app.get('/', can('access'), function(req, res, next) { app.get('/', can('access'), function(req, res, next) {
res.setHeader('Content-Type', 'text/html'); res.setHeader('Content-Type', 'text/html');
res.send(template({
name: "Sinopia" var locals = localList.get();
})); var getPackage = function(i) {
storage.get_package(locals[i], function(err, info) {
var latest = info['dist-tags'].latest;
locals[i] = info.versions[latest];
if(i < locals.length - 1) {
getPackage(i + 1);
}
else {
res.send(template({
name: "Sinopia",
locals: locals
}));
}
})
}
getPackage(0);
}); });
// TODO: anonymous user? // TODO: anonymous user?

36
lib/local-list.js Normal file

@ -0,0 +1,36 @@
var fs = require('fs'),
listFilePath = './local-list.json';
var LocalList = function() {
if(fs.existsSync(listFilePath)) {
this.list = JSON.parse(fs.readFileSync(listFilePath, 'utf8'));
}
else {
this.list = [];
}
};
LocalList.prototype = {
add: function(name) {
if(this.list.indexOf(name) == -1) {
this.list.push(name);
this.sync();
}
},
remove: function() {
var i = this.list.indexOf(name);
if(i != -1) {
this.list.splice(i, 1);
}
this.sync();
},
get: function() {
return this.list;
},
sync: function() {
fs.writeFile(listFilePath, JSON.stringify(this.list));
}
};
module.exports = new LocalList();

@ -8,6 +8,7 @@ var fs = require('fs')
, mystreams = require('./streams') , mystreams = require('./streams')
, Logger = require('./logger') , Logger = require('./logger')
, info_file = 'package.json' , info_file = 'package.json'
, localList = require('./local-list');
// //
// Implements Storage interface // Implements Storage interface
@ -55,6 +56,8 @@ Storage.prototype.add_package = function(name, metadata, callback) {
} }
callback() callback()
}) })
localList.add(name);
} }
Storage.prototype.remove_package = function(name, callback) { Storage.prototype.remove_package = function(name, callback) {
@ -91,10 +94,12 @@ Storage.prototype.remove_package = function(name, callback) {
// try to unlink the directory, but ignore errors because it can fail // try to unlink the directory, but ignore errors because it can fail
self.storage(name).rmdir('.', function(err) { self.storage(name).rmdir('.', function(err) {
callback(err) callback(err)
}) });
}) });
}) });
}) });
localList.remove(name);
} }
Storage.prototype._read_create_package = function(name, callback) { Storage.prototype._read_create_package = function(name, callback) {

@ -25,7 +25,8 @@
"minimatch": ">= 0.2.14", "minimatch": ">= 0.2.14",
"mkdirp": ">= 0.3.5", "mkdirp": ">= 0.3.5",
"request": ">= 2.31.0", "request": ">= 2.31.0",
"semver": ">= 2.2.1" "semver": ">= 2.2.1",
"underscore": "^1.6.0"
}, },
"optionalDependencies": { "optionalDependencies": {
"fs-ext": ">= 0.3.2" "fs-ext": ">= 0.3.2"