-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
117 lines (102 loc) · 3.39 KB
/
Copy pathgulpfile.js
File metadata and controls
117 lines (102 loc) · 3.39 KB
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
'use strict';
const { src, dest, watch, series } = require('gulp');
const browserSync = require('browser-sync').create();
const del = require('del');
const panini = require('panini');
const prettyHtml = require('gulp-pretty-html');
const { exec } = require('child_process');
const path = require('path');
// BUILD TAILWIND CSS
function buildTailwind(done) {
console.log('---------------BUILDING TAILWIND CSS---------------');
exec(
path.join(__dirname, 'node_modules/.bin/tailwindcss') +
' -i ./src/css/tailwind.css -o ./dist/css/tailwind.css --minify',
(err, stdout, stderr) => {
if (err) { console.error(stderr); return done(err); }
browserSync.reload();
done();
}
);
}
// COMPILE HTML WITH PANINI
// index.html stays at root; all other pages go into subfolders as index.html
const rename = require('gulp-rename');
function compileHTML() {
console.log('---------------COMPILING HTML WITH PANINI---------------');
panini.refresh();
return src('src/pages/**/*.html')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
helpers: 'src/helpers/',
data: 'src/data/'
}))
.pipe(rename(function(file) {
// Keep index.html at root, move others to subdir/index.html
if (file.basename !== 'index') {
file.dirname = file.basename;
file.basename = 'index';
}
}))
.pipe(dest('dist'))
.pipe(browserSync.stream());
}
// COPY SPXP PROFILE FILES TO DIST
function copySPXPProfile() {
console.log('---------------COPYING SPXP PROFILE INTO DIST FOLDER---------------');
return src(['profile/**/*'])
.pipe(dest('dist'))
.pipe(browserSync.stream());
}
// COPY STATIC FILES (htaccess, robots, etc.)
function copyStatic() {
console.log('---------------COPYING STATIC FILES INTO DIST FOLDER---------------');
return src(['src/.htaccess'], { dot: true })
.pipe(dest('dist'));
}
// COPY SELF-HOSTED FONTS TO DIST
function copyFonts() {
console.log('---------------COPYING FONTS INTO DIST FOLDER---------------');
return src(['src/assets/fonts/**/*'])
.pipe(dest('dist/assets/fonts'))
.pipe(browserSync.stream());
}
// PRETTIFY HTML FILES
function prettyHTML() {
console.log('---------------HTML PRETTIFY---------------');
return src('dist/**/*.html')
.pipe(prettyHtml({
indent_size: 4,
indent_char: ' ',
unformatted: ['code', 'pre', 'em', 'strong', 'span', 'i', 'b', 'br']
}))
.pipe(dest('dist'));
}
// DELETE DIST FOLDER
function cleanDist(done) {
console.log('---------------REMOVING OLD FILES FROM DIST---------------');
del.sync('dist');
return done();
}
// BROWSER SYNC
function browserSyncInit(done) {
console.log('---------------BROWSER SYNC---------------');
browserSync.init({
server: './dist'
});
return done();
}
// WATCH FILES (including Tailwind sources)
function watchFiles() {
watch('src/**/*.html', series(compileHTML, prettyHTML, buildTailwind));
watch('src/css/**/*.css', buildTailwind);
watch('profile/**/*', copySPXPProfile);
}
// DEV - local development with live reload
exports.dev = series(cleanDist, copySPXPProfile, copyStatic, copyFonts, compileHTML, prettyHTML, buildTailwind, browserSyncInit, watchFiles);
// BUILD - production build
exports.build = series(cleanDist, copySPXPProfile, copyStatic, copyFonts, compileHTML, prettyHTML, buildTailwind);
// Default task
exports.default = exports.dev;