Skip to content

Instantly share code, notes, and snippets.

@LordZamy
Created May 18, 2015 19:13
Show Gist options
  • Save LordZamy/62f014fea09eed2f292a to your computer and use it in GitHub Desktop.
Save LordZamy/62f014fea09eed2f292a to your computer and use it in GitHub Desktop.
restart:go being annoying af
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