DEV Community

Francesco Menghi
Francesco Menghi

Posted on

Supporting JSON config file

This week, I worked on Leyang Yu Static Site Generator project called jellybean. I added a new issue on her repo to let her know that I wanted to add a new --config option to support a JSON config file. Luckily she agreed, so I got started right away.

After forking her repo and cloning the fork to my local machine, I create and switched to a new local branch called issue-15 by doing:
git checkout -b issue-15.

On this branch I made the necessary changes to allow the program to work with a JSON config file. To do that I used the node module jsonfile to read the content of the JSON file and save it into argv:

argv = jsonfile.readFileSync(argv.config, (err) => {
    if (err) console.error(err);
Enter fullscreen mode Exit fullscreen mode

Of course I also had to add the option for --config and -c to yargs (The node module used to parse arguments from the command line):

.option('config', {
    alias: 'c',
    describe: 'Path to a JSON config file',
    type: 'string'
Enter fullscreen mode Exit fullscreen mode

Once I had an initial version, I wanted to know what Leyang thought of it, so I pushed the branch to my copy of the jellybean repo (git push origin issue-15) and opened a draft Pull Request. This is a great way to show the work in progress to the project maintainer.

I received some feedback from her and made the requested changes. While doing that, I noticed other bugs that escaped me at the beginning (For example I was not checking if path.extname(input) == '.json').

We had one more round of back and forth and finally my Pull Request was merged into the repo. This made me realize how important it is to get a second pair of eyes looking at the my code. I also learned that I need to do a lot more testing before being ready to push my code for a PR.

Discussion (0)