-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
129 lines (113 loc) · 3.13 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
import gulp from "gulp";
import concat from "gulp-concat";
import cleanCss from "gulp-clean-css";
import uglify from "gulp-uglify-es";
// Broken; Is not producting valid images
// import imagemin from "gulp-imagemin";
import pump from "pump";
import fs from 'fs';
import path from 'path';
function copyFiles(srcPath, destPath) {
return new Promise((resolve, reject) => {
fs.readdir(srcPath, (err, files) => {
if (err) {
console.error(`Error reading directory ${srcPath}`, err);
reject(err);
return;
}
files.forEach(file => {
const srcFile = path.join(srcPath, file);
const destFile = path.join(destPath, file);
fs.stat(srcFile, (err, stat) => {
if (err) {
console.error(`Error getting stats for file ${srcFile}`, err);
reject(err);
return;
}
if (stat.isDirectory()) {
fs.mkdir(destFile, { recursive: true }, (err) => {
if (err) {
console.error(`Error creating directory ${destFile}`, err);
reject(err);
return;
}
copyFiles(srcFile, destFile).then(resolve).catch(reject);
});
} else {
fs.mkdir(path.dirname(destFile), { recursive: true }, (err) => {
if (err) {
console.error(`Error creating directory for file ${destFile}`, err);
reject(err);
return;
}
fs.copyFile(srcFile, destFile, (err) => {
if (err) {
console.error(`Error copying file ${srcFile} to ${destFile}`, err);
reject(err);
return;
}
resolve();
});
});
}
});
});
});
});
}
const { series, src, dest } = gulp;
function css() {
return src([
"node_modules/bulma/css/bulma.min.css",
"src/prism.css",
"src/panther.css",
"src/custom.css",
])
.pipe(concat("custom.min.css"))
.pipe(cleanCss())
.pipe(dest("assets/css"));
}
function css_desktop() {
return src([
"node_modules/bulma/css/bulma.min.css",
"src/prism.css",
"src/panther.css",
"src/custom.css",
"src/custom_desktop.css",
])
.pipe(concat("custom_desktop.min.css"))
.pipe(cleanCss())
.pipe(dest("assets/css"));
}
function js(cb) {
pump(
[
src([
"node_modules/vue/dist/vue.js",
"node_modules/lunr/lunr.js",
"src/prism.js",
"src/mermaid.min.js",
"src/custom.js",
]),
concat("bundle.min.js"),
uglify.default(),
dest("assets/js"),
],
cb
);
}
function fonts() {
return src("src/fonts/**/*").pipe(dest("assets/fonts"));
}
function images() {
const srcPath = 'src/images';
const destPath = 'assets/images';
return copyFiles(srcPath, destPath);
}
function watch() {
gulp.watch("src/*.css", css);
gulp.watch("src/*.js", js);
gulp.watch("src/images/**/*.{jpg,png,svg}", images);
}
export default series(css, css_desktop, js, fonts, images);
export const watchTask = series(watch);