-
Notifications
You must be signed in to change notification settings - Fork 133
/
autojake.js
executable file
·42 lines (31 loc) · 1.1 KB
/
autojake.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/local/bin/node
// Automatically runs Jake when files change.
//
// Thanks to Davide Alberto Molin for contributing this code.
// See http://www.letscodejavascript.com/v3/comments/live/7 for details.
//
// NOTE: The "COMMAND" variable must be changed for this to work on Windows.
(function() {
"use strict";
var gaze;
try { gaze = require("gaze"); }
catch (err) { console.log("To use this script, run 'npm install gaze'."); process.exit(1); }
var spawn = require("child_process").spawn;
var WATCH = "src/**/*.js";
var COMMAND = "./jake.sh"; // Mac/Unix
// var COMMAND = "jake.bat"; // Windows
var COMMAND_ARGS = ["loose=true"];
var buildRunning = false;
gaze(WATCH, function(err, watcher) {
console.log("Will run " + COMMAND + " when " + WATCH + " changes.");
watcher.on("all", function(evt, filepath) {
if (buildRunning) return;
buildRunning = true;
console.log("\n> " + COMMAND + " " + COMMAND_ARGS.join(" "));
var jake = spawn(COMMAND, COMMAND_ARGS, { stdio: "inherit" });
jake.on("exit", function(code) {
buildRunning = false;
});
});
});
}());