diff --git a/Gruntfile.js b/Gruntfile.js index 5edad075..5defac72 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,6 +7,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-contrib-qunit"); grunt.loadNpmTasks("grunt-contrib-connect"); grunt.loadNpmTasks("grunt-contrib-watch"); + grunt.loadNpmTasks("grunt-contrib-clean"); var distribution = "build/openseadragon/openseadragon.js", minified = "build/openseadragon/openseadragon.min.js", @@ -43,6 +44,19 @@ module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), + clean: { + build: ["build"], + release: { + src: [ + "../site-build/openseadragon", + "../site-build/openseadragon.zip", + "../site-build/openseadragon.tar" + ], + options: { + force: true + } + } + }, concat: { options: { banner: "/**\n * @version <%= pkg.name %> <%= pkg.version %>\n */\n\n" @@ -93,7 +107,7 @@ module.exports = function(grunt) { }, watch: { files: [ "grunt.js", "src/*.js" ], - tasks: "default" + tasks: "build" }, jshint: { options: { @@ -109,20 +123,41 @@ module.exports = function(grunt) { } }); - // Copy task. - grunt.registerTask("copy", function() { + // Copy:build task. + // Copies the image files into the appropriate location in the build folder. + grunt.registerTask("copy:build", function() { grunt.file.recurse("images", function(abspath, rootdir, subdir, filename) { grunt.file.copy(abspath, "build/openseadragon/images/" + (subdir || "") + filename); }); }); - // Default task. - grunt.registerTask("default", ["jshint:beforeconcat", "concat", "jshint:afterconcat", "uglify", "copy"]); + // Copy:release task. + // Copies the contents of the build folder into ../site-build. + grunt.registerTask("copy:release", function() { + grunt.file.recurse("build", function(abspath, rootdir, subdir, filename) { + grunt.file.copy(abspath, "../site-build/" + (subdir || "") + filename); + }); + }); + + // Build task. + // Cleans out the build folder and builds the code and images into it, checking lint. + grunt.registerTask("build", [ + "clean:build", "jshint:beforeconcat", "concat", "jshint:afterconcat", "uglify", "copy:build" + ]); // Test task. - grunt.registerTask("test", ["default", "connect", "qunit"]); + // Builds and runs unit tests. + grunt.registerTask("test", ["build", "connect", "qunit"]); // Package task. - grunt.registerTask("package", ["default", "compress"]); + // Builds and creates the .zip and .tar files. + grunt.registerTask("package", ["build", "compress"]); + // Publish task. + // Cleans the built files out of ../site-build and copies newly built ones over. + grunt.registerTask("publish", ["package", "clean:release", "copy:release"]); + + // Default task. + // Does a normal build. + grunt.registerTask("default", ["build"]); }; diff --git a/README.md b/README.md index e84f2fc9..d37c0cb1 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,14 @@ If you want to build tar and zip files for distribution (they will also appear i grunt package +Note that the `build` folder is masked with .gitignore; it's just for your local use, and won't be checked in to the repository. + +You can also publish the built version to the site-build repository. This assumes you have cloned it next to this repository. The command is: + + grunt publish + +... which will delete the existing openseadragon folder, along with the .zip and .tar files, out of the site-build folder and replace them with newly built ones from the source in this repository; you'll then need to commit the changes to site-build. + ## Testing Our tests are based on [QUnit](http://qunitjs.com/) and [PhantomJS](http://phantomjs.org/); they're both installed when you run `npm install`. At the moment we don't have much in the way of tests, but we're working to fix that. To run on the command line: diff --git a/package.json b/package.json index 2daf64b9..1dc1a3e3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "grunt-contrib-uglify": "~0.1.1", "grunt-contrib-qunit": "~0.1.1", "grunt-contrib-connect": "~0.1.2", - "grunt-contrib-watch": "~0.2.0" + "grunt-contrib-watch": "~0.2.0", + "grunt-contrib-clean": "~0.4.0" }, "scripts": { "test": "grunt test"