Last active
April 27, 2017 14:31
-
-
Save donhenton/7c7ccce6f808d2fc5074 to your computer and use it in GitHub Desktop.
gulpfile to update tomcat when changes take place
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
/** | |
* | |
* @type Module gulp|Module gulp | |
* gulp file that will monitor files in the src tree and then move them | |
* to the tomcat instance. In effect a poor-man's JRebel | |
* | |
* Your tomcat server needs to be running and to see the changes | |
* This script will also refresh one page of your choice specified in the | |
* refresh page. Refreshing the page requires installation of the chrome | |
* live reload plugin | |
* | |
* this file must be in src/main/resources/assets it | |
* assumes it is only working with css, js in the assets folder and below | |
* | |
* usage: gulp watch-assets | |
* | |
* modules below must be installed globally | |
* | |
* the live reload plugin page may have to be the only page up in chrome? | |
* | |
*/ | |
var gulp = require('gulp'); | |
var tap = require('gulp-tap'); | |
var watch = require('gulp-watch'); | |
var livereload = require('gulp-livereload'); | |
/** | |
* this is the list of files to watch will have to change this each usage | |
* @type Array | |
*/ | |
var watchItems = [ | |
'css/alpha.css', | |
'js/beta.js', | |
'js/gamma.js']; | |
/** | |
* the page that you want livereload to refresh | |
* | |
*/ | |
var pageURL = 'http://localhost:8080/myapp/mypage'; | |
/* html items are handled separately */ | |
var htmlItem = '../pages/MyPage.html'; | |
/* system needs to have TOMCAT_HOME properly defined */ | |
var tomcatHome = process.env.TOMCAT_HOME; | |
gulp.task('watch-assets', function () { | |
livereload.listen(); | |
watch(watchItems, function (events, done) { | |
gulp.start(['copy-assets', 'refresh']); | |
}); | |
watch(htmlItem, function (events, done) { | |
gulp.start(['copy-html','reload-html']); | |
}); | |
}); | |
gulp.task('copy-assets', function () { | |
return gulp.src(watchItems, {'base': './../'}) | |
.pipe(tap(function (file, t) | |
{ | |
console.log('updating ' + file.relative); | |
})) | |
.pipe(gulp.dest(tomcatHome + '/webapps/myapp/WEB-INF/classes')); | |
}); | |
gulp.task('reload-html', function() | |
{ | |
//apparently needs to be done twice | |
function reloadHTML() | |
{ | |
livereload.reload(pageURL); | |
livereload.reload(pageURL); | |
} | |
setTimeout( reloadHTML,1000); | |
}); | |
gulp.task('copy-html', function () { | |
return gulp.src(htmlItem, {'base': './..'}) | |
.pipe(tap(function (file, t) | |
{ | |
console.log('updating html ' + file.relative); | |
})) | |
.pipe(gulp.dest(tomcatHome + '/myapp/tools/WEB-INF/classes')) | |
}); | |
/** | |
* the location of the page to refresh will have to be changed as well | |
*/ | |
gulp.task('refresh', function () { | |
console.log('refresh') | |
livereload.reload(pageURL); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://donhenton.com/blog/archives/1786