-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
129 lines (116 loc) · 3.11 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
const { series, src, dest, watch } = require("gulp");
const nunjucksRender = require("gulp-nunjucks-render");
const browserSync = require("browser-sync");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const del = require("del");
const cache = require("gulp-cache");
const data = require("gulp-data"); // This plugin calls the JSON data file.
const fs = require("fs"); // Using for the JSON parsing...
const autoprefixer = require("gulp-autoprefixer");
// Nunjucks HTML templating engine
function nunjucks(done) {
return src("src/pages/**/*.njk")
.pipe(
data(function () {
return JSON.parse(fs.readFileSync("src/public/assets/data/data.json"));
})
)
.pipe(nunjucksRender({ path: ["src/templates"] }))
.pipe(dest("src/public"));
done();
}
// Sass compiler
function sassify(done) {
return (
src("src/public/assets/sass/**/*.scss")
.pipe(sourcemaps.init())
// gulp-sass kullanarak Sass dosyasını CSS'e çeviriyor. (nested, compact, expanded, compressed)
.pipe(
sass({
outputStyle: "expanded",
includePaths: ["node_modules/gerillass/scss"]
})
).on("error", function swallowError(error) {
console.log(error.toString());
this.emit("end");
})
.pipe(autoprefixer({ cascade: false }))
.pipe(sourcemaps.write())
.pipe(dest("src/public/assets/css"))
.pipe(browserSync.stream())
);
done();
}
function browser_sync(done) {
browserSync.init({
watch: true,
server: { baseDir: "src/public" },
port: 5000,
});
done();
}
// Moves all the Bootstrap related JavaScript files into the js folder
function bootstrapper(done) {
return src([
"node_modules/bootstrap/dist/js/bootstrap.js",
"node_modules/jquery/dist/jquery.js",
"node_modules/popper.js/dist/popper.js",
])
.pipe(dest("src/public/assets/js"))
.pipe(browserSync.stream());
done();
}
function html() {
return src("src/public/*.html").pipe(dest("dist"));
}
function images() {
return src("src/public/assets/images/**/*.+(png|jpg|gif|svg)").pipe(
dest("dist/assets/images")
);
}
function fonts() {
return src("src/public/assets/fonts/**/*").pipe(dest("dist/assets/fonts"));
}
function css() {
return src("src/public/assets/css/**/*.css").pipe(dest("dist/assets/css/"));
}
function js() {
// The ordering is very important here!
// First it moves all the js files
// Second it overwrites the "scripts.js" file with the transpiled one
return src("src/public/assets/js/**/*.js").pipe(dest("dist/assets/js/"));
}
// Deletes the dist folder
function clean_dist() {
return del("./dist");
}
// Cleans the cache
function clear_cache(done) {
return cache.clearAll(done);
}
function watch_files(done) {
watch("src/**/*.njk", nunjucks);
watch("src/**/*.json", nunjucks);
watch("src/**/*.scss", sassify);
watch("src/**/*.html", browserSync.reload);
done();
}
exports.start = series(
clear_cache,
bootstrapper,
browser_sync,
sassify,
nunjucks,
watch_files
);
exports.build = series(
clean_dist,
bootstrapper,
js,
sassify,
css,
images,
fonts,
html
);