DEV Community

mpa-LHutchinson
mpa-LHutchinson

Posted on

Week 12: Lab 9: Packaged release

Introduction

In this weeks lab, I learned how to package my project and put it out there for others to be able to use. This allowed me to publish my package on npm and anyone can now access and use it on their own computer without having to clone my projects repository. In this blog, I will be going over how I managed to do this and the challenges I faced along the way.

Which release tool and package registry did you choose? Provide links to everything you mention.

For this lab, I used npm as my packaging tool for my project. This is because my project uses node, and npm is by far the most popular packaging tool for node projects. Here's the link for npm and how you can get started contributing packages to the registry:

https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry

What was the process for creating a release? Be detailed so that other developers could read your blog and get some idea how to do the same.

The process of creating a release involved first involved me modifying my package.json file to include a name and version of my project. I would update the version with this command:

npm version patch

This would update the version from 0.0.1 for example to 0.0.2, and this is what I would do until I was comfortable with my version of the project, in which I would run

npm version major

Which would upgrade to version 1.0.0. But before that I still had a lot to add.

I created my first package, by running

npm pack

This would create a .tgz folder where the package could be uploaded. Then I would run

npm login
npm publish

In order to login to npm and publish the package. However, I realized there is already an npm package with the name auto-readme. So I just named the package auto-readme-liam and then I could publish it. This is how my first version of the package, 0.0.1 was uploaded. But it wasn't over, as there was more I had to add.

I needed to add this to my package.json:

"bin": {
"auto-readme-liam": "./index.js"
}

This would allow the user to run a script that runs the program. I also added this to the top of my index.js file:

#!/usr/bin/env node

There were some other issues, but I'm gonna go over them in the next question since it's more fit there. Once I fixed these issues however, I updated my README file to include instructions on installing the package.

What did you learn while doing your release? Did you have any "aha!" moments or get stuck?

I actually learned something about my project that was an issue. When I was testing my package release, I realized the README file that my program was supposed to generate was not generating in the proper directory. This, I figured out, was because my project would use _dirname in some parts, for example this:

var generatedFilePath = path.join(__dirname, readmeFileName);

However, _dirname in this case would end up being the global node_modules folder, since it was installed globally. To fix this, I replaced all instances of _dirname with process.cwd(), which refers to whatever directory the script is being executed in. I tested this and updated my package, and luckily it worked now. I'm glad I caught this problem, and if I ever make similar projects in the future I'll remember to do this.

How much did you have to alter your code, files, build, etc. to use the chosen package format and registry?

As you can see from the above questions, I didn't have to add a ton of new changes to my code. I just had to change around 5 lines in my index.js file and I had to add about 3 new things to my package.json file. The simplicity of node.js allowed me to upload my project to node easily.

How did the User Testing session with your partner go? Describe what it was like, where they got stuck, and how you corrected the problems.

Luckily testing this with a partner went pretty well. The only thing I needed to change was the instructions in my README for how to provide an api key, as the command to do it was slightly different in command prompt compared to the visual studio terminal for example. Once I found this out, I updated my README to give the user more clear instructions.

How do users install and use your project now that it has been released? Provide links and some instructions.

These instructions come straight from the README file of the official package release of my project. If you'd like to check it out, here's the link:

https://www.npmjs.com/package/auto-readme-liam

First, install the package:

npm install -g auto-readme-liam

Then, provide your API key as an environment variable:

set GROQ_API_KEY="<YourAPIkey>"

Once you do this, run this command:

auto-readme-liam

And now you're set! You can also run this command for help:

auto-readme-liam --h

Top comments (0)