/* jshint node: true */
"use strict";

var q = require("q");
var exec = q.denodeify(require("child_process").exec);
var glob = require("glob");
var path = require("path");
var utils = require("./utils");

var CASPERJS_PATH = path.resolve(__dirname, "./casperjs");

var casperjs = function casperjs(filename, args) {
	return [
		"phantomjs", // Engine name (either PhantomJS or SlimerJS)
		utils.quote(path.join(CASPERJS_PATH, "bin", "bootstrap.js")),
		"--casper-path=" + utils.quote(CASPERJS_PATH),
		"--cli",
		utils.quote(path.resolve(__dirname, "./index.casper.js")),
		"--script=" + utils.quote(path.relative(__dirname, filename))
	]
	.concat(args)
	.join(" ");
};

var MUN = {};
glob.sync(path.join(__dirname, "scripts/**/*.casper.js")).forEach(function (e, i, a) {
	var module = utils.hyphensToCamelCase(path.basename(path.dirname(e)));
	var script = utils.hyphensToCamelCase(path.basename(e).split(".")[0]);
	MUN[module] = MUN[module] || {};
	MUN[module][script] = function (args) {
		return exec(casperjs(e, Array.prototype.slice.call(arguments)));
	};
});

module.exports = MUN;

@@ -645,16 +645,22 @@
 cat(args
+ %7C%7C %5B%5D
 )%0A%09.join
@@ -982,20 +982,16 @@
 nction (
-args
 ) %7B%0A%09%09re

Remove unused variables