-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
122 lines (103 loc) · 3.31 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
"use strict";
// Include gulp
var fs = require("fs");
var gulp = require("gulp");
var sourcemaps = require("gulp-sourcemaps")
var path = require("path");
var browserSync = require("browser-sync").create();
var sass = require('gulp-sass');
var babelify = require('babelify');
var gutil = require('gulp-util');
var replace = require('gulp-replace');
var browserify = require("browserify");
var source = require('vinyl-source-stream');
var reload = browserSync.reload;
var runSequence = require('run-sequence');
var extensions = ['.js','.json','.es6'];
gulp.task('watch',['browserify', 'sass'], function(){
browserSync.init({
server:'./src'
});
gulp.watch("./src/sass/**/*.scss", ['sass']);
gulp.watch("./src/scripts/**/*.js", ['browserify']);
gulp.watch("./src/**/*.html").on('change', reload);
gulp.watch("./src/bundle*.js").on('change', reload);
});
gulp.task('sass',function(){
return gulp.src('./src/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass()).on('error', function logError(error) {
console.error(error);
})
.pipe(sourcemaps.write())
.pipe(gulp.dest('./src/css'))
.pipe(reload({stream:true}));
});
gulp.task('browserify', ['browserify_phone', 'browserify_moderator', 'browserify_screen', 'browserify_summary']);
gulp.task('browserify_phone',function(){
return browserify({entries: './src/scripts/app_phone.js', debug:true, extensions: extensions})
.transform(babelify)
.on('error', gutil.log)
.bundle()
.on('error', gutil.log)
.pipe(source('bundle_phone.js'))
.pipe(gulp.dest('./src'));
});
gulp.task('browserify_moderator',function(){
return browserify({entries: './src/scripts/app_moderator.js', debug:true, extensions: extensions})
.transform(babelify)
.on('error', gutil.log)
.bundle()
.on('error', gutil.log)
.pipe(source('bundle_moderator.js'))
.pipe(gulp.dest('./src'));
});
gulp.task('browserify_screen',function(){
return browserify(['./src/scripts/app_screen.js'], {debug:true})
.transform(babelify)
.on('error', gutil.log)
.bundle()
.on('error', gutil.log)
.pipe(source('bundle_screen.js'))
.pipe(gulp.dest('./src'));
});
gulp.task('browserify_summary',function(){
return browserify(['./src/scripts/app_summary.js'], {debug:true})
.transform(babelify)
.on('error', gutil.log)
.bundle()
.on('error', gutil.log)
.pipe(source('bundle_summary.js'))
.pipe(gulp.dest('./src'));
});
gulp.task("copy", function () {
return gulp.src([
"src/*.html",
"src/*.js",
"src/*.json",
"src/css/**",
"src/assets/**",
],{"base":"./src"})
.pipe(gulp.dest('./public/'));
});
gulp.task("replace", function(){
gulp.src(['./public/bundle_phone.js', './public/bundle_moderator.js'])
.pipe(replace('/* SERVICE_WORKER_REPLACE', ''))
.pipe(replace('SERVICE_WORKER_REPLACE */', ''))
.pipe(gulp.dest('./public/'));
});
gulp.task("replace_timestamp", function(){
gulp.src(['./public/service-worker-phone.js', './public/service-worker-moderator.js'])
.pipe(replace('{timestamp}', Date.now()))
.pipe(gulp.dest('./public/'));
})
gulp.task('build',function(){
runSequence(
['browserify', 'sass'],
'copy',
'replace',
'replace_timestamp'
);
});
/* Default task */
gulp.task("default", ["watch"]);