Skip to content

Commit

Permalink
Automatically tests for package.json file - Closes remy#14, and suppo…
Browse files Browse the repository at this point in the history
…rt for coffee-script - Closes remy#8
  • Loading branch information
remy committed Apr 23, 2011
1 parent a467b88 commit 88269ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ And `nodemon` will be installed in to your bin path.
`nodemon` wraps your application, so you can pass all the arguments you would normally pass to your app:

nodemon [your node app]

For example, if my application accepted a host and port as the arguments, I would start it as so:

nodemon ./server.js localhost 8080

Any output from this script is prefixed with `[nodemon]`, otherwise all output from your application, errors included, will be echoed out as expected.

`nodemon` also supports running and monitoring [coffee-script](http://jashkenas.github.com/coffee-script/) apps:

nodemon server.coffee

If no script is given, `nodemon` will test for a `package.json` file and if found, will run the file associated with the *main* property ([ref](https://github.com/remy/nodemon/issues/14)).

# Ignoring files

In some cases you will want to ignore some specific files, directories or file patterns, to prevent nodemon from prematurely restarting your application.
Expand Down
24 changes: 21 additions & 3 deletions nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ var fs = require('fs'),

function startNode() {
sys.log('\x1B[32m[nodemon] starting node\x1B[0m');
node = spawn('node', nodeArgs);

var ext = path.extname(app);
if (ext === '.coffee') {
node = spawn('coffee', nodeArgs);
} else {
node = spawn('node', nodeArgs);
}

node.stdout.on('data', function (data) {
sys.print(data);
Expand Down Expand Up @@ -114,7 +120,20 @@ function usage() {
sys.print('usage: nodemon [--debug] [your node app]\ne.g.: nodemon ./server.js localhost 8080\nFor details see http://github.com/remy/nodemon/\n\n');
}

if (!nodeArgs.length || nodeArgs[0] == 'help') {
if (!nodeArgs.length) {
// try to get the app from the package.json
// doing a try/catch because we can't use the path.exist callback pattern
// or we could, but the code would get messy, so this will do exactly
// what we're after - if the file doesn't exist, it'll throw.
try {
app = JSON.parse(fs.readFileSync('./package.json').toString()).main;
nodeArgs.push(app);
} catch (e) {
nodeArgs.push('help'); // default to help
}
}

if (nodeArgs[0] == 'help') {
usage();
process.exit(0);
}
Expand All @@ -129,7 +148,6 @@ if (nodeArgs[0] == '--debug') {
app = nodeArgs[1];
}


sys.log('[nodemon] v' + meta.version);

// Change to application dir
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"url": "http://github.com/remy"
},
"bin": { "nodemon" : "./nodemon.js" },
"repository": { "type" : "git", "url" : "http://github.com/remy/nodemon.git" },
"repository": { "type" : "git", "url" : "http://github.com/remy/nodemon.git" },
"description": "Simple monitor script for use during development of a node.js app.",
"keywords": ["monitor", "development", "restart", "autoload", "reload", "terminal"],
"version": "0.2.2",
"version": "0.3.0",
"main": "./nodemon"
}

0 comments on commit 88269ba

Please sign in to comment.