#!/usr/bin/env node
/*jshint shelljs:true */

"use strict";

var browserify = require("browserify");
var bundle     = browserify("./src/jshint.js");
var version    = require("../package.json").version;
require("shelljs/make");

if (!test("-e", "../dist"))
	mkdir("../dist");

bundle.require("./src/jshint.js", { expose: "jshint" });
bundle.bundle({}, function (err, src) {
	var web   = "./dist/jshint-" + version + ".js";
	var rhino = "./dist/jshint-rhino-" + version + ".js";

	[ "// " + version,
		"var JSHINT;",
		"var window;",
		"if (typeof window === 'undefined') window = {};",
		"(function () {",
		"var require;",
		src,
		"JSHINT = require('jshint').JSHINT;",
		"}());"
	].join("\n").to(web);

	("#!/usr/bin/env rhino\nvar window = {};\n" + cat(web, "./src/platforms/rhino.js")).to(rhino);
	chmod("+x", rhino);
});