Last active
February 28, 2017 21:07
-
-
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.
This file contains hidden or 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
| 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