-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (104 loc) · 3.06 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var browserify = require('browserify'),
bower = require('gulp-bower'),
concat = require('gulp-concat'),
karma = require('gulp-karma'),
gulp = require('gulp'),
gutil = require('gulp-util'),
shell = require('gulp-shell'),
jade = require('gulp-jade'),
jshint = require('gulp-jshint'),
stylus = require('gulp-stylus'),
minifyHtml = require('gulp-minify-html'),
nodemon = require('gulp-nodemon'),
path = require('path'),
protractor = require('gulp-protractor').protractor,
source = require('vinyl-source-stream'),
stringify = require('stringify'),
watchify = require('watchify'),
mocha = require('gulp-mocha'),
exit = require('gulp-exit'),
request = require('request');
var paths = {
public: 'public/**',
jade: 'app/**/*.jade',
styles: 'app/styles/layout.styl',
scripts: 'app/**/*.js',
staticFiles: [
'!app/**/*.+(styl|css|js|jade)',
'app/**/*.*'
],
clientTests: [],
serverTests: ['test/server/**/*.js']
};
gulp.task('jade', function() {
gulp.src(paths.jade)
.pipe(jade())
.pipe(gulp.dest('./public/'));
});
gulp.task('styles', function () {
gulp
.src(paths.styles)
.pipe(stylus({
paths: [ path.join(__dirname, 'styles') ]
}))
.pipe(gulp.dest('./public/css'));
});
gulp.task('static-files',function(){
return gulp.src(paths.staticFiles)
.pipe(gulp.dest('public/'));
});
gulp.task('nodemon', function () {
nodemon({ script: 'index.js', ext: 'js', ignore: ['public/**','app/**','node_modules/**'] })
.on('restart', function () {
console.log('>> node restart');
});
});
gulp.task('scripts', function() {
gulp.src(paths.scripts)
.pipe(concat('index.js'))
.pipe(gulp.dest('./public/js'));
});
gulp.task('browserify', function() {
var b = browserify();
b.add('./app/js/application.js');
return b.bundle()
.on('success', gutil.log.bind(gutil, 'Browserify Rebundled'))
.on('error', gutil.log.bind(gutil, 'Browserify Error: in browserify gulp task'))
.pipe(source('index.js'))
.pipe(gulp.dest('./public/js'));
});
gulp.task('watch', function() {
gulp.watch(paths.jade, ['jade']);
gulp.watch(paths.styles, ['styles']);
gulp.watch(paths.scripts, ['browserify']);
});
gulp.task('bower', function() {
return bower()
.pipe(gulp.dest('public/lib/'));
});
gulp.task('test:server', ['test:client'], function() {
return gulp.src(paths.serverTests)
.pipe(mocha({
reporter: 'spec',
timeout: 50000
}))
.pipe(exit());
});
gulp.task('keep-alive', function () {
var env = process.env.NODE_ENV;
if (env === 'production') {
var apiHost = process.env.API_URL;
setInterval(function() {
request.get(apiHost + '/keep-alive', {}, function (err, res, body) {
if (err) {
return err;
}
console.log('This is the response from the API server: ', body);
return;
});
}, 3600000);
}
});
gulp.task('build', ['bower', 'jade', 'styles', 'browserify', 'static-files']);
gulp.task('production', ['nodemon', 'build']);
gulp.task('default', ['keep-alive', 'nodemon', 'build', 'watch']);