Last active
March 2, 2016 12:53
-
-
Save slemarchand/fd4f15868edeb592e64a to your computer and use it in GitHub Desktop.
Synchronize webapps assets from maven projects sources to webapps context directories.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// original gist: ttps://gist.github.com/slemarchand/fd4f15868edeb592e64a | |
// | |
// Synchronize webapps assets (including jsp and jspf files) | |
// from maven projects sources to webapps context directories. | |
// | |
// usage example: | |
// gulp --gulpfile sync-webapps.gulpfile.js --sources . --webapps ${CATALINA_HOME}/webapps | |
// | |
// install required packages: | |
// npm install -g gulp gulp-watch gulp-print node-find-files gulp-util | |
// | |
var gulp = require('gulp'), | |
watch = require('gulp-watch'), | |
print = require('gulp-print'), | |
FindFiles = require('node-find-files'), | |
gutil = require('gulp-util'); | |
gulp.task('default', function() { | |
var sourcesDir = gutil.env.sources; | |
var webappsDir = gutil.env.webapps; | |
var finder = new FindFiles({ | |
rootFolder : sourcesDir, | |
filterFunction : function (path) { | |
return (path.endsWith('/src/main/webapp')); | |
} | |
}); | |
finder.on("match", function(path, stat) { | |
var pathElements = path.split('/'), | |
context = pathElements[pathElements.length - 4], | |
src = path + '/**/*', | |
dest = webappsDir + '/' + context; | |
gulp.src([src, '!./**/web.xml']) | |
.pipe(watch(src)) | |
.pipe(print(function(filepath) { | |
return "synchronize " + filepath; | |
})) | |
.pipe(gulp.dest(dest)); | |
}); | |
finder.startSearch(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment