From bc23e9cea628fc547c7a037617edd8ede130fadd Mon Sep 17 00:00:00 2001 From: jdescottes Date: Mon, 5 May 2014 22:36:34 +0200 Subject: [PATCH 1/2] Enhancement : full piskel build deployed to dest Use grunt [default] to build the application. Target dest with a webserver to launch the application. --- .gitignore | 7 ++----- Gruntfile.js | 32 ++++++++++++++++++++++++-------- package.json | 2 ++ src/piskel-boot.js | 6 +++--- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 780fe156..578dec56 100644 --- a/.gitignore +++ b/.gitignore @@ -12,15 +12,12 @@ npm-debug.log # git stackdumps *.stackdump -# builds -build/*.js -build/*.css # diffs diff.txt -# Closure compiler generated JS binary. -build/closure/closure_compiled_binary.js +# build destination +dest # marked as private *.private.* \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 1f65ddf0..f1dbd772 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -36,6 +36,10 @@ module.exports = function(grunt) { }; grunt.initConfig({ + clean: { + before: ['dest'], + after: ['build/closure/closure_compiled_binary.js'] + }, jshint: { options: { indent:2, @@ -79,11 +83,11 @@ module.exports = function(grunt) { separator : ';' }, src : piskelScripts, - dest : 'build/piskel-packaged.js' + dest : 'dest/js/piskel-packaged.js' }, css : { src : piskelStyles, - dest : 'build/piskel-style-packaged.css' + dest : 'dest/css/piskel-style-packaged.css' } }, uglify : { @@ -92,10 +96,20 @@ module.exports = function(grunt) { }, my_target : { files : { - 'build/piskel-packaged-min.js' : ['build/piskel-packaged.js'] + 'dest/js/piskel-packaged-min.js' : ['dest/js/piskel-packaged.js'] } } }, + copy: { + main: { + files: [ + {src: ['src/piskel-boot.js'], dest: 'dest/piskel-boot.js'}, + {src: ['src/js/lib/iframeLoader.js'], dest: 'dest/js/lib/iframeLoader.js'}, + {expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'}, + {expand: true, src: ['**/*.html'], cwd: 'src/', dest: 'dest/', filter: 'isFile'} + ] + } + }, closureCompiler: { options: { // [REQUIRED] Path to closure compiler @@ -161,7 +175,9 @@ module.exports = function(grunt) { src: ['src/css/**/*.css'] }); + grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-connect'); + grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-uglify'); @@ -173,18 +189,18 @@ module.exports = function(grunt) { grunt.registerTask('lint', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint']); // Validate & Test - grunt.registerTask('test', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint', 'compile', 'connect:test', 'ghost:default']); + grunt.registerTask('test', ['lint', 'compile', 'connect:test', 'ghost:default']); // Validate & Test (faster version) will NOT work on travis !! - grunt.registerTask('precommit', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint', 'compile', 'connect:test', 'ghost:local']); + grunt.registerTask('precommit', ['lint', 'compile', 'connect:test', 'ghost:local']); // Compile JS code (eg verify JSDoc annotation and types, no actual minified code generated). - grunt.registerTask('compile', ['closureCompiler:compile']); + grunt.registerTask('compile', ['closureCompiler:compile', 'clean:after']); - grunt.registerTask('merge', ['concat:js', 'concat:css', 'uglify']); + grunt.registerTask('merge', ['concat:js', 'concat:css', 'uglify', 'copy']); // Validate & Build - grunt.registerTask('default', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint', 'concat:js', 'concat:css', 'compile', 'uglify']); + grunt.registerTask('default', ['clean:before', 'lint', 'compile', 'merge']); // Start webserver grunt.registerTask('serve', ['connect:serve']); diff --git a/package.json b/package.json index eb77b76e..408cb852 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,10 @@ }, "devDependencies": { "grunt": "~0.4.1", + "grunt-contrib-clean": "0.5.0", "grunt-contrib-connect": "0.3.0", "grunt-contrib-concat": "0.1.2", + "grunt-contrib-copy": "0.5.0", "grunt-contrib-jshint": "0.5.4", "grunt-contrib-uglify": "0.2.2", "grunt-ghost": "1.0.12", diff --git a/src/piskel-boot.js b/src/piskel-boot.js index 7e6dfdf6..b933517b 100644 --- a/src/piskel-boot.js +++ b/src/piskel-boot.js @@ -59,11 +59,11 @@ } else { var script; if (window.location.href.indexOf("pack") != -1) { - script = "build/piskel-packaged.js"; + script = "js/piskel-packaged.js"; } else { - script = "build/piskel-packaged-min.js"; + script = "js/piskel-packaged-min.js"; } - loadStyle('build/piskel-style-packaged.css'); + loadStyle('css/piskel-style-packaged.css'); var loaderInterval = window.setInterval(function () { if (document.querySelectorAll("[data-iframe-loader]").length === 0) { From adca1bbd08afe727693d6cf081fba7d7240be2ad Mon Sep 17 00:00:00 2001 From: jdescottes Date: Mon, 5 May 2014 23:08:11 +0200 Subject: [PATCH 2/2] Added grunt server task to run server+watch --- Gruntfile.js | 40 ++++++++++++++++++++++++++++++---------- package.json | 3 +++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index f1dbd772..8897fe68 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -64,12 +64,29 @@ module.exports = function(grunt) { base : '.', port : 4321 } - }, - serve : { - options : { - base : '.', - port : 1234, - keepalive : true + } + }, + express: { + server: { + options: { + port: 9001, + hostname : 'localhost', + bases: ['dest'] + } + } + }, + open : { + server : { + path : 'http://localhost:9001/' + } + }, + + watch: { + scripts: { + files: ['src/**/*.*'], + tasks: ['merge'], + options: { + spawn: false } } }, @@ -175,14 +192,17 @@ module.exports = function(grunt) { src: ['src/css/**/*.css'] }); + grunt.loadNpmTasks('grunt-closure-tools'); grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-closure-tools'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-express'); grunt.loadNpmTasks('grunt-ghost'); + grunt.loadNpmTasks('grunt-open'); grunt.loadNpmTasks('grunt-leading-indent'); // Validate @@ -202,6 +222,6 @@ module.exports = function(grunt) { // Validate & Build grunt.registerTask('default', ['clean:before', 'lint', 'compile', 'merge']); - // Start webserver - grunt.registerTask('serve', ['connect:serve']); + // Start webserver and watch for changes + grunt.registerTask('server', ['express', 'open', 'watch']); }; diff --git a/package.json b/package.json index 408cb852..99855747 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,10 @@ "grunt-contrib-copy": "0.5.0", "grunt-contrib-jshint": "0.5.4", "grunt-contrib-uglify": "0.2.2", + "grunt-contrib-watch": "0.6.1", + "grunt-express": "1.0", "grunt-ghost": "1.0.12", + "grunt-open": "0.2.3", "grunt-leading-indent": "0.1.0", "grunt-closure-tools": "~0.8.3" }