mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
Added listings
This commit is contained in:
parent
bb129c1151
commit
34b631fa12
@ -6,5 +6,15 @@
|
||||
</head>
|
||||
<body>
|
||||
<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>
|
||||
</html>
|
||||
|
28
lib/index.js
28
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?
|
||||
|
36
lib/local-list.js
Normal file
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')
|
||||
, 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) {
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user