/
gulpfile.babel.js
97 lines (87 loc) · 2.26 KB
/
gulpfile.babel.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
import fs from "fs";
import path from "path";
import { src, dest, watch, parallel, series } from "gulp";
import { exec } from "child_process";
import { create as browserSyncCreate } from "browser-sync";
import postcss from "gulp-postcss";
import cssnano from "cssnano";
import postcssPresetEnv from "postcss-preset-env";
import concat from "gulp-concat";
const browserSync = browserSyncCreate();
const path404 = path.join(__dirname, "documentation/output/404.html");
const content_404 = () =>
fs.existsSync(path404) ? fs.readFileSync(path404) : null;
const cleanOutput = () => exec("cd documentation && rm -rf outout/");
const buildContent = () => exec("cd documentation && invoke build");
const reload = cb => {
browserSync.init(
{
ui: {
port: 9002
},
server: {
baseDir: "documentation/output",
serveStaticOptions: {
extensions: ["html"]
}
},
files: "documentation/output/*.html",
port: 9001
},
(_, bs) => {
bs.addMiddleware("*", (_, res) => {
res.write(content_404());
res.end();
});
}
);
cb();
};
const watchFiles = () => {
watch(
[
"documentation/content/**/*.md",
"documentation/content/**/*.rest",
"documentation/pelicanconf.py",
"documentation/publishconf.py",
"templates/**/*.html",
"static/**/*.css",
"!static/**/elegant.prod.css",
"static/**/*.js"
],
{ ignoreInitial: false },
buildAll
);
};
const pathProdCSS = path.join(__dirname, "static/css/elegant.prod.css");
const rmProdCSS = cb => {
if (fs.existsSync(pathProdCSS)) {
fs.unlinkSync(pathProdCSS);
}
cb();
};
const compileCSS = () => {
const plugins = [
// postcssPresetEnv comes with autoprefixer
postcssPresetEnv(),
cssnano()
];
return src([
"static/tipuesearch/tipuesearch.css",
"static/css/*.css",
"!static/css/elegant.prod.css"
])
.pipe(postcss(plugins))
.pipe(concat("elegant.prod.css"))
.pipe(dest("static/css/"));
};
const buildAll = series(rmProdCSS, compileCSS, buildContent);
const elegant = series(
compileCSS,
cleanOutput,
buildContent,
parallel(watchFiles, reload)
);
exports.css = series(rmProdCSS, compileCSS);
exports.elegant = elegant;
exports.default = elegant;