DEV Community

Richard Leddy
Richard Leddy

Posted on

get-npm-assets for an easier installation

It's easy enough to do a post install in your npm package. But, after a while, package after package, the shell scripting gets tedious.

I have some packages that install executable node.js scripts in the npm global bin directory. Then, I had to go fishing around for a template for the config file. I just wanted a command that would get the stuff for me. And, I needed the command to run for a particular script in the bin directory.

Maybe it's out there. But, it seemed easy enough to make and pass on. So, today, I made get-npm-assets.

You can read the Read.me to see how to make use of it.

Just to give you a highlight, I have already put it to use for one of my other packages copious-endpoints. For that, I made a asset-map.json file. This file maps the bin scripts released by copious-endpoints to the files that are needed to run each program.

Here is the file contents:

{
    "copious-contacts" : "contact-service.conf",
    "copious-user" : "relay-service.conf"
}
Enter fullscreen mode Exit fullscreen mode

This is file relates to the bin field in package.json. Here is the bin field from the module's package.json file:

  "bin" : {
    "copious-user" : "./bin/endpoint-user.js",
    "copious-contacts" : "./bin/endpoint-contacts.js",
    "add-mini-links" : "./bin/add-mini-links.js"
  },
Enter fullscreen mode Exit fullscreen mode

So, to use one of the programs released the user will need to call something like this:

$copious-user relay-services.conf
Enter fullscreen mode Exit fullscreen mode

But, where is that file? What should it look like? If I knew once, what if it changed?

But, I could call get-npm-assets as follows:

$get-npm-assets copious-user
Enter fullscreen mode Exit fullscreen mode

Now, as a user, I don't have to look into the module directory to get an example. And, this version of the command will get the relay-services.conf instead of contact-service.conf.

You an also set up an assets directory and have the whole directory copied into a local assets directory that get-npm-assets will make for you.

Enjoy. Please leave issues in the github repository.

Top comments (0)