Created
May 18, 2015 19:13
-
-
Save LordZamy/62f014fea09eed2f292a to your computer and use it in GitHub Desktop.
restart:go being annoying af
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
var gulp = require('gulp'), | |
jade = require('gulp-jade'), | |
runSequence = require('run-sequence'), | |
del = require('del'), | |
shell = require('gulp-shell'); | |
gulp.task('clean', del.bind(null, ['.tmp', 'dist/*', '!dist/.git'], {dot: true})); | |
// doesn't compile extended templates | |
gulp.task('compile:jade', function() { | |
return gulp.src('./src/templates/*.jade') | |
.pipe(jade()) | |
.pipe(gulp.dest('./dist/views')); | |
}); | |
// places compiled app in ./dist and then runs it | |
// TODO: Kill previous process after spawning new one | |
var proc; | |
gulp.task('restart:go', function() { | |
console.log(proc); | |
return gulp.src('') | |
.pipe(shell([ | |
'<%= killProc() %>', | |
'go build -o ./dist/<%= genProcString() %> ./src/app/main.go', | |
'cd ./dist && ./<%= getProcName() %> &' | |
], { | |
templateData: { | |
killProc: function() { | |
if(!proc) | |
return ":"; | |
return "killall " + proc; | |
}, | |
genProcString: function() { | |
proc = "_" + (Math.random() + 1).toString(36).substring(7); | |
console.log(proc, getProc()); | |
return proc; | |
}, | |
getProcName: function() { | |
return proc; | |
} | |
} | |
})); | |
}); | |
function getProc() { | |
return proc; | |
} | |
gulp.task('serve', function() { | |
gulp.watch(['./src/templates/**/*.jade'], ['compile:jade']); | |
gulp.watch(['./src/app/**/*.go'], ['restart:go']); | |
}); | |
gulp.task('default', ['clean'], function() { | |
runSequence('compile:jade', 'restart:go'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment