In episode 29 I showed you how to write a Lumo script, a re-implementation of
tree command, using several of Node’s built-in packages.
In this episode you’ll learn how to publish your script as an NPM package, and
how to make use of third party libraries from NPM and Clojars.
So far this script is just a single file, and it has no dependencies apart from
what ClojureScript and Node provide out of the box.
Let’s try to make it more interesting, by using an npm package to add some color
to the output.
First create a
package.json inside the
birch directory. There’s a handy
init command to help you with that. The defaults are fine for now, just press
enter a bunch of times, or you can add
--yes to accept all defaults.
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
entry point: (index.js)
About to write to /tmp/birch/package.json:
"test": "echo \"Error: no test specified\" && exit 1"
Is this ok? (yes)
Now you can install the
cli-color npm package. Add the
--save flag, this way
cli-color gets added as a dependency in
package.json. This also adds a
node_modules directory which contains the downloaded package. If you’re
planning to make a git repo for this project then make sure to exclude this
directory from version control.