var jsonfile = require('jsonfile')
var dependency = require('./dependency')
var version = jsonfile.readFileSync("package.json").version;

function changeSrc(src) {
	// remove "use strict";
	// change version;
	src = src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, "$1").replace(/#__VERSION__#/g, version);
	return src;
}

module.exports = {
	build: {
		options: {
			banner: "<%=banner.common %>\"use strict\";\n",
			process: changeSrc
		},
		src: dependency.eg.concat(["src/agent.js","src/raf.js"], dependency.egCore, dependency.egExtend, ["src/visible.js", "src/movableCoord.js", "src/flicking.js",  "src/infiniteGrid.js"]),
		dest: "dist/<%=pkg.outputname%>.js"
	},
	pkgd_eg: {
		options : {
			banner : "<%=banner.common %><%=banner.pkgd('egjs') %><%=concat.pkgd_eg.src.join('\\n* ')%>\n*/\n",
			process: changeSrc
		},
		src : dependency.hammer.concat(dependency.eg, ["src/agent.js","src/raf.js"], dependency.egCore, dependency.egExtend, ["src/visible.js", "src/movableCoord.js", "src/flicking.js",  "src/infiniteGrid.js"]),
		dest : "dist/pkgd/<%=pkg.outputname%>.pkgd.js"
	},
	pkgd_flicking: {
		options : {
			banner : "<%=banner.common %><%=banner.pkgd('eg.flicking') %><%=concat.pkgd_flicking.src.join('\\n* ')%>\n*/\n",
			process: changeSrc
		},
		src : dependency.hammer.concat(dependency.eg, ["src/agent.js","src/raf.js"], dependency.egCore, ["src/hook/cssPrefix.js", "src/movableCoord.js", "src/flicking.js"]),
		dest : "dist/pkgd/flicking.pkgd.js"
	},
	pkgd_infiniteGrid: {
		options : {
			banner : "<%=banner.common %><%=banner.pkgd('eg.infiniteGrid') %><%=concat.pkgd_infiniteGrid.src.join('\\n* ')%>\n*/",
			process: changeSrc
		},
		src : dependency.eg.concat(dependency.egCore, ["src/plugin/persist.js", "src/infiniteGrid.js"]),
		dest : "dist/pkgd/infiniteGrid.pkgd.js"
	}
};

var jsonfile = require('jsonfile')
var dependency = require('./dependency')
var version = jsonfile.readFileSync("package.json").version;

function changeSrc(src) {
	// remove "use strict";
	// change version;
	src = src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, "$1").replace(/#__VERSION__#/g, version);
	return src;
}

module.exports = {
	build: {
		options: {
			banner: "<%=banner.common %>\"use strict\";\n",
			process: changeSrc
		},
		src: dependency.eg.concat(["src/agent.js","src/raf.js"], dependency.egCore, dependency.egExtend, ["src/visible.js", "src/movableCoord.js", "src/flicking.js",  "src/infiniteGrid.js"]),
		dest: "dist/<%=pkg.outputname%>.js"
	},
	pkgd_eg: {
		options : {
			banner : "<%=banner.common %><%=banner.pkgd('egjs') %><%=concat.pkgd_eg.src.join('\\n* ')%>\n*/\n",
			process: changeSrc
		},
		src : dependency.hammer.concat(dependency.eg, ["src/agent.js","src/raf.js"], dependency.egCore, dependency.egExtend, ["src/visible.js", "src/movableCoord.js", "src/flicking.js",  "src/infiniteGrid.js"]),
		dest : "dist/pkgd/<%=pkg.outputname%>.pkgd.js"
	},
	pkgd_flicking: {
		options : {
			banner : "<%=banner.common %><%=banner.pkgd('eg.flicking') %><%=concat.pkgd_flicking.src.join('\\n* ')%>\n*/\n",
			process: changeSrc
		},
		src : dependency.hammer.concat(dependency.eg, ["src/agent.js","src/raf.js"], dependency.egCore, ["src/hook/cssPrefix.js", "src/movableCoord.js", "src/flicking.js"]),
		dest : "dist/pkgd/flicking.pkgd.js"
	},
	pkgd_infiniteGrid: {
		options : {
			banner : "<%=banner.common %><%=banner.pkgd('eg.infiniteGrid') %><%=concat.pkgd_infiniteGrid.src.join('\\n* ')%>\n*/",
			process: changeSrc
		},
		src : dependency.eg.concat(["src/agent.js"], dependency.egCore, ["src/plugin/persist.js", "src/infiniteGrid.js"]),
		dest : "dist/pkgd/infiniteGrid.pkgd.js"
	}
};

update infiniteGrid package build