-
-
Notifications
You must be signed in to change notification settings - Fork 400
/
gulpfile.ts
229 lines (193 loc) · 6.19 KB
/
gulpfile.ts
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import { dest, parallel, series, src, watch } from "gulp";
import { init, write } from "gulp-sourcemaps";
import concat from "gulp-concat";
import gulpSass from "gulp-sass";
import gzip from "gulp-gzip";
import minifyCSS from "gulp-csso";
import sassLib from "sass";
import svgmin from "gulp-svgmin";
import terser from "gulp-terser";
const sass = gulpSass(sassLib);
const jsSrc = [
"./html/js/display*.js",
"./html/js/product-*.js",
"./html/js/search.js",
"./html/js/hc-sticky.js",
"./html/js/stikelem.js",
"./html/js/scrollNav.js",
];
const sassSrc = "./scss/**/*.scss";
const imagesSrc = ["./node_modules/leaflet/dist/**/*.png"];
// nginx needs both uncompressed and compressed files as we use try_files with gzip_static always & gunzip
export function icons() {
const processed = src("*.svg", { cwd: "./icons" }).
pipe(
svgmin({
// @ts-ignore
configFile: "icons/svgo.config.js",
})
).
pipe(dest("./html/images/icons/dist"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/images/icons/dist"));
return processed && compressed;
}
export function attributesIcons() {
const processed = src("*.svg", { cwd: "./html/images/attributes/src" }).
pipe(svgmin()).
pipe(dest("./html/images/attributes/dist"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/images/attributes/dist"));
return processed && compressed;
}
export function css() {
console.log("(re)building css");
const processed = src(sassSrc).
pipe(init()).
pipe(
sass({
errLogToConsole: true,
outputStyle: "expanded",
includePaths: ["./node_modules/foundation-sites/scss"],
}).on("error", sass.logError)
).
pipe(minifyCSS()).
pipe(write(".")).
pipe(dest("./html/css/dist"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/css/dist"));
return processed && compressed;
}
export function copyJs() {
const processed = src([
"./node_modules/@webcomponents/**/webcomponentsjs/**/*.js",
"./node_modules/foundation-sites/js/vendor/*.js",
"./node_modules/foundation-sites/js/foundation.js",
"./node_modules/papaparse/papaparse.js",
"./node_modules/osmtogeojson/osmtogeojson.js",
"./node_modules/leaflet/dist/leaflet.js",
"./node_modules/leaflet.markercluster/dist/leaflet.markercluster.js",
"./node_modules/blueimp-tmpl/js/tmpl.js",
"./node_modules/blueimp-load-image/js/load-image.all.min.js",
"./node_modules/blueimp-canvas-to-blob/js/canvas-to-blob.js",
"./node_modules/blueimp-file-upload/js/*.js",
"./node_modules/@yaireo/tagify/dist/tagify.js",
"./node_modules/cropperjs/dist/cropper.js",
"./node_modules/jquery-cropper/dist/jquery-cropper.js",
"./node_modules/jquery-form/src/jquery.form.js",
"./node_modules/highcharts/highcharts.js",
"./node_modules/jsvectormap/dist/jsvectormap.js",
"./node_modules/jsvectormap/dist/maps/world-merc.js",
"./node_modules/select2/dist/js/select2.min.js",
"./node_modules/jsbarcode/dist/JsBarcode.all.min.js",
]).
pipe(init()).
pipe(terser()).
pipe(write(".")).
pipe(dest("./html/js/dist"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/js/dist"));
return processed && compressed;
}
export function buildJs() {
console.log("(re)building js");
const processed = src(jsSrc).
pipe(init()).
pipe(terser()).
pipe(write(".")).
pipe(dest("./html/js/dist"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/js/dist"));
return processed && compressed;
}
function buildjQueryUi() {
const processed = src([
"./node_modules/jquery-ui/ui/jquery-patch.js",
"./node_modules/jquery-ui/ui/version.js",
"./node_modules/jquery-ui/ui/widget.js",
"./node_modules/jquery-ui/ui/position.js",
"./node_modules/jquery-ui/ui/keycode.js",
"./node_modules/jquery-ui/ui/unique-id.js",
"./node_modules/jquery-ui/ui/safe-active-element.js",
"./node_modules/jquery-ui/ui/widgets/autocomplete.js",
"./node_modules/jquery-ui/ui/widgets/menu.js",
]).
pipe(init()).
pipe(terser()).
pipe(concat("jquery-ui.js")).
pipe(write(".")).
pipe(dest("./html/js/dist"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/js/dist"));
return processed && compressed;
}
function jQueryUiThemes() {
const processed = src([
"./node_modules/jquery-ui/themes/base/core.css",
"./node_modules/jquery-ui/themes/base/autocomplete.css",
"./node_modules/jquery-ui/themes/base/menu.css",
"./node_modules/jquery-ui/themes/base/theme.css",
]).
pipe(init()).
pipe(minifyCSS()).
pipe(concat("jquery-ui.css")).
pipe(write(".")).
pipe(dest("./html/css/dist/jqueryui/themes/base"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/css/dist/jqueryui/themes/base"));
return processed && compressed;
}
function copyCss() {
const processed = src([
"./node_modules/leaflet/dist/leaflet.css",
"./node_modules/leaflet.markercluster/dist/MarkerCluster.css",
"./node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css",
"./node_modules/@yaireo/tagify/dist/tagify.css",
"./node_modules/cropperjs/dist/cropper.css",
"./node_modules/select2/dist/css/select2.min.css",
]).
pipe(init()).
pipe(minifyCSS()).
pipe(write(".")).
pipe(dest("./html/css/dist"));
const compressed = processed.
pipe(gzip()).
pipe(dest("./html/css/dist"));
return processed && compressed;
}
function copyImages() {
return src(imagesSrc).pipe(dest("./html/css/dist"));
}
export default function buildAll() {
return new Promise(
parallel(
copyJs,
buildJs,
buildjQueryUi,
copyCss,
copyImages,
jQueryUiThemes,
series(icons, attributesIcons, css)
)
);
}
function watchAll() {
watch(jsSrc, { delay: 500 }, buildJs);
watch(sassSrc, { delay: 500 }, css);
watch(imagesSrc, { delay: 500 }, copyImages);
// do we want to watch everything to support checkout of a branch with new libs ?
}
export { watchAll as watch };
export function dynamic() {
buildAll().then(() => {
console.log("Build succeeded start watching for css and js changes");
watchAll();
});
}