Skip to content

Instantly share code, notes, and snippets.

@pietro909
Created September 24, 2016 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietro909/af76038eea581bf829de2d5bc586ba7b to your computer and use it in GitHub Desktop.
Save pietro909/af76038eea581bf829de2d5bc586ba7b to your computer and use it in GitHub Desktop.
Gulp for Elm, thanks to Stef from Slack channel
'use strict';
var gulp = require('gulp'),
http = require('http'),
st = require('st'),
exec = require('child_process').exec,
gutil = require('gulp-util'),
clear = require('clear'),
counter = 0;
var cmd = 'elm make ./Main.elm --output ./bundle.js';
clear();
gulp.task('default', ['server', 'watch', 'elm']);
gulp.task('watch', function(cb) {
gulp.watch('**/*.elm', ['elm']);
});
gulp.task('server', function(done) {
gutil.log(gutil.colors.blue('Starting server at http://localhost:4000'));
http.createServer(
st({
path: __dirname,
index: 'index.html',
cache: false
})
).listen(4000, done);
});
gulp.task('elm', function(cb) {
if (counter > 0){
clear();
}
exec(cmd, function(err, stdout, stderr) {
if (err){
gutil.log(gutil.colors.red('elm make: '),gutil.colors.red(stderr));
} else {
gutil.log(gutil.colors.green('elm make: '), gutil.colors.green(stdout));
}
cb();
});
counter++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment