-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
39 lines (36 loc) · 1.13 KB
/
gulpfile.js
File metadata and controls
39 lines (36 loc) · 1.13 KB
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
require("dotenv").config();
const fs = require("fs");
const gulp = require("gulp");
const merge = require("gulp-merge-json");
const plumber = require("gulp-plumber");
const jeditor = require("gulp-json-editor");
const mapify = () => {
const index = JSON.parse(fs.readFileSync("./styles/map/base.json")).imports;
const tileSource =
process.env.NODE_ENV === "production" ? "remote" : process.env.TILES;
return gulp
.src(["base", ...index].map(l => `styles/map/${l}.json`))
.pipe(plumber())
.pipe(
merge({
fileName: "mapbox-styles.json",
concatArrays: true
})
)
.on("error", err => console.log(err))
.pipe(
jeditor(function(json) {
json.sources = json[tileSource];
json.layers = json.layers.map(l => {
const source = tileSource == "local" ? "local" : "composite";
l.source = l.source == "$source" ? source : l.source;
return l;
});
return json;
})
)
.pipe(gulp.dest("public/dist"));
};
gulp.task("watch", () => gulp.watch("styles/map/*.json", mapify));
gulp.task("default", mapify);
gulp.task("mapify", mapify);