forked from jdm-contrib/jdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
74 lines (61 loc) · 2.18 KB
/
gulpfile.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
var gulp = require("gulp"),
fs = require("fs"),
rename = require("gulp-rename"),
del = require("del"),
swig = require("gulp-swig"),
data = require("gulp-data"),
jsonlint = require("gulp-jsonlint");
var translations = JSON.parse(fs.readFileSync("_trans/_config.json")),
rtl = ["fa", "ar"],
sites,
trans,
notes;
gulp.task("jsonlint", function() {
var prev = null;
var sitesSet = new Set();
JSON.parse(fs.readFileSync("sites.json")).forEach(function(site) {
var name = site.name.toUpperCase().replace(/^the\s+/i, "");
// Check for unsorted entries
if (prev && prev > name) {
throw "Sites must be listed in alphanumeric order. " + prev + " needs to come after " + name;
}
prev = name;
// Check for duplicate entries
if (sitesSet.has(name)) {
throw name + " already exists on the list.";
}
sitesSet.add(name);
});
gulp.src("sites.json")
.pipe(jsonlint())
.pipe(jsonlint.reporter());
});
gulp.task("clean", function(callback) {
return del(["docs/*.html"], callback);
});
gulp.task("translate", ["clean"], function() {
translations.forEach(function(translation) {
sites = JSON.parse(fs.readFileSync("sites.json"));
trans = JSON.parse(fs.readFileSync("_trans/" + translation.code + ".json"));
if (translation.code !== "en") {
sites.forEach(function(site, i) {
if (site.notes) {
site.notes = site["notes_"+translation.code] ? site["notes_"+translation.code] : site.notes;
sites[i] = site;
}
});
}
gulp.src("template.html")
.pipe(rename((translation.code === "en" ? "index" : translation.code) + ".html"))
.pipe(data({
trans: translation,
i18n: trans,
sites,
rtl: (rtl.indexOf(translation.code) === -1) ? false : true,
assetPath: "assets"
}))
.pipe(swig())
.pipe(gulp.dest("docs"));
});
});
gulp.task("default", ["jsonlint", "translate"]);