Closed seanewest closed 10 years ago
I love this idea, and have had it on my mind as well. Would happily merge a PR.
@seanewest perhaps, for this use-case, ndm could interview the user for environment variables while generating the scripts directly from the package?
Yeah I think thats a good idea to interview automatically when generating a global package
How does this sound:
:boom: treat the globally installed package just like a single node-packaged service, where we basically pull all of the bin/scripts/env/args from the package.json
, which could include hints for the interview process.
:boom: packages can optionally include a service.json
. I was assuming no sub-services like an ndm wrapper though.
:boom: commands supported (at least for now?): generate
start
stop
restart
. Technically there could be a namespace collision with ndm start <service-name>
and ndm start <package-name>
when you are in the folder of an ndm wrapper but I was thinking we could just allow that.
Edit: I accidentally deleted this message and reposted it. Had to inspect the html in devtools to get the message back!
@seanewest this sounds like exactly what I was picturing. Any thoughts about how we'll figure out where the global npm modules are installed? I bet we can include a dependency from the npm-cli to introspect this.
I was just figuring we could use <prefix>/lib/node_modules
no?
As in the following code:
var npm = require('npm')
var path = require('path')
var pkg = 'myservice' //as in ndm <cmd> myservice
npm.load(function (er, npm) {
var prefix = npm.config.get('prefix')
var pkg_path = path.join(prefix, 'lib', 'node_modules', pkg)
console.log(pkg_path)
})
That seems nice and simple.
On Sunday, July 27, 2014, seanewest notifications@github.com wrote:
I was just figuring we could use
/lib/node_modules no? As in the following code:
var npm = require('npm')var path = require('path')var pkg = 'myservice' //as in ndm
myservice npm.load(function (er, npm) { var prefix = npm.config.get('prefix') var pkg_path = path.join(prefix, 'lib', 'node_modules', pkg) console.log(pkg_path)}) — Reply to this email directly or view it on GitHub https://github.com/npm/ndm/issues/39#issuecomment-50286296.
@seanewest I like the idea that ndm start service
would first look for a local service.json, and then fall back to looking in the global packages directory, a couple questions:
ndm start
.ndm start
runs interview
-> generate
-> start
.I could see this being a simpler flow.
@seanewest I think that this, https://github.com/npm/ndm/pull/47/files, gets things part of the way towards what you're looking for.
I needed this myself to make it easier to deploy services directly from packages.
Awesome! That helps a lot. Sorry I haven't been able to work on this, I can take a crack at it this weekend.
On Wednesday, July 30, 2014, Benjamin E. Coe notifications@github.com wrote:
@seanewest https://github.com/seanewest I think that this, https://github.com/npm/ndm/pull/47/files, gets things part of the way towards what you're looking for.
I needed this myself to make it easier to deploy services directly from packages.
— Reply to this email directly or view it on GitHub https://github.com/npm/ndm/issues/39#issuecomment-50660488.
What about adding ndm as a dependency and using an API to allow module authors to write an install command/sub-command? It sounds like feature/scope creep, but I think it would actually help curb such creep by letting module authors handle their special cases on their own without requiring extensions to ndm that nobody has thought of yet.
@rmg I like the simplicity of this. A module author could:
start
, stop
, restart
, install
, uninstall
bins.and, boom self-installable service. I think we actually have everything we need to do this already, although we might want to write some tests around the use-case + documentation.
Then the module author could use ndm programatically in their custom installer so they could do extra things like create users, files, directories, whatever, as part of the interview/install process without ndm needing to add explicit support for such actions.
I would love to be able to ship an npm package (with a service.json) that can be installed as a service, right away, like so:
Same goes for start/stop etc.
Currently one has to create a wrapper around services that are dependencies. I can understand this setup in a devops environment where you want to package together and distribute services, and in addition with specific args for ports etc.
But I think it would also be cool if in addition there was a more basic use case where you could just start an individual service directly from the npm package, without creating a wrapper at all.
If I'm not mistaken to pull this off you would need to allow top-level scripts in the service.json, right next to the top-level args and env.
I'd be more than willing to send a PR if this sounds like something that could get merged.