'use strict';

var path = require('path')
, basename = path.basename(__filename, '.js')
, debug = require('debug')('dm:server')
, fs = require('fs')
;

module.exports = function (packagename) {
  var names = [ packagename, 'dm-' + packagename ];
  var m = function (name) {
    try {
      return { manifest : require.resolve(name + '/manifest.json'), name : name };
    }
    catch (e) {
      debug('error', e);
      return;
    }
  };
  var r = function (prev, cur) {
    return prev === undefined ? cur : prev;
  };
  var plugin = names.map(m).reduce(r, undefined);

  if (!plugin) {
    return;
  }

  var manifest = require(plugin.manifest);
  var stat = fs.statSync(plugin.manifest);
  manifest.packagename = plugin.name;
  manifest.url =  '/' + manifest.id;
  manifest.accessed = stat.atime;
  manifest.updated = stat.mtime;
  manifest.published = stat.ctime;

  return manifest;
}

@@ -291,16 +291,24 @@
 return %7B
+%0A       
  manifes
@@ -352,16 +352,83 @@
 .json'),
+%0A        package : require.resolve(name + '/package.json'),%0A       
  name : 
@@ -431,16 +431,22 @@
 e : name
+%0A     
  %7D;%0A    
@@ -467,33 +467,8 @@
 ) %7B%0A
-      debug('error', e);%0A
     
@@ -775,24 +775,70 @@
 lugin.name;%0A
+  manifest.package = require(plugin.package);%0A
   manifest.u

load package.json