forked from vonWolfehaus/von-grid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
89 lines (76 loc) · 2.19 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
var gulp = require('gulp');
var fs = require('fs');
var $ = require('gulp-load-plugins')();
var del = require('del');
var runSequence = require('run-sequence');
var path = require('path');
var spawn = require('child_process').spawn;
var node;
var pkg = require('./package.json');
var dist = 'public/dist';
var src = 'public/src';
var PORT = process.env.PORT || 3000;
/**
* $ gulp server
* description: launch the server. If there's a server already running, kill it.
*/
gulp.task('server', function() {
console.log("server");
if (node) node.kill();
node = spawn('node', ['app.js', PORT], {stdio: 'inherit'});
node.on('close', function (code) {
if (code === 8) {
gulp.log('Error detected, waiting for changes...');
}
});
// exec('mongod --dbpath ./data', function (err, stdout, stderr) {
// console.log('starting mongo');
// console.log(stdout);
// console.log(stderr);
// cb(err);
// });
});
/**
* $ gulp
* description: start the development environment
*/
gulp.task('default', function() {
gulp.watch('server');
// gulp.watch(['*.js', 'custom_modules/*.*', 'custom_modules/**/*.*'], function() {
// console.log("watching be");
// runSequence('server');
// });
//
// gulp.watch(['public/src/**/*.*'], function() {
// console.log("watching fe");
// runSequence('hex');
// });
});
gulp.task('hex', function() {
console.log("hex");
gulp.src([src+'/vg.js', src+'/**/*.js', '!src/grids/Hex.js', '!src/grids/HexGrid.js'])
.pipe($.plumber({errorHandler: handleErrors}))
.pipe($.sourcemaps.init())
.pipe($.concat('hex-grid.min.js'))
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dist))
});
// clean up if an error goes unhandled.
process.on('exit', function() {
if (node) run('default');
});
/*----------------------------------------------------------------------
HELPERS
*/
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
// Send error to notification center with gulp-notify
$.notify.onError({
title: 'Build error',
message: '<%= error%>',
showStack: true
}).apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
}