diff --git a/Gruntfile.js b/Gruntfile.js index 6340c9b..063cb98 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -47,6 +47,18 @@ module.exports = function(grunt) { } }); + grunt.registerTask("cleanPkgd", function() { + if (grunt.file.exists("dist/pkgd/eg.pkgd.js")) { + grunt.file["delete"]("dist/pkgd/eg.pkgd.js", { force: true }); + } + if (grunt.file.exists("dist/pkgd/flicking.pkgd.js")) { + grunt.file["delete"]("dist/pkgd/flicking.pkgd.js", { force: true }); + } + if (grunt.file.exists("dist/pkgd/infiniteGrid.pkgd.js")) { + grunt.file["delete"]("dist/pkgd/infiniteGrid.pkgd.js", { force: true }); + } + }); + grunt.registerTask("validate-commit", function() { if (!grunt.file.exists(".git/hooks/commit-msg")) { var fs = require("fs"); @@ -56,7 +68,7 @@ module.exports = function(grunt) { }); grunt.registerTask("docBuild", ["copy:doc", "clean", "jsdoc"]); - grunt.registerTask("build", ["concat", "uglify", "docBuild"]); + grunt.registerTask("build", ["concat", "uglify", "cleanPkgd", "docBuild"]); // grunt.registerTask("build", ["concat", "uglify", "copy:lib", "docBuild"]); grunt.registerTask("default", ["validate-commit","jshint", "jscs", "build", "test"]); grunt.registerTask("check", ["jshint", "jscs", "test"]); diff --git a/config/concat.js b/config/concat.js index fc3d744..0790a2f 100644 --- a/config/concat.js +++ b/config/concat.js @@ -2,18 +2,44 @@ 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 = { - options: { - banner: "<%=banner.common %>\"use strict\";\n", - process: function(src) { - // remove "use strict"; - // change version; - src = src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, "$1").replace(/#__VERSION__#/g, version); - return src; - } - }, build: { + options: { + banner: "<%=banner.common %>\"use strict\";\n", + process: changeSrc + }, src: dependency.egCore.concat(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.outlayer, 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.egCore, ["src/hook/css.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.outlayer.concat(dependency.egCore, ["src/customEvent/scrollEnd.js", "src/plugin/persist.js", "src/infiniteGrid.js"]), + dest : "dist/pkgd/infiniteGrid.pkgd.js" } }; \ No newline at end of file diff --git a/config/uglify.js b/config/uglify.js index d4da7ce..9e60a78 100644 --- a/config/uglify.js +++ b/config/uglify.js @@ -10,23 +10,23 @@ module.exports = { }, pkgd_eg: { options : { - banner : "<%=banner.common %><%=banner.pkgd('egjs') %><%=uglify.pkgd_eg.src.join('\\n* ')%>\n*/\n" + banner : "<%=banner.common %><%=banner.pkgd('egjs') %><%=concat.pkgd_eg.src.join('\\n* ')%>\n*/\n" }, - src : dependency.hammer.concat(dependency.outlayer, dependency.egCore, dependency.egExtend, ["src/visible.js", "src/movableCoord.js", "src/flicking.js", "src/infiniteGrid.js"]), - dest : "dist/pkgd/eg.pkgd.min.js" + src : "dist/pkgd/<%=pkg.outputname%>.pkgd.js", + dest : "dist/pkgd/<%=pkg.outputname%>.pkgd.min.js" }, pkgd_flicking: { options : { - banner : "<%=banner.common %><%=banner.pkgd('eg.flicking') %><%=uglify.pkgd_flicking.src.join('\\n* ')%>\n*/\n" + banner : "<%=banner.common %><%=banner.pkgd('eg.flicking') %><%=concat.pkgd_flicking.src.join('\\n* ')%>\n*/\n" }, - src : dependency.hammer.concat(dependency.egCore, ["src/hook/css.js", "src/movableCoord.js", "src/flicking.js"]), + src : "dist/pkgd/flicking.pkgd.js", dest : "dist/pkgd/flicking.pkgd.min.js" }, pkgd_infiniteGrid: { options : { - banner : "<%=banner.common %><%=banner.pkgd('eg.infiniteGrid') %><%=uglify.pkgd_infiniteGrid.src.join('\\n* ')%>\n*/\n" + banner : "<%=banner.common %><%=banner.pkgd('eg.infiniteGrid') %><%=concat.pkgd_infiniteGrid.src.join('\\n* ')%>\n*/\n" }, - src : dependency.outlayer.concat(dependency.egCore, ["src/customEvent/scrollEnd.js", "src/plugin/persist.js", "src/infiniteGrid.js"]), + src : "dist/pkgd/infiniteGrid.pkgd.js", dest : "dist/pkgd/infiniteGrid.pkgd.min.js" } }; \ No newline at end of file