forked from openfoodfacts/openfoodfacts-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
178 lines (159 loc) · 4.98 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
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 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"];
export function icons() {
return src("*.svg", { cwd: "./icons" }).
pipe(
svgmin({
// @ts-ignore
configFile: "icons/svgo.config.js",
})
).
pipe(dest("./html/images/icons/dist"));
}
export function attributesIcons() {
return src("*.svg", { cwd: "./html/images/attributes/src" }).
pipe(svgmin()).
pipe(dest("./html/images/attributes/dist"));
}
export function css() {
console.log("(re)building css");
return 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"));
}
export function copyJs() {
return 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"));
}
export function buildJs() {
console.log("(re)building js");
return src(jsSrc).
pipe(init()).
pipe(terser()).
pipe(write(".")).
pipe(dest("./html/js/dist"));
}
function buildjQueryUi() {
return 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"));
}
function jQueryUiThemes() {
return 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"));
}
function copyCss() {
return 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"));
}
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();
});
}