forked from LimeSurvey/LimeSurvey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
262 lines (240 loc) · 7.96 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
// for bootstrap 5:
// gulp build / gulp watch
// for admintheme:
// gulp build_theme / gulp watch_theme
// for survey_theme_fruity:
// gulp build_survey_theme_fruity / gulp watch_survey_theme_fruity
// for survey_theme_ls6:
// gulp build_survey_theme_ls6 / gulp watch_survey_theme_ls6
const {watch, series, parallel} = require('gulp');
const {src, dest} = require('gulp');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const sass = require('gulp-sass')(require('sass'));
const gulppostcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const concat = require('gulp-concat');
const rtlcss = require('gulp-rtlcss');
const gulpIf = require('gulp-if');
const useref = require('gulp-useref');
const replace = require('gulp-replace');
const merge = require('merge-stream');
const sourcemaps = require('gulp-sourcemaps');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const browserify = require('browserify');
const header = require('gulp-header');
const fs = require('fs');
function js_minify() {
// browserify package handler
return browserify({
entries: ['assets/bootstrap_5/js/bootstrap_5.js']
})
// transform babelify ES6 to ES5 [@babel/preset-env]
.transform(babelify, {
presets: ['@babel/preset-env'],
retainLines: false,
compact: false,
global: true
})
// bundle the transformed code
.bundle()
// sourcemap
.pipe(source('assets/bootstrap_5/js/bootstrap_5.js'))
// rename
.pipe(rename('bootstrap_5.js'))
// buffer
.pipe(buffer())
// distination
.pipe(dest('assets/bootstrap_5/build/js/'))
.pipe(uglify())
.pipe(rename({extname: '.min.js'}))
.pipe(dest('assets/bootstrap_5/build/js/'));
}
function scss_transpile() {
return src('assets/bootstrap_5/scss/bootstrap_5.scss')
.pipe(sass());
}
function scss_minify() {
let plugins = [
autoprefixer(),
cssnano()
];
return scss_transpile()
.pipe(dest('assets/bootstrap_5/build/css'))
.pipe(gulppostcss(plugins))
.pipe(rename({extname: '.min.css'}))
.pipe(dest('assets/bootstrap_5/build/css'));
}
function scss_minify_rtl() {
let plugins = [
autoprefixer(),
cssnano()
];
return scss_transpile()
.pipe(rtlcss())
.pipe(rename({suffix: '-rtl'}))
.pipe(dest('assets/bootstrap_5/build/css'))
.pipe(gulppostcss(plugins))
.pipe(rename({extname: '.min.css'}))
.pipe(dest('assets/bootstrap_5/build/css'));
}
exports.watch = function () {
watch('assets/bootstrap_5/js/**/*.js', js_minify);
watch('assets/bootstrap_5/scss/**/*.scss', parallel(scss_minify, scss_minify_rtl));
};
exports.build = parallel(
js_minify,
scss_minify,
scss_minify_rtl
);
function theme() {
let plugins = [
autoprefixer(),
cssnano()
];
return src(['assets/admin_themes/Sea_Green/sea_green.scss'])
.pipe(sass())
.pipe(dest('themes/admin/Sea_Green/css'))
.pipe(gulppostcss(plugins))
.pipe(rename({extname: '.min.css'}))
.pipe(dest('themes/admin/Sea_Green/css'));
}
function theme_rtl() {
let plugins = [
autoprefixer(),
cssnano()
];
return src(['assets/admin_themes/Sea_Green/sea_green.scss'])
.pipe(sass())
.pipe(rtlcss())
.pipe(rename({suffix: '-rtl'}))
.pipe(dest('themes/admin/Sea_Green/css'))
.pipe(gulppostcss(plugins))
.pipe(rename({extname: '.min.css'}))
.pipe(dest('themes/admin/Sea_Green/css'));
}
exports.watch_theme = function () {
watch('assets/admin_themes/**/*.scss', theme);
watch('assets/admin_themes/**/*.scss', theme_rtl);
};
exports.build_theme = parallel(
theme,
theme_rtl
);
function survey_theme_fruity() {
let variations = [
["apple_blossom", "#AA4340"],
["bay_of_many", "#214F7E"],
["black_pearl", "#071630"],
["free_magenta", "#C63678"],
["purple_tentacle", "#993399"],
["sea_green", "#328637"],
["sunset_orange", "#FE5B35"],
["skyline_blue", "#91dcff"]
];
let plugins = [
autoprefixer(),
cssnano()
];
let variationsFiles = variations.map(variation => {
let variationName = variation[0];
let variationColor = variation[1];
return src(['assets/survey_themes/fruity/fruityThemeTemplate.scss'])
.pipe(replace('$base-color: #ffffff;', '$base-color: ' + variationColor + ';'))
.pipe(sass())
.pipe(gulppostcss(plugins))
.pipe(rename(variationName + '.css'))
.pipe(dest('themes/survey/fruity/css/variations'));
});
return merge(variationsFiles);
}
exports.build_survey_theme_fruity = parallel(
survey_theme_fruity
);
exports.watch_survey_theme_fruity = function () {
watch('assets/survey_themes/fruity/src/**/*.scss', survey_theme_fruity);
};
function survey_theme_ls6() {
let variations = [
["apple", "#14AE5C"],
["blueberry", "#5076FF"],
["grape", "#8146F6"],
["mango", "#ED5046"],
];
let plugins = [
autoprefixer(),
// cssnano()
];
let variationsFiles = variations.map(variation => {
let variationName = variation[0];
let variationColor = variation[1];
return src(['assets/survey_themes/fruity_twentythree/theme_template.scss'])
.pipe(replace('$base-color: #ffffff;', '$base-color: ' + variationColor + ';'))
.pipe(sass())
.pipe(gulppostcss(plugins))
.pipe(rename('theme_' + variationName + '.css'))
.pipe(dest('themes/survey/fruity_twentythree/css/variations'));
});
return merge(variationsFiles);
}
function survey_theme_ls6_rtl() {
let variations = [
["apple", "#14AE5C"],
["blueberry", "#5076FF"],
["grape", "#8146F6"],
["mango", "#ED5046"],
];
let plugins = [
autoprefixer(),
// cssnano()
];
let variationsFiles = variations.map(variation => {
let variationName = variation[0];
let variationColor = variation[1];
return src(['assets/survey_themes/fruity_twentythree/theme_template.scss'])
.pipe(replace('$base-color: #ffffff;', '$base-color: ' + variationColor + ';'))
.pipe(sass())
.pipe(rtlcss())
.pipe(gulppostcss(plugins))
.pipe(rename('theme_' + variationName + '-rtl.css'))
.pipe(dest('themes/survey/fruity_twentythree/css/variations'));
});
return merge(variationsFiles);
}
function survey_theme_ls6_js() {
// browserify package handler
return browserify({
entries: ['assets/survey_themes/fruity_twentythree/theme_js_modules.js']
})
// transform babelify ES6 to ES5 [@babel/preset-env]
.transform(babelify, {
presets: ['@babel/preset-env'],
retainLines: false,
compact: false,
global: true
})
// bundle the transformed code
.bundle()
// sourcemap
.pipe(source('assets/survey_themes/fruity_twentythree/theme_js_modules.js'))
// rename
.pipe(rename('theme.js'))
// buffer
.pipe(buffer())
// distination
.pipe(header(fs.readFileSync('assets/survey_themes/fruity_twentythree/theme_js_disclaimer.js')))
.pipe(dest('themes/survey/fruity_twentythree/scripts/'));
}
exports.build_survey_theme_ls6 = parallel(
survey_theme_ls6,
survey_theme_ls6_rtl,
survey_theme_ls6_js
);
exports.watch_survey_theme_ls6 = function () {
watch('assets/survey_themes/fruity_twentythree/**/*.scss', survey_theme_ls6);
watch('assets/survey_themes/fruity_twentythree/**/*.scss', survey_theme_ls6_rtl);
watch('assets/survey_themes/fruity_twentythree/**/*.js', survey_theme_ls6_js);
};