"use strict";

var gulp = require("gulp"),
	fs = require("fs"),
	jshint = require("gulp-jshint");

// JSHint
// https://github.com/wearefractal/gulp-jshint
gulp.task("jshint", function () {

	//
	// FIXME
	//
	// gulp.jshint not reading .jshintrc
	// side-effect of JSHint itself not read configuration when using stdin
	//
	// https://github.com/wearefractal/gulp-jshint/issues/4
	//

	var options = JSON.parse(fs.readFileSync(".jshintrc", "utf8"));

	//
	// FIXME
	//
	// Can't use following due to Error: EMFILE, too many open files:
	//
	//	gulp.src("./**/*.js")
	//		.pipe(ignore({
	//			pattern: [
	//				"./node_modules/**",
	//				"./test/temp/**"]}))
	//
	// Must wait for core impl of .src() ignores
	//
	// https://github.com/wearefractal/gulp/issues/35
	//

	gulp.src("./*.js")
		.pipe(jshint(options))
		.pipe(jshint.reporter("default"));

	gulp.src("./test/**/*.js")
		.pipe(jshint(options))
		.pipe(jshint.reporter("default"));
});

// default task
gulp.task("default", function () {
	gulp.run("jshint");
});

@@ -57,16 +57,48 @@
 (%22fs%22),%0A
+%09cp = require(%22child_process%22),%0A
 %09jshint 
@@ -1045,12 +1045,133 @@
 hint%22);%0A
-%7D);
+%0A%09gulp.watch(%5B%22index.js%22, %22./test/**%22%5D, function () %7B%0A%09%09gulp.run(%22jshint%22);%0A%09%09cp.fork(%22node_modules/.bin/mocha%22);%0A%09%7D);%0A%0A%7D);%0A
 %0A

add watcher