Skip to content

Instantly share code, notes, and snippets.

@slemarchand
Last active March 2, 2016 12:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slemarchand/fd4f15868edeb592e64a to your computer and use it in GitHub Desktop.
Save slemarchand/fd4f15868edeb592e64a to your computer and use it in GitHub Desktop.
Synchronize webapps assets from maven projects sources to webapps context directories.
//
// 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