Skip to content

Instantly share code, notes, and snippets.

@zoe-1
Created April 3, 2015 13:44
Show Gist options
  • Save zoe-1/784100440f0cf2299010 to your computer and use it in GitHub Desktop.
Save zoe-1/784100440f0cf2299010 to your computer and use it in GitHub Desktop.
Why use a Makefile with node.js project
start:
npm start
install:
npm install
test:
npm test
cov:
npm run test-coverage
cov-html:
npm run test-coverage-html
cov-mac:
npm run test-coverage-html
open -a Safari ./test/coverage.html
@zoe-1
Copy link
Author

zoe-1 commented Apr 3, 2015

Why use a Makfile
The Makefile is useful for automating tasks in your project.
npm commands can execute automated tasks but they can get very long. Long commands are inconvenient to type over and over.

For example, npm allows you to run two commands related to executing scripts by default: "npm start" and "npm test". If you make other custom npm commands in the scripts section, they will fail without "run" preceding the command.

ex) "npm run command_name" // illustrates a command with run before it.

The below command will list npm commands that do not need a "run" before them.
npm --help command // (Commands test and start are included here).

Look at: https://github.com/zoe-1/nmax/blob/master/package.json to see a package.json file with a significant amount of scripts commands in them. Commands are made in the scripts:{ } section.

In the above linked package.json file there is the below command:

"protractor": "protractor test/protractor-conf.js"

To execute this command you must type: "npm run protractor". "npm protractor" without will not work .
"npm run protractor" will run tests on the project. The command is a long. So, let's use a Makefile to
simplify the command.

Put in your Makefile:

pro:
   npm run protractor

Then type:

make pro

And, the long "npm run protractor" command will be executed.

As a project develops you will need automate tasks like:

  1. changes to the configuration state (live versus development states)
  2. execution of tests
  3. server start up
  4. and others....(For example, git push commands to different remote repos)

In this assignment, I believe Eran is showing us how to use the Makefile as a convenient method
to manage and execute our projects most important automated tasks.

@ardibello
Copy link

If you use yarn, then you will not need the extra run like you do with npm. You could just run yarn protractor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment