-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
189 lines (157 loc) · 5.75 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
//jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
useref = require('gulp-useref');
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
clean = require('gulp-rimraf'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
lr = require('tiny-lr'),
server = lr(),
main_scripts = [ 'node_modules/socket.io-client/socket.io.js',
'bower_components/three.js/three.js',
'assets/scripts/libs/*.js'],
live_scripts = [ 'bower_components/recordrtc/RecordRTC.js',
'assets/scripts/live.js'],
stage_scripts = [ 'assets/scripts/stage.js' ];
// Styles
gulp.task('styles', function() {
return gulp.src('assets/styles/main.scss')
.pipe(sass()) //{ style: 'expanded', }
.pipe(autoprefixer({ browsers: ['last 2 versions'], cascade: false }))
.pipe(gulp.dest('dist/assets/styles'))
.pipe(rename({ suffix: '.min' }))
.pipe(cssnano())
.pipe(livereload(server))
.pipe(gulp.dest('dist/assets/styles'))
.pipe(notify({ message: 'Styles task complete' }));
});
// DEV Styles
gulp.task('dev_styles', function() {
return gulp.src('assets/styles/main.scss')
.pipe(sass()) //{ style: 'expanded', }
.pipe(autoprefixer({ browsers: ['last 2 versions'], cascade: false }))
.pipe(gulp.dest('assets/styles')) //create a DEV version for node server to see it
.pipe(notify({ message: 'DEV Styles task complete' }));
});
// Templates
gulp.task('templates', function() {
return gulp.src(['templates/**/*'])
.pipe(useref({ noAssets: true }))
.pipe(gulp.dest('dist/templates'));
});
//node scripts
gulp.task('node_scripts', function() {
gulp.src(['./*.js','!./gulpfile.js'])
.pipe(gulp.dest('dist'))
.pipe(notify({ message: 'NodeJS Scripts task complete' }));
});
// LIVE Scripts
gulp.task('live_scripts', function() {
return gulp.src(live_scripts)
//.pipe(jshint('.jshintrc'))
//.pipe(jshint.reporter('default'))
.pipe(concat('live.js'))
.pipe(gulp.dest('dist/assets/scripts'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(livereload(server))
.pipe(gulp.dest('dist/assets/scripts'))
.pipe(notify({ message: 'Stand-alone Scripts task complete' }));
});
// STAGE Scripts
gulp.task('stage_scripts', function() {
return gulp.src(stage_scripts)
//.pipe(jshint('.jshintrc'))
//.pipe(jshint.reporter('default'))
.pipe(concat('stage.js'))
.pipe(gulp.dest('dist/assets/scripts'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(livereload(server))
.pipe(gulp.dest('dist/assets/scripts'))
.pipe(notify({ message: 'Stand-alone Scripts task complete' }));
});
// MAIN (common) Scripts
gulp.task('main_scripts', function() {
return gulp.src(main_scripts)
//.pipe(jshint('.jshintrc'))
//.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/assets/scripts'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(livereload(server))
.pipe(gulp.dest('dist/assets/scripts'))
.pipe(notify({ message: 'General Scripts task complete' }));
});
// Images
gulp.task('images', function() {
return gulp.src('assets/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(livereload(server))
.pipe(gulp.dest('dist/assets/images'))
.pipe(notify({ message: 'Images task complete' }));
});
// Clean
gulp.task('clean', function() {
return gulp.src(['dist/assets/styles', 'dist/scripts', 'dist/images', 'dist/templates', 'dist/index.js', 'dist/middleware.js'], {read: false})
.pipe(clean());
});
// Default task
gulp.task('default', ['clean','node_scripts', 'styles', 'main_scripts', 'stage_scripts','live_scripts', 'images', 'templates']).on('change', function() {
gulp.run();
});
// Watch
gulp.task('watch', function() {
// Listen on port 35729
server.listen(35729, function (err) {
if (err) {
return console.log(err)
};
// Watch .scss files
gulp.watch('assets/styles/**/*.scss', ['styles']).on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
// Watch .js files
gulp.watch('assets/scripts/**/*.js', ['main_scripts','stage_scripts','live_scripts']).on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
// Watch image files
gulp.watch('assets/images/**/*', ['images']).on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
// Watch HTML files
gulp.watch('assets/templates/**/*', ['templates']).on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
// Watch HTML files
gulp.watch(['./index.js', './middleware.js'], ['server']).on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
});
// DEV tasks
gulp.task('dev', ['clean','dev_styles', 'watch_dev']).on('change', function() {
gulp.run();
});
// Watch
gulp.task('watch_dev', function() {
// Listen on port 35728
server.listen(35728, function (err) {
if (err) {
return console.log(err)
};
// Watch .scss files
gulp.watch('assets/styles/**/*.scss', ['dev_styles']).on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
});