Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodemon refactor & JSON config #200

Merged
merged 121 commits into from Dec 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
5f863dd
Added nodemon.json to add ignore files
pasindud May 29, 2013
7ca27b0
Added nodemon.json file
pasindud May 29, 2013
af0003b
Merge remote-tracking branch 'nodemon/master'
pasindud Jun 9, 2013
3a96abd
Nodemon json file var
pasindud Jun 9, 2013
37e0894
clean nodemon json
pasindud Jun 9, 2013
be894dc
nodemon json variable meaning ful
pasindud Jun 9, 2013
9bae958
Merge branch 'master' of git://github.com/pasindud/nodemon into featu…
remy Jun 24, 2013
5da131d
starting the complete rewrite of nodemon in to tiny testable modules
remy Aug 1, 2013
1708d14
initial tests for rules
remy Aug 2, 2013
3efca97
Argument parsing, and executable support and tests
remy Aug 4, 2013
c5f2bee
Testing the exec rules and the parser
remy Aug 5, 2013
56663f5
Trying to simplify the chain of nodemon process
remy Aug 7, 2013
30fb321
reporter: dot => spec for better visibility on travis
remy Aug 7, 2013
5293f08
fixed parse test expectation
remy Aug 7, 2013
5d44ebb
still in progress - lots of file laying out
remy Aug 19, 2013
9fd778e
Tests pass. Using process.emit('nodemon:*'), nodemon starts and trigg…
remy Aug 19, 2013
84a461f
Basic running and restarting working
remy Aug 25, 2013
9cb84a8
Add node 0.6 to tests
remy Oct 27, 2013
b2a4328
Using odd version to flag dev release
remy Oct 27, 2013
d90fee7
Loading .json files, parsing cli & detailed output
remy Oct 29, 2013
9a86e7b
Fixed cli parser so that it add watch, ignore, etc
remy Oct 29, 2013
c5aa368
Updated tests to read new options location
remy Oct 29, 2013
69c7147
removed colors dep
remy Oct 29, 2013
b984783
0.9.1
remy Oct 29, 2013
ed040ed
node 0.6 compat
remy Oct 29, 2013
aceee64
Fixed #216. If --exec is used, don't try to detect userScript
remy Oct 29, 2013
ccd20a5
0.9.2
remy Oct 29, 2013
817e226
Custom merge with tests
remy Oct 30, 2013
565f59d
0.9.3
remy Oct 30, 2013
81eb5ef
Fixed `nodemnon .` and nodemon.json loaded before flags set
remy Oct 30, 2013
c67fbe4
0.9.4
remy Oct 30, 2013
fcc843c
Test confirming fix for #212
remy Oct 30, 2013
cc44b58
Fixed extension watching and fixed perf bug in check
remy Oct 31, 2013
55d09b0
0.9.5
remy Oct 31, 2013
0b0d31c
Got the logic in reverse with config merge
remy Oct 31, 2013
e983d00
0.9.6
remy Oct 31, 2013
c7f5016
Only reset search time /after/ file changes detected
remy Oct 31, 2013
d25228c
Beginning of more docs
remy Oct 31, 2013
71df2ce
Windows friendly slash
remy Oct 31, 2013
b56e4d2
Add code coverage metrics
matthew-andrews Oct 31, 2013
9063479
Merge pull request #219 from matthew-andrews/feature/json-config
remy Nov 12, 2013
f6887c9
making main based off the module, not the "binary"
remy Nov 12, 2013
31eeeee
Merge branch 'feature/json-config' of github.com:remy/nodemon into fe…
remy Nov 12, 2013
2909a17
First tests to ensure nodemon is actually restarting correctly
remy Nov 14, 2013
5cee0cf
0.9.7
remy Nov 14, 2013
ed480b6
Allowing 5sec for mocha to run. Also better clean up on test exit
remy Nov 14, 2013
f76560c
0.9.8
remy Nov 14, 2013
eef9efc
Capture error on simple running
remy Nov 20, 2013
a7fe84f
Legacy mode working again and Vagrant working ok
remy Nov 20, 2013
21ba614
trying to get nodemon start tests to pass on linux - problems with fs…
remy Nov 20, 2013
a2d67ec
0.9.9
remy Nov 20, 2013
d7c3647
Using event bus for tests and requirable nodmeon
remy Nov 25, 2013
bbe6632
merge up
remy Nov 25, 2013
c503222
Refactoring.
remy Dec 3, 2013
59e0135
More test off of lib
remy Dec 3, 2013
306eb6c
0.9.10
remy Dec 3, 2013
ccb050b
Copy across fix #228
remy Dec 3, 2013
6157225
Start initial watch right away - fixes timing issues in tests
remy Dec 3, 2013
3e000fa
Removed redundant test
remy Dec 3, 2013
c8d59ff
Removes support for node 0.6 in nodemon 0.9.x and upwards
remy Dec 3, 2013
9853e08
Fixed #118 plus a bunch of jshint fixes
remy Dec 4, 2013
e777dea
jshint cleaning
remy Dec 4, 2013
ae184b7
Passing tests on linux
remy Dec 4, 2013
8dbaf0a
0.9.11
remy Dec 4, 2013
d092d71
Ignore .git & node_modules/**/node_modules by default. Closes #230
remy Dec 5, 2013
975e535
0.9.12
remy Dec 5, 2013
871ecd4
removed old tests and old nodemon...whoooo
remy Dec 5, 2013
90f3bcd
Test help
remy Dec 5, 2013
80fbaca
unsure whether exit.js was ever used
remy Dec 5, 2013
48855d0
More test coverage
remy Dec 5, 2013
4785409
tweaks to copy
remy Dec 5, 2013
c5a5c88
tweaking numbers to test travis
remy Dec 5, 2013
71d6f2d
just because.
remy Dec 6, 2013
abc27cd
Correct signal passing. Fixes #232.
remy Dec 10, 2013
62a5415
Fixed default *.js restart option
remy Dec 10, 2013
999a8d6
0.9.13
remy Dec 10, 2013
e8118ce
Was throwing exception on version check
remy Dec 10, 2013
93ab2b0
Updating FAQ & authors
remy Dec 10, 2013
ffe5a55
Fixed test to check ignore rules
remy Dec 10, 2013
dad51cf
Simplified ignore test (was true twice on mac)
remy Dec 10, 2013
999f87e
Support for execMap #195 and tests
remy Dec 10, 2013
eed651f
0.9.14
remy Dec 10, 2013
6877d57
On exception, ask for issue to be filed
remy Dec 10, 2013
86d13db
Merged #231 allowing for multiple nodemons (I think!)
remy Dec 10, 2013
7197107
Moved coverage to it's own npm command
remy Dec 10, 2013
40aad4d
Ensure --debug is slupped correctly. Fixes #226.
remy Dec 10, 2013
93b8895
rules.reset() wasn't working at all!!!
remy Dec 11, 2013
3fe5f04
Removed config/init.js and moved to index.js
remy Dec 11, 2013
417a4c6
Now loading old style nodemonignore configs
remy Dec 11, 2013
b4b3d90
fixtures for legacy nodemonignore files
remy Dec 11, 2013
05e5cec
test for --debug=X
remy Dec 11, 2013
4f5593d
Fix nodemon.config.required flag, and expose config
remy Dec 11, 2013
3f9a003
Better coverage of cli/parse lib
remy Dec 11, 2013
fe27740
Re-introducing require tests
remy Dec 11, 2013
4edea10
0.9.15
remy Dec 11, 2013
ad0eba3
Required nodemon, upon quit, correctly unwatches files
remy Dec 12, 2013
36e779d
Testing required restart
remy Dec 12, 2013
0594917
0.9.16
remy Dec 12, 2013
c7d18c0
Fix require test. Reset event state after complete
remy Dec 12, 2013
21acd84
MOAR test coverage. 71% - good enough for 1.0.0 release
remy Dec 12, 2013
bf8c20c
fixed watchable tweak
remy Dec 12, 2013
8d5214c
fixed merge cockup
remy Dec 12, 2013
f5a568b
Documenting the event system in nodemon for require & spawn
remy Dec 13, 2013
6a57446
restart is both a state and command
remy Dec 13, 2013
5c7af6b
More tests. 79% code coverage + more docs
remy Dec 14, 2013
996d9ae
Removed rules.test as it wasn't used
remy Dec 14, 2013
713950a
cleanly remove rules.test
remy Dec 14, 2013
86d3228
Passing all tests on linux
remy Dec 14, 2013
1fcc30d
Fixing coffeescript tests for windows
remy Dec 15, 2013
c5ca025
More coffeescript tests passing on windows
remy Dec 15, 2013
9ef2ccd
more coffeescript windows support
remy Dec 15, 2013
96cd53c
Windows support, note to self: path.sep
remy Dec 15, 2013
a0e7a57
0.9.17
remy Dec 16, 2013
2dc197a
fixed watching multiple extensions
remy Dec 20, 2013
52e8a70
Adding website for nodemon.io
remy Dec 29, 2013
14be08a
Tweak procfile
remy Dec 29, 2013
ab46402
78 tests passing on mac.
remy Dec 29, 2013
0735109
show which config is loaded
remy Dec 29, 2013
30a4a19
Docs and 1.0.0 release. Whoop whoop!
remy Dec 29, 2013
9673b84
Use update-notifier to keep nodemon up to date
remy Dec 29, 2013
80379a7
Merge branch 'master' into feature/json-config
remy Dec 29, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ results

