-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
558 lines (514 loc) · 15.5 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
"use strict";
/*
* Gulp Builder for WordPress Theme FAU-Einrichtungen
*/
const { src, dest, watch, series, parallel } = require("gulp"),
sass = require("gulp-sass")(require("sass")),
sourcemaps = require("gulp-sourcemaps"),
uglify = require("gulp-uglify"),
bump = require("gulp-bump"),
semver = require("semver"),
info = require("./package.json"),
wpPot = require("gulp-wp-pot"),
touch = require("gulp-touch-cmd"),
header = require("gulp-header"),
concat = require("gulp-concat"),
replace = require("gulp-replace"),
rename = require("gulp-rename"),
yargs = require("yargs"),
map = require("map-stream");
const clonetarget = yargs.argv.target;
/**
* Template for banner to add to file headers
*/
var banner = [
"/*!",
"Theme Name: <%= info.name %>",
"Version: <%= info.version %>",
"Requires at least: <%= info.compatibility.wprequires %>",
"Tested up to: <%= info.compatibility.wptestedup %>",
"Requires PHP: <%= info.compatibility.phprequires %>",
"Description: <%= info.description %>",
"Theme URI: <%= info.repository.url %>",
"GitHub Theme URI: <%= info.repository.url %>",
"GitHub Issue URL: <%= info.repository.issues %>",
"Author: <%= info.author.name %>",
"Author URI: <%= info.author.url %>",
"License: <%= info.license %>",
"License URI: <%= info.licenseurl %>",
"Tags: <%= info.tags %>",
"Text Domain: <%= info.textdomain %>",
"*/",
].join("\n");
/**
* Create Clone for a given theme
*/
function cloneTheme(cb) {
var targetdir = "";
var farbfamilie = "zuv";
var theme = yargs.argv.theme;
var builddir = yargs.argv.builddir;
if (builddir === undefined) {
builddir = "../build/";
}
switch (theme) {
case "zuv":
targetdir = builddir + "FAU-ZUV/";
farbfamilie = "zuv";
break;
case "phil":
targetdir = builddir + "FAU-Philfak/";
farbfamilie = "phil";
break;
case "med":
targetdir = builddir + "FAU-Medfak/";
farbfamilie = "med";
break;
case "rw":
targetdir = builddir + "FAU-RWFak/";
farbfamilie = "rw";
break;
case "tf":
targetdir = builddir + "FAU-Techfak/";
farbfamilie = "tf";
break;
case "nat":
targetdir = builddir + "FAU-Natfak/";
farbfamilie = "nat";
break;
default:
console.log(
`No valid theme defined. Please use argument: gulp clone --theme=name , with name=(phil|rw|tf|nat|med)`
);
break;
}
if (targetdir === "") {
cb();
return;
}
console.log(`Building theme for: ${theme}`);
console.log(` Target directory: ${targetdir}`);
console.log(` Color: ${farbfamilie}`);
var sassdir = targetdir + info.source.sass;
var variablesfile = sassdir + "_variables.scss";
var constfile = targetdir + "functions/constants.php";
var helpercssbanner = [
"/*!",
"* Backend-CSS for Theme:",
"* Theme Name: <%= info.themeClones." + farbfamilie + ".name %>",
"* Version: <%= info.version %>",
"* GitHub Issue URL: <%= info.repository.issues %>",
"*/",
].join("\n");
var themebanner = [
"/*!",
"Theme Name: <%= info.themeClones." + farbfamilie + ".name %>",
"Version: <%= info.version %>",
"Requires at least: <%= info.compatibility.wprequires %>",
"Tested up to: <%= info.compatibility.wptestedup %>",
"Requires PHP: <%= info.compatibility.phprequires %>",
"Description: <%= info.themeClones." + farbfamilie + ".description %>",
"Theme URI: <%= info.themeClones." + farbfamilie + ".GitHubThemeURI %>",
"GitHub Theme URI: <%= info.themeClones." +
farbfamilie +
".GitHubThemeURI %>",
"GitHub Issue URL: <%= info.repository.issues %>",
"Author: <%= info.author.name %>",
"Author URI: <%= info.author.url %>",
"License: <%= info.license %>",
"License URI: <%= info.licenseurl %>",
"Tags: <%= info.tags %>",
"Text Domain: <%= info.textdomain %>",
"*/",
].join("\n");
// Copy files
function copyprocess() {
console.log(`Starting copy files to ${targetdir}`);
return src([
"**/*",
"!.git{,/**}",
"!node_modules{,/**}",
"!.babelrc",
"!.DS_Store",
"!.gitignore",
"!README.md",
"!package.json",
"!gulpfile.babel.js",
"!package-lock.json",
]).pipe(dest(targetdir));
}
// Update color family in variables.scss
function setcolorfamily() {
console.log(
` - Update color family in ${variablesfile} to ${farbfamilie}`
);
return src([variablesfile])
.pipe(
replace(/farbfamilie: '(.*)'/g, "farbfamilie: '" + farbfamilie + "'")
)
.pipe(dest(sassdir));
}
// Update theme config to the theme type
function setwebsite_usefaculty() {
// find this entry and change it:
// 'website_usefaculty' => '',
// phil, med, nat, rw, tf
console.log(` - Update constfile family ${constfile} to ${farbfamilie}`);
return src([constfile])
.pipe(
replace(
/'website_usefaculty'\s*=>\s*'(.*)'/g,
"'website_usefaculty' => '" + farbfamilie + "'"
)
)
.pipe(dest(targetdir + "functions/"));
}
// Copy theme screenshot in the new base directory
function copyscreenshot() {
var screenshot =
targetdir + "img/screenshots/screenshot-" + farbfamilie + ".png";
console.log(` - Copy screenshot ${screenshot} to ${targetdir}`);
return src([screenshot])
.pipe(rename("screenshot.png"))
.pipe(dest(targetdir));
}
// Copy social media icons in the new base directory
function copysocialmedia() {
var srcsocialmedia = targetdir + "src/favicons/" + farbfamilie + "/**";
var targetsocialmedia = targetdir + "img/socialmedia/";
console.log(
` - Copy Social Media Icons ${srcsocialmedia} to ${targetsocialmedia}`
);
return src([srcsocialmedia]).pipe(dest(targetsocialmedia));
}
// Create Backend Styles for dev
function buildbackendstyles() {
return src([targetdir + info.source.sass + "fau-theme-admin.scss"])
.pipe(header(helpercssbanner, { info: info }))
.pipe(sass({quietDeps: true, outputStyle: 'compressed'}).on("error", sass.logError))
.pipe(dest(targetdir + "css/"))
.pipe(touch());
console.log(` - Backend styles created in ${targetdir}css`);
}
// Create Backend Styles for dev
function buildproductivestyle() {
var inputscss = targetdir + info.source.sass + "fau-theme-style.scss";
console.log(
` - Creating new CSS from SCSS-File ${inputscss} in ${targetdir}style.css`
);
return src([inputscss])
.pipe(header(themebanner, { info: info }))
.pipe(sass({quietDeps: true, outputStyle: 'compressed'}).on("error", sass.logError))
.pipe(rename(info.maincss))
.pipe(dest(targetdir))
.pipe(touch());
}
const dothis = series(
copyprocess,
parallel(
setcolorfamily,
setwebsite_usefaculty,
copyscreenshot,
copysocialmedia
),
buildbackendstyles,
buildproductivestyle
);
dothis();
cb();
return;
}
/*
* SASS and Autoprefix CSS Files, without clean
*/
function devbuildbackendstyles() {
return src([info.source.sass + "fau-theme-admin.scss"])
.pipe(sass({indentWidth: 4, quietDeps: true, precision: 3, sourceComments: true }).on("error", sass.logError))
.pipe(dest("./css"))
.pipe(touch());
}
/*
* Compile all styles with SASS and clean them up
*/
function buildbackendstyles() {
return src([info.source.sass + "fau-theme-admin.scss"])
.pipe(sass({quietDeps: true, outputStyle: 'compressed'}).on("error", sass.logError))
.pipe(dest("./css"))
.pipe(touch());
}
/*
* Main Styles for prod
*/
function buildmainstyle() {
return src([info.source.sass + "fau-theme-style.scss"])
.pipe(header(banner, { info: info }))
.pipe(sass({quietDeps: true, outputStyle: 'compressed' }).on("error", sass.logError))
.pipe(rename(info.maincss))
.pipe(dest("./"))
.pipe(touch());
}
/*
* Main Styles for Dev
*/
function devbuildmainstyle() {
return src([info.source.sass + "fau-theme-style.scss"])
.pipe(header(banner, { info: info }))
.pipe(sourcemaps.init())
.pipe(sass({indentWidth: 4, quietDeps: true, precision: 3, sourceComments: true }).on("error", sass.logError))
.pipe(sourcemaps.write())
.pipe(rename(info.maincss))
.pipe(dest("./"))
.pipe(touch());
}
/*
* Print Styles
*/
function buildprintstyle() {
return src([info.source.sass + "fau-theme-print.scss"])
.pipe(header(banner, { info: info }))
.pipe(sass({outputStyle: 'compressed'}).on("error", sass.logError))
.pipe(rename(info.printcss))
.pipe(dest("./"))
.pipe(touch());
}
// Block Editor Styles for Prod
function buildeditorstyles() {
return src([info.source.sass + "fau-theme-blockeditor.scss"])
.pipe(sass({quietDeps: true, outputStyle: 'compressed'}).on("error", sass.logError))
.pipe(dest("./css"))
.pipe(touch());
}
// Block Editor Styles for Dev
function devbuildeditorstyles() {
return src([info.source.sass + "fau-theme-blockeditor.scss"])
.pipe(sass({indentWidth: 4, quietDeps: true, precision: 3, sourceComments: true }).on("error", sass.logError))
.pipe(dest("./css"))
.pipe(touch());
}
// Classic Editor Styles for Prod
function buildclassiceditorstyles() {
return src([info.source.sass + "fau-theme-classiceditor.scss"])
.pipe(sass({quietDeps: true, outputStyle: 'compressed'}).on("error", sass.logError))
.pipe(dest("./css"))
.pipe(touch());
}
// Classic Editor Styles for Dev
function devbuildclassiceditorstyles() {
return src([info.source.sass + "fau-theme-classiceditor.scss"])
.pipe(sass({indentWidth: 4, quietDeps: true, precision: 3, sourceComments: true }).on("error", sass.logError))
.pipe(dest("./css"))
.pipe(touch());
}
// Main JS
function bundleadminjs() {
return src([
info.source.js + "admin/admin.js",
// info.source.js + 'admin/banner-logo-link-widget.js',
info.source.js + "admin/classic-editor-templateswitch.js"
])
.pipe(concat(info.adminjs))
.pipe(uglify())
.pipe(dest(info.jsdir))
.pipe(touch());
}
// we depart customizerjs from admin js, due to js conflicts
function makecustomizerjs() {
return src([info.source.js + "admin/customizer-range-value-control.js"])
.pipe(uglify())
.pipe(rename("fau-theme-customizer-range-value-control.min.js"))
.pipe(dest(info.jsdir))
.pipe(touch());
}
// we depart wplink from admin js, due to needed extra vals
function makewplinkjs() {
return src([info.source.js + "admin/rrze-wplink.js"])
.pipe(uglify())
.pipe(rename("fau-theme-wplink.min.js"))
.pipe(dest(info.jsdir))
.pipe(touch());
}
function bundlemainjs() {
return src([
info.source.js + "main/jquery.fancybox.js",
// info.source.js + 'main/jquery.hoverIntent.min.js',
// we remove hoverIntent, cause its already provider from wordpress
// info.source.js + 'main/jquery.tablesorter.min.js',
// tablesorter moved in elements plugin (March 2023)
// info.source.js + 'main/slick.js',
// we remove slick from the main js to reduce the data transfered
// in default situations. slick we only use on special pages, where we
// can call it additional
info.source.js + "main/console-errors.js",
info.source.js + "main/main.js",
])
.pipe(concat(info.mainjs))
.pipe(uglify())
.pipe(dest(info.jsdir))
.pipe(touch());
}
function makeslickjs() {
return src([info.source.js + "main/slick.js"])
.pipe(uglify())
.pipe(rename("fau-theme-slick.min.js"))
.pipe(dest(info.jsdir))
.pipe(touch());
}
function makecustomblockjs() {
return src([info.source.js + "main/fau-costum-image-block.js"])
.pipe(uglify())
.pipe(rename("fau-costum-image-block.min.js"))
.pipe(dest(info.jsdir))
.pipe(touch());
}
function makeblockeditorjs() {
return src(["src/js/blockeditor/deregister-blockstyles.js"])
.pipe(uglify())
.pipe(rename("fau-theme-register-blockstyles.min.js"))
.pipe(dest(info.jsdir))
.pipe(touch());
}
function updatepot() {
return src(["**/*.php", "!vendor/**/*.php"])
.pipe(
wpPot({
domain: info.textdomain,
package: info.name,
team: info.author,
bugReport: info.repository.issues,
ignoreTemplateNameHeader: true,
})
)
.pipe(dest("languages/" + info.textdomain + ".pot"))
.pipe(touch());
}
// Set debugmode true
function set_debugmode() {
// find this entry and change it:
// 'website_usefaculty' => '',
// phil, med, nat, rw, tf
var constfile = "./functions/constants.php";
console.log(` - Set Debugmode true in constfile ${constfile}`);
return src([constfile])
.pipe(replace(/'debugmode'\s*=>\s*(.*),/g, "'debugmode' => true,"))
.pipe(dest("./functions/"));
}
// Set debugmode true
function unset_debugmode() {
// find this entry and change it:
// 'website_usefaculty' => '',
// phil, med, nat, rw, tf
var constfile = "./functions/constants.php";
console.log(` - Set Debugmode false in constfile ${constfile}`);
return src([constfile])
.pipe(replace(/'debugmode'\s*=>\s*(.*),/g, "'debugmode' => false,"))
.pipe(dest("./functions/"));
}
/*
* Update Version on Patch-Level
* (All other levels we are doing manually; This level has to update automatically on each build)
*/
function upversionpatch() {
var newVer = semver.inc(info.version, "patch");
return src([
"./package.json",
"./README.md",
"./readme.txt",
"./" + info.maincss,
])
.pipe(
bump({
version: newVer,
})
)
.pipe(dest("./"))
.pipe(touch());
}
/*
* Update DEV Version on prerelease level.
* Reason: in the Theme function, we will recognise the prerelease version by its syntax.
* This will allow the theme automatically switch to the non-minified-files instead of
* the minified versions.
* In other words: If we use dev, the theme wil load script files without ".min.".
*/
function devversion() {
var newVer = semver.inc(info.version, "prerelease");
return src([
"./package.json",
"./README.md",
"./readme.txt",
"./" + info.maincss,
])
.pipe(
bump({
version: newVer,
})
)
.pipe(dest("./"))
.pipe(touch());
}
exports.pot = updatepot;
exports.devversion = devversion;
exports.bundlemainjs = bundlemainjs;
exports.bundleadminjs = bundleadminjs;
exports.makeslickjs = makeslickjs;
exports.makecustomblockjs = makecustomblockjs;
exports.makeblockeditorjs = makeblockeditorjs;
exports.makecustomizerjs = makecustomizerjs;
exports.makewplinkjs = makewplinkjs;
exports.clone = cloneTheme;
exports.buildmainstyle = buildmainstyle;
exports.buildprintstyle = buildprintstyle;
exports.devbuildmainstyle = devbuildmainstyle;
exports.debugmode = set_debugmode;
exports.nodebug = unset_debugmode;
var js = series(
bundlemainjs,
makeslickjs,
makecustomblockjs,
makeblockeditorjs,
bundleadminjs,
makecustomizerjs,
makewplinkjs
);
var dev = series(
devbuildbackendstyles,
devbuildmainstyle,
buildprintstyle,
devbuildeditorstyles,
devbuildclassiceditorstyles,
js,
devversion
);
exports.cssdev = series(
devbuildbackendstyles,
devbuildeditorstyles,
devbuildclassiceditorstyles,
devbuildmainstyle,
buildprintstyle
);
exports.css = series(
devbuildbackendstyles,
devbuildeditorstyles,
devbuildclassiceditorstyles,
devbuildmainstyle,
buildprintstyle);
exports.js = js;
exports.dev = dev;
exports.build = series(
buildbackendstyles,
buildmainstyle,
buildprintstyle,
buildeditorstyles,
buildclassiceditorstyles,
js,
upversionpatch
);
/* Temporary */
exports.watch = function () {
watch(
info.source.sass + "**/*.scss",
{ ignoreInitial: false },
buildprintstyle
);
};
exports.default = dev;