-
Notifications
You must be signed in to change notification settings - Fork 188
/
gulpfile.babel.js
161 lines (147 loc) · 3.95 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
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
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 run from "gulp-run-command";
import postcss from "gulp-postcss";
import magician from "postcss-font-magician";
import cssnano from "cssnano";
import postcssPresetEnv from "postcss-preset-env";
import rfs from "rfs";
import concat from "gulp-concat";
import terser from "gulp-terser";
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 compileBootstrapLess = () =>
exec(
"node_modules/recess/bin/recess --compile static/bootstrap/bootstrap.less > static/css/bootstrap.css"
);
const compileResponsiveLess = () =>
exec(
"node_modules/recess/bin/recess --compile static/bootstrap/responsive.less > static/css/bootstrap_responsive.css"
);
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/**/*.less",
"static/**/*.js",
"!static/**/bootstrap.css",
"!static/**/bootstrap_responsive.css",
"!static/**/elegant.prod.9e9d5ce754.css",
"!static/js/elegant.prod.9e9d5ce754.js",
],
{ ignoreInitial: false },
buildAll
);
};
const pathProdCSS = path.join(
__dirname,
"static/css/elegant.prod.9e9d5ce754.css"
);
const rmProdCSS = (cb) => {
if (fs.existsSync(pathProdCSS)) {
fs.unlinkSync(pathProdCSS);
}
cb();
};
const minifyJS = () => {
return src([
"static/applause-button/applause-button.js",
"static/photoswipe/photoswipe.js",
"static/photoswipe/photoswipe-ui-default.js",
"static/photoswipe/photoswipe-array-from-dom.js",
"static/lunr/lunr.js",
"static/clipboard/clipboard.js",
"static/js/create-instagram-gallery.js",
"static/js/copy-to-clipboard.js",
"static/js/lunr-search-result.js",
"!static/js/elegant.prod.9e9d5ce754.js",
])
.pipe(concat("elegant.prod.9e9d5ce754.js"))
.pipe(terser())
.pipe(dest("static/js/"));
};
const compileCSS = () => {
const plugins = [
// postcssPresetEnv comes with autoprefixer
postcssPresetEnv({ stage: 1 }),
magician({}),
rfs(),
cssnano({
preset: "default",
}),
];
return src([
"static/applause-button/applause-button.css",
"static/photoswipe/photoswipe.css",
"static/photoswipe/default-skin/default-skin.css",
"static/css/*.css",
"!static/css/elegant.prod.9e9d5ce754.css",
])
.pipe(postcss(plugins))
.pipe(concat("elegant.prod.9e9d5ce754.css"))
.pipe(dest("static/css/"));
};
const buildAll = series(
rmProdCSS,
compileBootstrapLess,
compileResponsiveLess,
compileCSS,
minifyJS,
buildContent
);
exports.validate = run("jinja-ninja templates");
exports.js = minifyJS;
exports.css = series(
rmProdCSS,
compileBootstrapLess,
compileResponsiveLess,
compileCSS
);
const build = series(
compileBootstrapLess,
compileResponsiveLess,
compileCSS,
minifyJS,
cleanOutput,
buildContent
);
exports.build = build;
const elegant = series(build, parallel(watchFiles, reload));
exports.elegant = elegant;
exports.default = elegant;