puddi
Puddi is a node.js library for dependencies managing, made for people who hate managing them.
It works by adding a single raw file for each module, which describes its internal specificities.
To install puddi, a simple npm install puddi
should be sufficient.
module.yml
The file is encoded using the YAML syntax. (JSON is great, but not really human- readable.)
module: name: my_module depends: - other_module - another_module.child_module
examples
Assuming you want to create a javascript game, you will probably have a client and a server, and some shared structures. So your file hierarchy should be :
- application
- structure
- client
- server
We have four modules here. The structure module, which will contain our shared data structures, the modules for both the client and the server and, lastly, the main application module.
Using puddi, our file hierarchy will become :
- application
- structures
- module.yml
- client
- module.yml
- server
- module.yml
- module.yml
- structures
The structures module doesn't depend on anything, but the client and the server modules both depend on the structures module, and the application module depends on both the client and the server modules.
So this is what the module.yml file should be like :
application
module: name: application depends: - client - server
client
module: name: client depends: - application.structures
server
module: name: server depends: - application.structures
structures
module: name: structures
Note that a module inherits its super module's scope. So instead of
application.structures
, we can simply write structures
. It's juste a matter
of verbosity.
Now, using puddi, you can simply select the module to resolve (assuming you are in your application directory) :
puddi . application.client --print | xargs -n 1 echo "Client-side application contains this module :"
puddi . application.server --print | xargs -n 1 echo "Server-side application contains this module :"
Only the required module and its dependencies will be printed, in a dependencies-aware order.
If, for some reason, one of your folders' name contains a line return, the
output will be broken. In that case, replace --print
with --print0
, which
will use a null character as a separator. You will then be able to efficiently
split the output with a command like xargs
with its -0
option.
usefuls examples
What we have done is not fun. Who dares about print some folders path in a specific order ?
But modern shells are powerful. Very powerful. And same is for node libaries !
Using the power of the xargs
, you will be able to execute binaries in a
specific order, and do some magic with it.
For instance (bash file) :
#!/usr/bin/env bash # Want to check your code with JSHint ? forEachJavascriptFile . application jshint # This will process every client files using UglifyJS, and write the output in the build folder forEachJavascriptFile . application.client uglifyjs > build/client.jsforEachJavascriptFile . application.server uglifyjs > build/server.js
puddi as node.js library
You can obviously use Puddi as a node.js library.
Very simple showcase :
var puddi = ; puddi;