npm-debug.log
node_modules
coverage
14 changes: 14 additions & 0 deletions .jshintrc
@@ -0,0 +1,14 @@
{
"browser": true,
"camelcase": true,
"curly": true,
"devel": true,
"eqeqeq": true,
"forin": true,
"indent": 2,
"noarg": true,
"node": true,
"quotmark": "single",
"undef": true,
"unused": true
}
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,9 +1,9 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
before_script:
- npm install -g coffee-script
- npm install
notifications:
email: false
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,8 @@
# Contribute

WIP - but here's the TL;DR

- .jshintrc
- new command line options are generally discouraged
- ensure style is consistent
- add tests for newly added code (and try to mirror directory and file structure if possible)
134 changes: 82 additions & 52 deletions README.md
@@ -1,16 +1,11 @@
# nodemon

[![Flattr this](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/1211372/remynodemon-on-GitHub)
For use during development of a node.js based application.

For use during development of a node.js based application.

nodemon will watch the files in the directory where nodemon was started, and if they change, it will automatically restart your node application.
nodemon will watch the files in the directory that nodemon was started, and if they change, it will automatically restart your node application.

nodemon does **not** require *any* changes to your code or method of development. nodemon simply wraps your node application and keeps an eye on any files that have changed. Remember that nodemon is a replacement wrapper for `node`, think of it as replacing the word "node" on the command line when you run your script.

[![NPM version](https://badge.fury.io/js/nodemon.png)](http://badge.fury.io/js/nodemon)
[![Travis Status](https://travis-ci.org/remy/nodemon.png)](https://travis-ci.org/remy/nodemon)

# Installation

Either through forking or by using [npm](http://npmjs.org) (the recommended way):
Expand Down Expand Up @@ -43,102 +38,137 @@ You can also pass the debug flag to node through the command line as you would n

If you have a `package.json` file for your app, you can omit the main script entirely and nodemon will read the `package.json` for the `main` property and use that value as the app.

# Automatic re-running
Also check out the [FAQ](https://github.com/remy/nodemon/blob/master/faq.md) or [issues](https://github.com/remy/nodemon/issues) for nodemon.

## Automatic re-running

nodemon was original written to restart hanging processes such as web servers, but now supports apps that cleanly exit. If your script exits cleanly, nodemon will continue to monitor the directory (or directories) and restart the script if there are any changes.

## Manual restarting

Whilst nodemon is running, if you need to manually restart your application, instead of stopping and restart nodemon, you can simply type `rs` with a carridge return, and nodemon will restart your process.

## Config files

nodemon supports local and global configuration files. These are named `nodemon.json` and can be located in the current working directory or in your home directory.

nodemon was originally written to restart hanging processes such as web servers, but now supports apps that cleanly exit. If your script exits cleanly, nodemon will continue to monitor the directory (or directories) and restart the script if there are any changes.
The specificity is as follows, so that a command line argument will always override the config file settings:

# Manual restarting
- command line arguments
- local config
- global config

Whilst nodemon is running, if you need to manually restart your application, instead of stopping and restarting nodemon, you can simply type `rs` with a carriage return, and nodemon will restart your process.
A config file can take any of the command line arguments as JSON key values, for example:

# Running non-node scripts
{
"verbose": true,
"ignore": ["*.test.js", "fixtures/*"]
"execMap": {
"rb": "ruby",
"pde": "processing --sketch={{pwd}} --run"
}
}

The above `nodemon.json` file might be my global config so that I have support for ruby files and processing files, and I can simply run `nodemon demo.pde` and nodemon will automatically know how to run the script even though out of the box support for processing scripts.

Note that `ignore` and `watch` values are *merged* with your CLI arguments, rather than overwritten.

A further example of options can be seen in [sample-nodemon.md]()

*This section needs better documentation, but for now you can also see `nodemon --help config` ([also here]())*.

## Running non-node scripts

nodemon can also be used to execute and monitor other programs. nodemon will read the file extension of the script being run and monitor that extension instead of .js if there's no .nodemonignore:

nodemon --exec "python -v" ./app.py

Now nodemon will run `app.py` with python in verbose mode (note that if you're not passing args to the exec program, you don't need the quotes), and look for new or modified files with the `.py` extension.

# Monitoring multiple directories
### Default executables

Using the `nodemon.json` config file, you can define your own default executables using the `execMap` property. This is particularly useful if you're working with a language that isn't supported by default by nodemon.

To add support for nodemon to know about the .pl extension (for Perl), the nodemon.json file would add:

{
"execMap": {
"pl": "perl"
}
}

Now running the following, nodemon will know to use `perl` as the executable:

nodemon script.pl

It's generally recommended to use the global `nodemon.json` to add your own `execMap` options. However, if there's a common default that's missing, this can be merged in to the project so that nodemon supports it by default, by changing [default.js]() and sending a pull request.

## Monitoring multiple directories

By default nodemon monitors the current working directory. If you want to take control of that option, use the `--watch` option to add specific paths:

nodemon --watch app --watch libs app/server.js

Now nodemon will only restart if there are changes in the `./app` or `./libs` directory. By default nodemon will traverse sub-directories, so there's no need in explicitly including sub-directories.

# Specifying extension watch list
## Specifying extension watch list

By default, nodemon looks for files with the `.js`, `.coffee`, and `.litcoffee` extensions. If you use the `--exec` option and monitor `app.py` nodemon will monitor files with the extension of `.py`. However, you can specify your own list with the `-e` switch like so:
By default, nodemon looks for files with the `.js`, `.coffee`, and `.litcoffee` extensions. If you use the `--exec` option and monitor `app.py` nodemon will monitor files with the extension of `.py`. However, you can specify your own list with the `-e` (or `--ext`) switch like so:

nodemon -e js,css,html
nodemon -e js,jade

Or with alternative syntax:
Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions .js, .jade.

nodemon --ext '.js|.css|.html'
## Ignoring files

Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions .js, .css or .html.
By default, if nodemon will only restart when a `.js` JavaScript file changes. In some cases you will want to ignore some specific files, directories or file patterns, to prevent nodemon from prematurely restarting your application.

# Delaying restarting
This can be done via the command line:

In some situations, you may want to wait until a number of files have changed. The timeout before checking for new file changes is 1 second. If you're uploading a number of files and it's taking some number of seconds, this could cause your app to restart multiple times unnecessarily.
nodemon --ignore lib/ --ignore tests/

To add an extra throttle, or delay restarting, use the `--delay` command:
Or specific files can be ignored:

nodemon --delay 10 server.js
nodemon --ignore lib/app.js

The delay figure is number of seconds to delay before restarting. So nodemon will only restart your app the given number of seconds after the *last* file change.
Patterns can also be ignored (but be sure to quote the arguments):

nodemon --ignore 'lib/*.js'

# Ignoring files
Finally regular expressions can be used, but need to be prefixed with a colon (this will ignore all numbered JS files):

By default, if nodemon will only restart when a `.js` JavaScript file changes. In some cases you will want to ignore some specific files, directories or file patterns, to prevent nodemon from prematurely restarting your application.
nodemon --ignore ':(\d)+\.js$'

You can use the [example ignore file](http://github.com/remy/nodemon/blob/master/nodemonignore.example) (note that this example file is not hidden - you must rename it to `.nodemonignore`) as a basis for your nodemon, but it's very simple to create your own:
Note that by default, nodemon will ignore the `.git` and `node_modules/**/node_modules` directories.

# this is my ignore file with a nice comment at the top

/vendor/* # ignore all external submodules
/public/* # static files
./README.md # a specific file
*.css # ignore any CSS files too
:(\d)*\.js # monitor javascript files with only digits in their name
## Delaying restarting

The ignore file accepts:
In some situations, you may want to wait until a number of files have changed. The timeout before checking for new file changes is 1 second. If you're uploading a number of files and it's taking some number of seconds, this could cause your app to restart multiple time unnecessarily.

* Comments starting with a `#` symbol
* Blank lines
* Specific files
* File patterns (this is converted to a regex, so you have full control of the pattern)
* Unescaped regex's begining with `:`.
To add an extra throttle, or delay restarting, use the `--delay` command:

nodemon --delay 10 server.js

**Note** the `.nodemonignore` file is read from the directory you run nodemon from, *not* from the location of the node script you're running.
The delay figure is number of seconds to delay before restarting. So nodemon will only restart your app the given number of seconds after the *last* file change.

# Controlling shutdown of your script
## Controlling shutdown of your script

nodemon sends a kill signal to your application when it sees a file update. If you need to clean up on shutdown inside your script you can capture the kill signal and handle it yourself.

The following example will listen once for the `SIGUSR2` signal (used by nodemon to restart), run the clean up process and then kill itself for nodemon to continue control:

process.once('SIGUSR2', function () {
gracefulShutdown(function () {
process.kill(process.pid, 'SIGUSR2');
process.kill(process.pid, 'SIGUSR2');
})
});

Note that the `process.kill` is *only* called once your shutdown jobs are complete. Hat tip to [Benjie Gillam](http://www.benjiegillam.com/2011/08/node-js-clean-restart-and-faster-development-with-nodemon/) for writing technique this up.

# Using nodemon in your Grunt workflow
## Using nodemon in your Grunt workflow

Check out the [grunt-nodemon](https://github.com/ChrisWren/grunt-nodemon) plugin to integrate nodemon with the rest of your project's grunt workflow.

# Help! My changes aren't being detected!

nodemon has three potential methods it uses to look for file changes. First, it polls using the find command to search for files modified within the last second. This method works on systems with a BSD based find (Mac, for example).

Next it tries using node's `fs.watch`. `fs.watch` will not always work however, and nodemon will try and detect if this is the case by writing a file to the tmp directory and seeing if fs.watch is triggered when it's removed. If nodemon finds that fs.watch was not triggered, it will then fall back to the third method (called legacy watch), which works by statting each file in your working directory looking for changes to the last modified time. This is the most cpu intensive method, but it may be the only option on some systems.

In certain cases, like when where you are working on a different drive than your tmp directory is on, `fs.watch` may give you a false positive. You can force nodemon to start using the most compatible legacy method by passing the -L switch, e.g. `nodemon -L /my/odd/file.js`.

# License

MIT [http://rem.mit-license.org](http://rem.mit-license.org)
17 changes: 17 additions & 0 deletions bin/nodemon.js
@@ -0,0 +1,17 @@
#!/usr/bin/env node
'use strict';
var cli = require('../lib/cli'),
nodemon = require('../lib/'),
updateNotifier = require('update-notifier'),
// checks for available update and returns an instance
notifier = updateNotifier({ packagePath: '../package' });

if (notifier.update) {
// notify using the built-in convenience method
notifier.notify();
}

var options = cli.parse(process.argv);
options.restartable = 'rs';

nodemon(options);
41 changes: 41 additions & 0 deletions doc/arch.md
@@ -0,0 +1,41 @@
# nodemon code arch

```
CLI -> parser -> nodemon options -> rules

rules -> configure -> watch -> start process
```

## CLI examples

Watch src but only *.js and *.coffee

nodemon --watch src/ -e js,coffee app.js

Parsed to:

{
watch: ['src/'],
ignore: [],
script: 'app.js'
options: {
extensions: ['js', 'coffee'],
exec: 'node'
}
}

Watch with no args:

nodemon

Parsed to (assuming a package.json or index.js is found):

{
watch: [], // meaning all subdirectories
ignore: [],
script: 'index.js',
options: {
extensions: ['js'],
exec: 'node'
}
}
44 changes: 44 additions & 0 deletions doc/cli/authors.txt
@@ -0,0 +1,44 @@

Remy Sharp - author and maintainer
http://github.com/remy
http://twitter.com/rem

project: nodemon
commits: 302
active : 107 days
files : 73
authors:
197 Remy Sharp 65.2%
40 remy 13.2%
8 Phred 2.6%
8 dylanmcd 2.6%
6 Pasindu De Silva 2.0%
4 ChrisWren 1.3%
3 Albert Netymk 1.0%
3 Shawn Biddle 1.0%
3 Coen Hyde 1.0%
2 Aivo Paas 0.7%
2 Christopher Wren 0.7%
2 Dylan McDiarmid 0.7%
2 Jason Griffin 0.7%
2 Josh Davis 0.7%
2 Vadim 0.7%
2 fearphage 0.7%
1 Alex Sexton 0.3%
1 Matthew Andrews 0.3%
1 Morgan "ARR!" Allen 0.3%
1 Dennis Kehrig 0.3%
1 Paul Armstrong 0.3%
1 Peter Lyons 0.3%
1 Chris Wren 0.3%
1 Chris Klaiber 0.3%
1 Bryan Kaplan 0.3%
1 Todd Wolfson 0.3%
1 frekw 0.3%
1 Wil Asche 0.3%
1 Everton Ribeiro 0.3%
1 Jared Hanson 0.3%
1 Alexey Petushkov 0.3%
1 Kaushik Shankar 0.3%

Please contribute http://github.com/remy/nodemon/
43 changes: 43 additions & 0 deletions doc/cli/config.txt
@@ -0,0 +1,43 @@

Typically the options to control nodemon are passed in via the CLI and are
listed under the default nodemon --help command.

nodemon can also be configured via a local and global config file:

* $HOME/nodemon.json
* $PWD/nodemon.json

All config options in the .json file map 1-to-1 with the CLI options, so a
config could read as:

{
"ext": "*.pde",
"verbose": true,
"exec": "processing --sketch=game --run"
}

There are a limited number of variables available in the config (since you
could use backticks on the CLI to use a variable, backticks won't work in
the .json config).

* {{pwd}} - the current directory
* {{filename}} - the filename you pass to nodemon

For example:

{
"ext": "*.pde",
"verbose": true,
"exec": "processing --sketch={{pwd}} --run"
}

The global config file is useful for setting up default default executables
instead of needed them in your local config:

{
"verbose": true,
"execMap": {
"rb": "ruby",
"pde": "processing --sketch={{pwd}} --run"
}
}