Skip to content

Instantly share code, notes, and snippets.

@trevorwhitney
Last active February 28, 2017 21:07
Show Gist options
  • Select an option

  • Save trevorwhitney/d0b024c81eea57d287f79574aaa4e7f8 to your computer and use it in GitHub Desktop.

Select an option

Save trevorwhitney/d0b024c81eea57d287f79574aaa4e7f8 to your computer and use it in GitHub Desktop.
A gulpfile that will stand up a livereload server in front of shipkin generated assets.
var gulp = require('gulp'),
spawn = require('child_process').spawn,
path = require('path'),
request = require('request'),
connect = require('gulp-connect'),
Promise = require('promise');
var serverPort = 8080,
liveReloadPort = 35729;
var determineHtmlPath = function(mdPath) {
var relativePath = path.relative(__dirname, mdPath);
return path.dirname(relativePath) + '/' + path.basename(relativePath, '.md') + '.html';
}
gulp.task('serve', function() {
connect.server({
root: 'build/site',
port: serverPort,
livereload: {
port: liveReloadPort
}
});
});
gulp.task('watch', function () {
gulp.watch(['**/*.md'], function(file) {
console.log("Regenerating HTML files");
new Promise(function(resolve, reject) {
var child = spawn('./gradlew', ['generate']);
child.on("error", reject);
child.on("exit", resolve);
}).then(function(result) {
request.get('http://localhost:' + liveReloadPort + '/changed?files=' + determineHtmlPath(file.path));
}, function(err) {
console.log("Failed to regenerate project: ", err);
});
});
});
gulp.task('default', ['serve', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment