From this excellent article by Kamil Ogórek. For more detail and the reasoning behind using the tools read the article.
This will set up a dev environment for a JavaScript project in less than 5 minutes, includes linting with Standard, and testing suite Ava. It also uses Chokidar-cli for file watching and Precommit-hook for running npm scripts automatically.
For a fresh install just run the code below or if you want to clone this repo there are dummy modules and tests already here.
# Create a directory and cd into it (#protip – $_ holds argument of your last command)
$ mkdir awesome-module && cd $_
# Initialize Node.js project with default settings
$ npm init --yes
# Create initial folders and files
$ mkdir lib test
$ touch index.js lib/meaningOfLife.js test/index.test.js test/meaningOfLife.test.js
# Initialize GIT repository and create initial commit
$ git init
$ git add -A; git commit -am "init project"
# Install the tools
$ npm i --save-dev ava standard chokidar-cli precommit-hook
# Create .gitignore
$ touch .gitignore && echo 'node_modules' > .gitignore
"scripts": {
"test": "ava",
"lint": "standard",
"dev": "chokidar '**/*.js' -c 'standard && ava'"
},
"pre-commit": ["test", "lint"],
That's it, run npm run dev
to get all files linted by Standard and tests run by Ava.
Git commits won't happen unless all tests are green and the linter is happy.
Tests and modules have been created to look at in this repo.