-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
268 lines (230 loc) · 8.39 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
var gulp = require('gulp');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var cssnano = require('gulp-cssnano');
var uglify = require('gulp-uglify');
var rename = require("gulp-rename");
var concat = require("gulp-concat");
var insert = require('gulp-insert');
const plumber = require('gulp-plumber');
var reload = browserSync.reload;
// Static Server + watching scss/html files
gulp.task('serve', ['sassQuizTake', 'sassQuizCreate', 'quizCreateJS', 'quizDashboardJS', 'quizResultsJS', 'quizTakeJS', 'quizTakeIframeParentJS', 'quizTakeUtilityJS'], function() {
browserSync({
proxy: "localhost:10044",
});
// quiz create
gulp.watch('public/quiz-create/css/sass/*.{scss,sass}', ['sassQuizCreate']);
// watch javascript files
// compress on change
gulp.watch('public/quiz-create/js/quiz-create/*.js', ['quizCreateJS']);
gulp.watch('public/quiz-create/js/dashboard.js', ['quizDashboardJS']);
// compress on change
gulp.watch('public/quiz-create/js/quiz-results/*.js', ['quizResultsJS']);
// quiz take
gulp.watch('public/quiz-take/css/sass/*.{scss,sass}', ['sassQuizTake']);
// compress on change
gulp.watch('public/quiz-take/js/quiz-take/*.js', ['quizTakeJS']);
// compress on change
gulp.watch('public/quiz-take/js/iframe-parent/*.js', ['quizTakeIframeParentJS']);
// compress on change Quiz Take utilities
gulp.watch('public/quiz-take/js/utilities/*.js', ['quizTakeUtilityJS']);
// Watch for file changes
onChangeReload = ["public/quiz-create/css/enp_quiz-create.min.css",
"public/quiz-create/templates/*.php",
"public/quiz-create/includes/*.php",
"public/quiz-create/js/dist/quiz-create.min.js",
"public/quiz-take/css/enp_quiz-take.min.css",
"public/quiz-create/templates/partials/*.php",
"public/quiz-take/*.php",
"public/quiz-take/includes/*.php",
"public/quiz-take/js/dist/quiz-take.min.js"
];
gulp.watch(onChangeReload).on('change', reload);
});
gulp.task('sassQuizCreate', function () {
processSASS('public/quiz-create/css/');
});
gulp.task('sassQuizTake', function () {
processSASS('public/quiz-take/css/');
// the slider is in the quiz create css now too...
processSASS('public/quiz-create/css/');
});
gulp.task('quizCreateJS', function(callback) {
runSequence('concatQuizCreateJS',
'compressQuizCreateJS',
callback);
});
gulp.task('concatQuizCreateJS', function() {
rootPath = "public/quiz-create/js/quiz-create/";
src = [rootPath+"quiz-create--utilities.js",
rootPath+"quiz-create--templates.js",
rootPath+"quiz-create--onLoad.js",
rootPath+"quiz-create--ux.js",
"public/quiz-create/js/utilities/display-messages.js",
rootPath+"quiz-create--reorder-question.js",
rootPath+"quiz-create--save-question.js",
rootPath+"quiz-create--save-question-image.js",
rootPath+"quiz-create--save-mc-option.js",
rootPath+"quiz-create--save-slider.js",
rootPath+"quiz-create--save.js",
"public/quiz-take/js/quiz-take/quiz-take--slider.js"
];
filename = 'quiz-create';
dist = 'public/quiz-create/js/dist/';
return concatjQuery(src, filename, dist);
});
gulp.task('compressQuizCreateJS', function() {
dist = 'public/quiz-create/js/dist/';
return compressJS(dist);
});
gulp.task('quizDashboardJS', function(callback) {
runSequence('concatQuizDashboardJS',
'compressQuizCreateJS',
callback);
});
gulp.task('concatQuizDashboardJS', function() {
rootPath = "public/quiz-create/js/";
src = [rootPath+"dashboard.js",
rootPath+"utilities/display-messages.js",
];
filename = 'dashboard';
dist = 'public/quiz-create/js/dist/';
return concatjQuery(src, filename, dist);
});
gulp.task('quizResultsJS', function(callback) {
runSequence('concatQuizResultsJS',
'concatQuizABResultsJS',
'compressQuizCreateJS',
callback);
});
gulp.task('quizABResultsJS', function(callback) {
runSequence('concatQuizABResultsJS',
'compressQuizCreateJS',
callback);
});
gulp.task('concatQuizResultsJS', function() {
rootPath = "public/quiz-create/js/quiz-results/";
src = [rootPath+"quiz-results.js",
rootPath+"quiz-results--init.js",
rootPath+"quiz-results--slider.js"
];
filename = 'quiz-results';
dist = 'public/quiz-create/js/dist/';
return concatjQuery(src, filename, dist);
});
gulp.task('concatQuizABResultsJS', function() {
rootPath = "public/quiz-create/js/quiz-results/";
src = [rootPath+"ab-results.js",
rootPath+"quiz-results--init.js",
rootPath+"quiz-results--slider.js"
];
filename = 'ab-results';
dist = 'public/quiz-create/js/dist/';
return concatjQuery(src, filename, dist);
});
gulp.task('quizTakeJS', function(callback) {
runSequence('concatQuizTakeJS',
'compressQuizTakeJS',
callback);
});
gulp.task('concatQuizTakeJS', function() {
rootPath = "public/quiz-take/js/quiz-take/";
src = [//"public/quiz-take/js/utilities/jquery.ui.touch-punch.min.js",
rootPath+"quiz-take--utilities.js",
rootPath+"quiz-take--templates.js",
rootPath+"quiz-take--ux.js",
rootPath+"quiz-take--postmessage.js",
rootPath+"quiz-take--question.js",
rootPath+"quiz-take--question-explanation.js",
rootPath+"quiz-take--mc-option.js",
rootPath+"quiz-take--slider.js",
rootPath+"quiz-take--quiz-end.js",
rootPath+"quiz-take--quiz-restart.js",
rootPath+"quiz-take--init.js",
];
filename = 'quiz-take';
dist = 'public/quiz-take/js/dist/';
return concatjQuery(src, filename, dist);
});
gulp.task('quizTakeIframeParentJS', function(callback) {
runSequence('concatQuizTakeIframeParentJS',
'compressQuizTakeJS',
callback);
});
gulp.task('concatQuizTakeIframeParentJS', function() {
rootPath = "public/quiz-take/js/iframe-parent/";
src = [rootPath+"enpIframeQuiz.js",
rootPath+"iframe-parent--listener.js",
];
filename = 'iframe-parent';
dist = 'public/quiz-take/js/dist/';
return gulp.src(src)
.pipe(plumber())
.pipe(concat(filename+'.js'))
.pipe(gulp.dest(dist));
});
gulp.task('quizTakeUtilityJS', function(callback) {
runSequence('concatQuizTakeUtilityJS',
'compressQuizTakeJS',
callback);
});
gulp.task('concatQuizTakeUtilityJS', function() {
rootPath = "public/quiz-take/js/utilities/";
src = [rootPath+"html5shiv.min.js",
rootPath+"jquery-ui.min.js",
rootPath+"underscore.min.js",
rootPath+"jquery.ui.touch-punch.min.js"
];
filename = 'utilities';
dist = 'public/quiz-take/js/dist/';
return gulp.src(src)
.pipe(plumber())
.pipe(concat(filename+'.js'))
.pipe(gulp.dest(dist));
});
gulp.task('compressQuizTakeJS', function() {
dist = 'public/quiz-take/js/dist/';
return compressJS(dist);
});
function concatjQuery(src, filename, dist) {
return gulp.src(src)
.pipe(plumber())
.pipe(concat(filename+'.js'))
.pipe(insert.wrap('jQuery( document ).ready( function( $ ) {', '});'))
.pipe(gulp.dest(dist));
}
function compressJS(path) {
return gulp.src([path+"*.js","!"+path+"*.min.js"])
.pipe(plumber())
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(path));
}
function processSASS(path) {
return gulp.src(path+'sass/*.{scss,sass}')
.pipe(plumber())
.pipe(sourcemaps.init())
// Converts Sass into CSS with Gulp Sass
.pipe(sass({
errLogToConsole: true
}))
// adds prefixes to whatever needs to get done
.pipe(autoprefixer())
// minify the CSS
.pipe(cssnano())
// rename to add .min
.pipe(rename({
suffix: '.min'
}))
.pipe(sourcemaps.write('.'))
// Outputs CSS files in the css folder
.pipe(gulp.dest(path));
}
// Creating a default task
gulp.task('default', ['serve']);