-
Notifications
You must be signed in to change notification settings - Fork 31
/
gulpfile.js
164 lines (150 loc) · 3.75 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
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
const gulp = require("gulp");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");
const nunjucksRender = require("gulp-nunjucks-render");
const axios = require("axios");
const { Transform } = require("stream");
const File = require("vinyl");
const { existsSync } = require("fs");
var assets = {
js: [
"docs/js/jquery-3.2.1.min.js",
"docs/js/jquery-migrate-3.0.0.min.js",
"docs/plugins/bootstrap/js/popper.min.js",
"docs/plugins/bootstrap/js/bootstrap.min.js",
"docs/js/custom.js",
],
};
var structure = {
index: ["index.html"],
events: ["index.html"],
education: ["index.html"],
schemas: ["index.html"],
"working-groups": [
"identifiers-discovery.html",
"storage-compute.html",
"claims-credentials.html",
"authentication.html",
"did-comm.html",
"sidetree.html",
"secure-data-storage.html",
],
};
var compiledRepos = null;
const repoTopics = {
"wg-auth": 1,
"wg-cc": 1,
"wg-id": 1,
"wg-sc": 1,
"wg-didcomm": 1,
"wg-crypto": 1,
"wg-keri": 1,
"wg-sidetree": 1,
"wg-ws": 1,
};
async function iterateRepos(fn, page = 1) {
return axios
.get(
`https://api.github.com/users/decentralized-identity/repos?type=public&per_page=100&page=${
page || 1
}`,
{
headers: { Accept: "application/vnd.github.mercy-preview+json" },
}
)
.then((response) => {
let repos = response.data;
if (repos && repos.length) {
fn(repos);
if (repos.length === 100) {
return iterateRepos(fn, ++page);
}
}
})
.catch((e) => console.log(e));
}
async function compileRepos() {
if (compiledRepos) return compiledRepos;
compiledRepos = {};
try {
await iterateRepos((repos) => {
repos.forEach((repo) => {
if (repo.topics)
repo.topics.forEach((topic) => {
if (repoTopics[topic]) {
let list = compiledRepos[topic] || (compiledRepos[topic] = []);
list.push(repo);
}
});
});
});
return compiledRepos;
} catch (error) {
return compiledRepos;
}
}
const repoCompilation = compileRepos();
gulp.task("assets", function () {
return gulp
.src(assets.js)
.pipe(uglify())
.pipe(concat("base.js"))
.pipe(gulp.dest("docs/js"));
});
gulp.task("assetsCopy", () => {
return gulp.src("assets/**").pipe(gulp.dest("docs/assets"));
});
gulp.task("templates", async () => {
return gulp
.src(["templates/pages/**/*.html.njk", "templates/pages/**/*.html"])
.pipe(
nunjucksRender({
path: ["templates", "templates/partials", "templates/pages"],
data: {
repos: compiledRepos || (await compileRepos()),
},
}).on("error", (e) => {
console.log(
`Error in ${
e.fileName ? e.fileName : "(filename not available)"
}: ${e.message.toString()}`
);
})
)
.pipe(
new Transform({
objectMode: true,
transform(file, enc, callback) {
if (file instanceof File) {
if (file.path.endsWith(".html.html")) {
file.path = file.path.slice(0, -5);
}
callback(null, file);
} else {
console.log(file);
callback(
new Error("Error, unexpected type received in pipe"),
null
);
}
},
})
)
.pipe(gulp.dest("./docs"));
});
gulp.task("repoCompilation", (done) => {
repoCompilation.then((z) => done());
});
gulp.task(
"build",
gulp.series(
"repoCompilation",
gulp.parallel("assets", "assetsCopy", "templates")
)
);
gulp.task("watch", () =>
gulp.watch(
["templates/**/*", "docs/js/**/*", "!docs/js/base.js"],
gulp.parallel("build")
)
);