[nodejs] Re: finding modules matching a name glob

2012-04-22 Thread phidelta
The problem with doing this via npm is that npm works with the
dependencies from the package.json which is a problem for plugins,
since they are seldom known at the time the package.json is writeen.

I have done something like this for my app. What I ended up doing is
simply defining a folder which all plugins have to be in.

function requirePlugins(plugindir) {
  require('fs').readdirSync(plugindir).map(function(item) {
return require('path').resolve(plugindir, item);
  }).forEach(function(plugin) {
if (/\.plugin$/.test(plugin)) require(plugin);
  });
}

on start-up I simply call

requirePlugins(require('path').resolve('./plugins'));

This avoids traversing a billion directories, and does what you need.
It is synchronous of course, but that is true for require anyhow and
does not matter much since it is ever only called on start-up.

Regards, Philipp

On Apr 21, 8:04 pm, Mike Pilsbury mike.pilsb...@gmail.com wrote:
  So doing an `npm ls` from a process is the only way to go?  Whatever it
  takes.

  It looks 
  likehttp://npmjs.org/doc/README.html#Using-npm-Programmaticallyoffers

 another option.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups nodejs group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en


Re: [nodejs] Re: finding modules matching a name glob

2012-04-22 Thread Mark Hahn
   What I ended up doing is simply defining a folder which all plugins
have to be in.

That seems to be a good minimalist approach.

One requirement for this project is for plugin developers to be able to
easily publish their plugins so that every app user can select which
plugins to use.  So some kind of public repository, or registry, is needed
to drop in plugins.  So I either use the npm registry or somewhat duplicate
it's functionality.

Then I need the modules installed locally.  Putting them all in a single
folder works for this.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups nodejs group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en