In lab 7 I was assigned the task to explore and learn about open source tooling and automation. I found this lab to be useful and learned some interesting things from it.
I did this lab by first creating a repository on GitHub. This repository will be expanded on in the coming weeks. It is a starting point to learning open source tools. I initialized the repository with a README.md file, added a .gitignore for node, and added a license using the MIT license.
Here is a link to my repository: https://github.com/badrmodoukh/Seneca2017LearningLab
After that I cloned the repository using:
git clone email@example.com:badrmodoukh/Seneca2017LearningLab.git
After the repository was cloned I initialized the package.json file using npm. This created the package.json file and included the information I set. The steps I took to accomplish this are:
- npm init
- entered the name, version, description, entry point, license
I implemented the isValidEmail and formatSenecaEmail functions in this file. This is the end result of that file:
The isValidEmail function checks to see if the passed in email is a valid Seneca email. The formatSenecaEmail function creates a Seneca email using the string that was passed into the function.
Once I finished implementing these functions I wanted to test my work and see if the functions did what they are suppose to do. In order for me to test my work I needed to write a simple command line tool that uses seneca.js.
I accomplished this task by following the steps done in this tutorial: Building command line tools with Node.js.
These are a summary of the steps I did:
- created an index.js file
- added a shebang (#!/usr/bin/env node) to the beginning of the file
- added a bin section in the package.json file with a property key “seneca” and property value “./index.js” which is the script that will run the seneca.js module
- used “commander” npm package to receive arguments
- defined the options to use
- installed shell command using npm install -g
Here is how the index.js file looks at the end:
This enabled me to test my seneca.js module by running the commands:
“seneca -v <seneca email>” which checks if the Seneca email is valid
“seneca -f <name>” which creates a Seneca email with the given name.
“seneca –help” which displays the options available to use this command
Here is how this looks:
After I tested the functions I implemented I needed to add ESLint to avoid common problems in my code.
I accomplished this by doing these steps:
- npm install eslint –save-dev (which installs eslint and adds it to the development dependencies in the package.json file)
- create a configuration for eslint using ./node_modules/.bin/eslint –init
- selected JSON format the eslint config file
This created a new file called .eslintrc.json.
After I configured eslint I ran it to check the seneca.js file and it showed me a couple of warnings that are “Unexpected unnamed function”.
I fixed this error by adding the function name to the function. ESLint Rules provides all the errors that can occur and how to fix them.
I added a script to the package.json file to always check my code when I make changes.
The final step I did was to use TravisCI. I thought using TravisCI will be a difficult task to accomplish but surprisingly it was very simple to add to the repository.
I followed the steps on Getting started to accomplish this task. I found these steps to be really easy to follow and clear.
Here is a summary of what I did to add TravisCI to my repository:
- signing in to Travis CI using my GitHub account
- Enabling Travis CI for my specific repository
- created a .travis.yml file for a node project to tell Travis CI what to build
Here is the link to my TravisCI build: TravisCI build for lab
Finally at the end I added the Travis CI build badge by copying the code in the Travis CI website. I did this by following these steps Embedding Status Images.
I learned a lot from doing this lab and found it to be really useful and interesting. The tools that are used in this lab such as ESLint and Travis CI are used in many other open source projects and being able to understand how to add them to a project I found to be really useful. Now I understand how other open source projects add these tools to their repositories.