-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
91 lines (79 loc) · 2.51 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
var gulp = require('gulp');
var elm = require('gulp-elm');
var insert = require('gulp-insert');
var nodemon = require('gulp-nodemon');
var gutil = require('gulp-util');
var chalk = require('chalk');
var livereload = require('gulp-livereload');
var open = require('open');
var del = require('del');
var shell = require('gulp-shell');
var notifier = require('node-notifier');
gulp.task('clean', function () {
return del([
'dist/',
// here we use a globbing pattern to match everything inside the `mobile` folder
'frontend/dist',
// we don't want to clean this file though so we negate the pattern
'elm-stuff'
]);
});
gulp.task('test', ['elm-init'], () => {
return gulp.src('tests/*.elm')
.pipe(elm().on('error', gutil.log))
.pipe(gulp.dest('tmp/'))
.pipe(shell(
[ 'echo start elm-test build'
, 'sh ./elm-stuff/packages/laszlopandy/elm-console/1.1.1/elm-io.sh tmp/Main.js tmp/test.js'
, 'node tmp/test.js' ]
))
});
gulp.task('watch-server', ['compile-backend'], function () {
nodemon({
script: 'dist/server.js',
ext: 'js',
watch: [
'dist/server.js'
],
})
.on('restart', function () {
gutil.log(chalk.yellow('Server restarted!'));
});
});
gulp.task('elm-init', elm.init);
gulp.task('compile-backend', ['elm-init'], function () {
return gulp.src('backend/server.elm')
.pipe(elm().on('error', function (err) {
gutil.log(err.message);
notifier.notify({title: 'Error compiling backend', message: err.message});
}))
.pipe(insert.append('Elm.worker(Elm.Main);\n'))
.pipe(gulp.dest('dist/'));
});
gulp.task('develop-backend', ['compile-backend', 'watch-server'], function () {
});
gulp.task('compile-frontend', ['elm-init'], function () {
livereload();
return gulp.src('frontend/Main.elm')
.pipe(elm().on('error', function (err) {
gutil.log(err);
notifier.notify('Error compiling frontend');
}))
.pipe(gulp.dest('frontend/dist'))
.pipe(livereload());
});
gulp.task('reload-index', function () {
gulp.src('frontend/index.html')
.pipe(livereload());
});
gulp.task('build', ['compile-frontend', 'compile-backend']);
gulp.task('default', ['compile-backend', 'compile-frontend', 'watch-server'], function () {
livereload.listen();
// gulp.watch('**/*.elm', ['test']);
gulp.watch('backend/*.elm', ['compile-backend']);
gulp.watch('frontend/*.elm', ['compile-frontend']);
gulp.watch('common/*.elm', ['compile-frontend', 'compile-backend']);
gulp.watch('frontend/index.html', ['reload-index']);
open('http://localhost:8080/');
});