-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
162 lines (141 loc) · 4.71 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const gulp = require('gulp');
const browserify = require('gulp-browserify');
const rename = require('gulp-rename');
const nodemon = require('gulp-nodemon');
const ts = require('gulp-typescript');
const sass = require('gulp-sass');
var browserSync = require('browser-sync');
var path = require('path');
var sourcemaps = require('gulp-sourcemaps');
var backendStream;
var tsServer = ts.createProject('src/server/tsconfig.json');
var tsWebsite = ts.createProject('src/website/ts/tsconfig.json');
/*
* Watch for changes in files.
*/
gulp.task('start', ['browser-sync'], function () {
gulp.watch('src/server/**/*', ['compileServer']);
gulp.watch('src/website/ts/**/*', ['compileWebsite']);
gulp.watch('src/website/public/css/**/*.css', ['copyCSS', 'inject']);
gulp.watch('src/views/**/*.hbs', ['copyViews', 'reload']);
gulp.watch('src/data/**/*', ['copyDataFiles']);
gulp.watch('src/website/public/img/**/*', ['copyImages']);
gulp.watch('src/website/public/js/**/*.js', ['copyJS']);
});
gulp.task('browser-sync', ['nodemon'], function () {
browserSync.init(null, {
open: true
});
});
gulp.task('nodemon', function () {
var started = false;
backendStream = nodemon({
script: 'build/server/main.js',
open: true,
watch: false,
})
.on('start', function () {
if (!started) {
started = true;
}
})
.on('restart', function () {
console.log('Express Restarting...')
//browserSync.reload();
})
.on('crash', function () {
console.error('Application has crashed!\n Restarting in 5 seconds...')
backendStream.emit('restart', 5) // restart the server in 10 seconds
});
});
gulp.task('reload', function () {
browserSync.reload();
})
gulp.task('inject', function () {
return gulp.src('public/css/**/*.css')
.pipe(browserSync.stream());
});
gulp.task('compileServer', function () {
return gulp.src('src/server/**/*.ts')
.pipe(tsServer()).js
.pipe(gulp.dest('build/server'))
.on('end', function () {
backendStream.restart();
});
});
gulp.task('compileWebsite', function (cb) {
return gulp.src('src/website/ts/**/*')
.pipe(tsWebsite()).js
.pipe(gulp.dest('website/public/js'))
.on('end', function () {
gulp.start('browserify');
});
});
/*
* Bundles the scripts, using Browserify.
*/
gulp.task('browserify', function () {
return gulp.src('build/website/public/js/build.js')
.pipe(browserify({
insertGlobals: true
}))
.pipe(rename('bundle.js'))
.pipe(gulp.dest('build/website/public/js', {
overwrite: true
}))
.on('end', function () {
browserSync.reload();
});
});
gulp.task('sass', function () {
gulp.src('src/website/public/sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./public/css/'))
.pipe(browserSync.stream());
});
gulp.task('compileSASS', function () {
gulp.src('src/website/public/sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('build/website/public/css/'))
});
gulp.task('bundleBrowserify', function () {
return gulp.src('build/website/public/js/build.js')
.pipe(browserify({
insertGlobals: true,
debug: !gulp.env.production
}))
.pipe(rename('bundle.js'))
.pipe(gulp.dest('./build/website/public/js'))
.on('end', function () {
browserSync.reload();
});
});
gulp.task('copyDataFiles', function () {
return gulp.src(['src/data/**/*'])
.pipe(gulp.dest('build/data'));
});
gulp.task('copyCSS', function () {
return gulp.src(['src/website/public/css/**/*'])
.pipe(gulp.dest('build/website/public/css'));
});
gulp.task('copyFonts', function () {
return gulp.src(['src/website/public/fonts/**/*'])
.pipe(gulp.dest('build/website/public/fonts'));
});
gulp.task('copyJS', function () {
return gulp.src(['src/website/public/js/**/*'])
.pipe(gulp.dest('build/website/public/js'));
});
gulp.task('copyViews', function () {
return gulp.src(['src/views/**/*'])
.pipe(gulp.dest('build/views'));
});
gulp.task('copyImages', function () {
return gulp.src(['src/website/public/img/**/*'])
.pipe(gulp.dest('build/website/public/img'));
});
gulp.task('copyRev', function () {
return gulp.src(['src/website/public/revolution/**/*'])
.pipe(gulp.dest('build/website/public/revolution'));
});
gulp.task('fullBuild', ['copyDataFiles', 'compileSASS', 'bundleBrowserify', 'copyCSS', 'copyFonts', 'copyJS', 'copyViews', 'copyImages', 'copyRev']);