forked from nvisionative/nvQuickTheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
478 lines (439 loc) · 14.8 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
const bs = require('browser-sync').create(),
gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
jshint = require('gulp-jshint'),
sass = require('gulp-sass')(require('sass')),
imagemin = require('gulp-imagemin'),
modernizr = require('gulp-modernizr'),
imwebp = require('imagemin-webp'),
webp = require('gulp-webp'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify-es').default,
log = require('fancy-log'),
replace = require('gulp-replace'),
zip = require('gulp-zip'),
clean = require('gulp-clean'),
cleanCSS = require('gulp-clean-css'),
details = require('./project-details.json'),
project = details.project,
version = details.version,
author = details.author,
company = details.company,
url = details.url,
email = details.email,
description = details.description;
const paths = {
projectdetails: {
src: './project-details.json'
},
fonts: {
src: './src/fonts/*',
dest: './dist/fonts/'
},
faFonts: {
src: [
'./node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.*',
'./node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.*'
],
dest: './dist/webfonts/'
},
faCss: {
src: [
'./node_modules/@fortawesome/fontawesome-free/css/brands.min.css',
'./node_modules/@fortawesome/fontawesome-free/css/solid.min.css',
'./node_modules/@fortawesome/fontawesome-free/css/fontawesome.min.css',
],
dest: './dist/css/'
},
normalize: {
src: './node_modules/normalize.css/normalize.css',
dest: './dist/css/'
},
bsJs: {
src: './node_modules/bootstrap/dist/js/bootstrap.bundle.min.*',
dest: './dist/js/'
},
images: {
src: './src/images/**/*.{jpg,jpeg,png,gif,svg,webp}',
dest: './dist/images/'
},
styles: {
src: './src/scss/**/*.scss',
dest: './dist/css/'
},
scripts: {
src: './src/js/*.js',
dest: './dist/js/'
},
containers: {
src: './containers/*',
dest: '../../Containers/'+project+'/'
},
manifest: {
src: './manifest.dnn',
dest: './'
},
zipdist: {
src: 'dist/**/*',
zipfile: 'dist.zip',
dest: './temp/'
},
zipcontainers: {
src: './containers/**/*',
zipfile: 'cont.zip',
dest: './temp/'
},
zipelse: {
src: ['./menus/**/*', './partials/*', '*.{ascx,xml,html,htm}', 'koi.json'],
zipfile: 'else.zip',
dest: './temp/'
},
zippackage: {
src: ['./temp/*.zip','*.{dnn,png,jpg,txt}', 'LICENSE'],
zipfile: project+'\_'+version+'\_install.zip',
dest: './build/'
},
cleantemp: {
src: './temp/'
},
cleandist: {
src: './dist/'
}
};
/*------------------------------------------------------*/
/* INIT TASKS ------------------------------------------*/
/*------------------------------------------------------*/
// Copy fonts from src/fonts to dist/fonts
function fontsInit() {
let nSrc=0;
return gulp.src(paths.fonts.src)
.pipe(gulp.dest(paths.fonts.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'font files distributed!');
})
}
// Copy fontawesome-free fonts from node_modules to dist/fonts
function faFontsInit() {
let nSrc=0;
return gulp.src(paths.faFonts.src)
.pipe(gulp.dest(paths.faFonts.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'FontAwesome files distributed!');
})
}
// Copy fontawesome-free CSS from node_modules to dist/css/fontawesome-free
function faCssInit() {
let nSrc=0;
return gulp.src(paths.faCss.src)
.pipe(gulp.dest(paths.faCss.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'CSS files distributed!');
})
}
// Compile normalize.css from node_modules and copy to dist/js
function normalizeInit() {
let nSrc=0;
return gulp.src(paths.normalize.src, { sourcemaps: true })
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(cleanCSS())
.pipe(rename({suffix: '.min'}))
.pipe(autoprefixer())
.pipe(gulp.dest(paths.normalize.dest, { sourcemaps: '.' }))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'normalize files distributed!');
})
}
// Copy bootstrap JS from node_modules to dist/js
function bsJsInit() {
let nSrc=0;
return gulp.src(paths.bsJs.src)
.pipe(gulp.dest(paths.bsJs.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'Bootstrap JS files distributed!');
})
}
// modernizr Init
function modernizrInit() {
let nSrc=0;
return gulp.src(paths.scripts.src)
.pipe(modernizr({
'options': [
'setClasses'
],
'tests': [
'webp'
]
}))
.pipe(uglify())
.pipe(rename({suffix: '-custom.min'}))
.pipe(gulp.dest(paths.scripts.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'modernizr files distributed!');
})
}
/*------------------------------------------------------*/
/* END INIT TASKS --------------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* IMAGE TASKS -----------------------------------------*/
/*------------------------------------------------------*/
// Optimize images and copy to dist/images
function optimize() {
let nSrc=0;
return gulp.src(paths.images.src, {since: gulp.lastRun(images)})
.pipe(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.mozjpeg({quality: 75, progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
], {
plugins: imwebp({quality:75})
}
))
.pipe(gulp.dest(paths.images.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'images optimized!');
})
}
// Make WebP versions of all images
function convert() {
let nSrc=0;
return gulp.src(paths.images.src, {since: gulp.lastRun(images)})
.pipe(webp())
.pipe(gulp.dest(paths.images.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'webp files created!');
})
}
/*------------------------------------------------------*/
/* END IMAGE TASKS -------------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* STYLES TASKS ----------------------------------------*/
/*------------------------------------------------------*/
// Compile custom SCSS to CSS and copy to dist/css
function styles() {
return gulp.src(paths.styles.src, { sourcemaps: true })
.pipe(sass({includePaths: ['./node_modules']},{outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(cleanCSS())
.pipe(rename({suffix: '.min'}))
.pipe(autoprefixer())
.pipe(gulp.dest(paths.styles.dest, { sourcemaps: '.' }))
.on('end', function() {
log('SCSS compiled, minified, and distributed!');
})
}
/*------------------------------------------------------*/
/* END STYLES TASKS ------------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* SCRIPTS TASKS ---------------------------------------*/
/*------------------------------------------------------*/
// Compile custom JS and copy to dist/js
function scripts() {
return gulp.src(paths.scripts.src, { sourcemaps: true })
.pipe(jshint())
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.scripts.dest, { sourcemaps: '.' }))
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
.on('end', function() {
log('JS uglified and distributed!');
})
}
/*------------------------------------------------------*/
/* END SCRIPTS TASKS -----------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* DNN TASKS -------------------------------------------*/
/*------------------------------------------------------*/
// Copy containers to proper DNN theme containers folder
function containers() {
let nSrc=0;
return gulp.src(paths.containers.src)
.pipe(gulp.dest(paths.containers.dest))
.on('data', function() { nSrc+=1; })
.on('end', function() {
log(nSrc, 'container files distributed!');
})
}
// Update manifest.dnn
function manifest() {
return gulp.src(paths.manifest.src)
.pipe(replace(/\<package name\=\"(.*?)(?=\")/, '<package name="'+company+ '.' +project))
.pipe(replace(/type\=\"Skin\" version\=\"(.*?)(?=\")/, 'type="Skin" version="'+version))
.pipe(replace(/\<friendlyName\>(.*?)(?=\<)/, '<friendlyName>'+project))
.pipe(replace(/\<description\>(.*?)(?=\<)/, '<description>'+description))
.pipe(replace(/\<name\>(.*?)(?=\<)/, '<name>'+author))
.pipe(replace(/\<organization\>(.*?)(?=\<)/, '<organization>'+company))
.pipe(replace(/\<url\>(.*?)(?=\<)/, '<url>'+url))
.pipe(replace(/\<email\>(.*?)(?=\<)/, '<email>'+email))
.pipe(replace(/\<skinName\>(.*?)(?=\<)/, '<skinName>'+project))
.pipe(replace(/(\\Skins\\)(.*?)(?=\\)/g, '\\Skins\\'+project))
.pipe(replace(/(\\Containers\\)(.*?)(?=\\)/g, '\\Containers\\'+project))
.pipe(gulp.dest(paths.manifest.dest))
.on('end', function() {
log('DNN manifest updated!');
})
}
/*------------------------------------------------------*/
/* END DNN TASKS ---------------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* MAINTENANCE TASKS -----------------------------------*/
/*------------------------------------------------------*/
// Clean up dist folder
function cleandist() {
return gulp.src(paths.cleandist.src, { allowEmpty: true })
.pipe(clean())
.on('end', function() {
log('dist folder cleaned up!');
})
}
/*------------------------------------------------------*/
/* END MAINTENANCE TASKS -------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* PACKAGING TASKS -------------------------------------*/
/*------------------------------------------------------*/
// ZIP contents of dist folder
function zipdist() {
return gulp.src(paths.zipdist.src)
.pipe(zip(paths.zipdist.zipfile))
.pipe(gulp.dest(paths.zipdist.dest))
.on('end', function() {
log('zipdist temporarily created!');
})
}
// ZIP contents of containers folder
function zipcontainers() {
return gulp.src(paths.zipcontainers.src)
.pipe(zip(paths.zipcontainers.zipfile))
.pipe(gulp.dest(paths.zipcontainers.dest))
.on('end', function() {
log('zipcontainers temporarily created!');
})
}
// ZIP everything else
function zipelse() {
return gulp.src(paths.zipelse.src, {base: '.'})
.pipe(gulp.dest(paths.zipelse.dest))
.on('end', function() {
log('zipelse temporarily created!');
})
.pipe(replace('dist/', ''))
.pipe(zip(paths.zipelse.zipfile))
.pipe(gulp.dest(paths.zipelse.dest))
.on('end', function() {
log('dist path removed and zipdist temporarily recreated!');
})
}
// git ziptemp
const ziptemp = gulp.series(zipdist, zipcontainers, zipelse);
// Assemble files into DNN theme install package
function zippackage() {
return gulp.src(paths.zippackage.src)
.pipe(zip(paths.zippackage.zipfile))
.pipe(gulp.dest(paths.zippackage.dest))
.on('end', function() {
log('Theme install package created!');
})
}
// Clean temp folder
function cleantemp() {
return gulp.src(paths.cleantemp.src)
.pipe(clean())
.on('end', function() {
log('temp folder cleaned up!');
})
}
/*------------------------------------------------------*/
/* END PACKAGING TASKS ---------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* DEV TASKS -------------------------------------------*/
/*------------------------------------------------------*/
//gulp serve
function serve() {
bs.init({
proxy: "nvQuickTheme.loc",
rewriteRules: [
{
match: /w\[".*"].*/g,
fn: (req, _res, match) => {
return match.replace(/(http:\/\/|https:\/\/)[a-zA-Z0-9.-]+\//g, `//${req.headers.host}/`);
}
},
],
});
gulp.watch(paths.images.src, images).on('change', bs.reload);
gulp.watch(paths.styles.src, styles).on('change', bs.reload);
gulp.watch(paths.scripts.src, scripts).on('change', bs.reload);
gulp.watch(paths.containers.src, containers).on('change', bs.reload);
}
// gulp watch
function watch() {
gulp.watch(paths.images.src, images);
gulp.watch(paths.styles.src, styles);
gulp.watch(paths.scripts.src, scripts);
gulp.watch(paths.containers.src, containers);
}
// gulp images
const images = gulp.series(optimize, convert);
// gulp init
const init = gulp.series(fontsInit, faFontsInit, faCssInit, normalizeInit, bsJsInit, modernizrInit);
// gulp build
const build = gulp.series(cleandist, init, styles, scripts, images, containers, manifest);
// gulp packageTheme
const packageTheme = gulp.series(build, ziptemp, zippackage, cleantemp);
/*------------------------------------------------------*/
/* END DEV TASKS ---------------------------------------*/
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* EXPORT TASKS ----------------------------------------*/
/*------------------------------------------------------*/
// You can use CommonJS `exports` module notation to declare tasks
exports.fontsInit = fontsInit;
exports.faFontsInit = faFontsInit;
exports.faCssInit = faCssInit;
exports.normalizeInit = normalizeInit;
exports.bsJsInit = bsJsInit;
exports.convert = convert;
exports.optimize = optimize;
exports.images = images;
exports.modernizrInit = modernizrInit;
exports.styles = styles;
exports.scripts = scripts;
exports.containers = containers;
exports.manifest = manifest;
exports.cleandist = cleandist;
exports.zipdist = zipdist;
exports.zipcontainers = zipcontainers;
exports.zipelse = zipelse;
exports.ziptemp = ziptemp;
exports.zippackage = zippackage;
exports.cleantemp = cleantemp;
exports.serve = serve;
exports.watch = watch;
exports.init = init;
exports.build = build;
exports.packageTheme = packageTheme;
// Define default task that can be called by just running `gulp` from cli
exports.default = build;
/*------------------------------------------------------*/
/* END EXPORT TASKS ------------------------------------*/
/*------------------------------------------------------*/