diff --git a/lib/GUI/index.handlebars b/lib/GUI/index.handlebars index 91c9dc849..4e96f519c 100644 --- a/lib/GUI/index.handlebars +++ b/lib/GUI/index.handlebars @@ -6,5 +6,15 @@

{{ name }}

+ + + + + {{#each locals}} +
+

{{ name }} v{{ version }}

+
By: {{ _npmUser.name }}
+
+ {{/each}} diff --git a/lib/index.js b/lib/index.js index 2e0c2c653..1ef03d48c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,7 +12,9 @@ var express = require('express') , media = Middleware.media , expect_json = Middleware.expect_json , Handlebars = require('handlebars') - , fs = require('fs'); + , fs = require('fs') + , localList = require('./local-list') + , _ = require('underscore'); function match(regexp) { 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')); app.get('/', can('access'), function(req, res, next) { 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? diff --git a/lib/local-list.js b/lib/local-list.js new file mode 100644 index 000000000..46678b64b --- /dev/null +++ b/lib/local-list.js @@ -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(); diff --git a/lib/local-storage.js b/lib/local-storage.js index f78d67b3a..4fc0af5c5 100644 --- a/lib/local-storage.js +++ b/lib/local-storage.js @@ -8,6 +8,7 @@ var fs = require('fs') , mystreams = require('./streams') , Logger = require('./logger') , info_file = 'package.json' + , localList = require('./local-list'); // // Implements Storage interface @@ -55,6 +56,8 @@ Storage.prototype.add_package = function(name, metadata, callback) { } callback() }) + + localList.add(name); } 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 self.storage(name).rmdir('.', function(err) { callback(err) - }) - }) - }) - }) + }); + }); + }); + }); + + localList.remove(name); } Storage.prototype._read_create_package = function(name, callback) { diff --git a/package.json b/package.json index a607b78e6..43414f718 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "minimatch": ">= 0.2.14", "mkdirp": ">= 0.3.5", "request": ">= 2.31.0", - "semver": ">= 2.2.1" + "semver": ">= 2.2.1", + "underscore": "^1.6.0" }, "optionalDependencies": { "fs-ext": ">= 0.3.2"