forked from vert-x3/vertx-web-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·276 lines (236 loc) · 8.3 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
var bower = require("gulp-bower");
var compress = require("compression");
var connect = require("connect");
var contributors = require("./src/main/community/contributors.js");
var contributorsGen = require("./src-gen/main/community/contributors-gen.js");
var decompress = require("gulp-decompress");
var del = require("del");
var flatten = require("gulp-flatten");
var fs = require("fs");
var githubConfig = require("./github.json");
var gulp = require("gulp");
var gutil = require("gulp-util");
var iconfilter = require("./src/main/filters/iconfilter.js");
var inject = require("gulp-inject-string");
var path = require("path");
var prettyHrtime = require("pretty-hrtime");
var rename = require("gulp-rename");
var replace = require("gulp-replace");
var request = require("request");
var serveStatic = require("serve-static");
var source = require("vinyl-source-stream");
var streamify = require("gulp-streamify");
var swig = require("swig");
var updateContributors = require("./src/main/tasks/update-contributors.js");
var users = require("./src/main/whos_using/users.js");
var Metalsmith = require("metalsmith");
var assets = require("metalsmith-assets");
var autoprefixer = require("metalsmith-autoprefixer");
var cleanCSS = require("metalsmith-clean-css");
var define = require("metalsmith-define");
var htmlMinifier = require("metalsmith-html-minifier");
var ignore = require("metalsmith-ignore");
var less = require("metalsmith-less");
var templates = require("metalsmith-templates");
// path to website on the server in production mode (i.e. when running
// `gulp build`). MUST BE ABSOLUTE AND MUST END WITH A SLASH!
var contextPath = "/";
// path to website on the server in development mode (i.e. when running
// `gulp watch`). MUST BE ABSOLUTE AND MUST END WITH A SLASH!
var contextPathDev = "/";
// port to listen to in development mode (i.e. when running `gulp watch`)
var devPort = 4000;
// website url in production mode (must be absolute; protocol and host may be omitted)
var siteUrl = "" + contextPath;
// website url in development mode (must be absolute; protocol and host may be omitted)
var siteUrlDev = "http://localhost:" + devPort + contextPathDev;
// paths to source files
var paths = {
bootstrap_js: "bower_components/bootstrap/dist/js/bootstrap.min.js",
docs_generated: "target/docs-generated",
entypo: "Entypo+",
less_includes: [
"src/site/stylesheets",
"src/main/less",
"bower_components/bootstrap/less"
],
src: "src/site",
src_gen: "src-gen",
site: "target/site",
vertx2: "src/main/vertx2",
target_asciidoctor_bs_themes: "target/asciidoctor-bs-themes",
target_docs: "target/site/docs",
target_icons: "target/site/assets/icons",
target_scripts: "target/site/javascripts",
target_stylesheets: "target/site/stylesheets",
target_vertx2: "vertx2",
templates: "src/main/templates"
};
// build site
function build(done, dev) {
var useTemplateCache = dev ? false : undefined;
if (!useTemplateCache) {
swig.setDefaults({ cache: false });
}
swig.setTag("icon", iconfilter.parse, iconfilter.compile, iconfilter.ends, iconfilter.block);
var site_url = siteUrl;
if (dev) {
site_url = siteUrlDev;
}
Metalsmith(__dirname)
.source(paths.src)
.destination(paths.site)
// do not remove files already in the target directory
.clean(false)
// compile LESS sources to CSS
.use(less({
render: {
paths: paths.less_includes
}
}))
// remove LESS sources
.use(ignore([
"**/*.less"
]))
// compress css
.use(cleanCSS())
// autoprefix css
.use(autoprefixer())
// define global variables for templates
.use(define({
"site_url": site_url,
"full_time_developers": contributors.full_time_developers,
"contributors": contributors.contributors.concat(contributorsGen.contributors),
"users_home_page": users.users_home_page,
"users_all": users.users_all
}))
// apply template engine in-place
.use(templates({
engine: "swig",
cache: useTemplateCache,
pattern: "**/*.html",
inPlace: true
}))
// apply templates (e.g. header, footer)
.use(templates({
engine: "swig",
cache: useTemplateCache,
pattern: "**/*.html",
directory: paths.templates
}))
// minify HTML
.use(htmlMinifier())
// copy old Vert.x 2 website
.use(assets({
source: paths.vertx2,
destination: paths.target_vertx2
}))
// build site
.build(done);
}
// build docs
function buildDocs(done, dev) {
var site_url = siteUrl;
if (dev) {
site_url = siteUrlDev;
}
Metalsmith(__dirname)
.source(paths.docs_generated)
.destination(paths.target_docs)
// do not remove files already in the target directory
.clean(false)
// define global variables for templates
.use(define({
"site_url": site_url
}))
// apply templates
.use(templates({
engine: "swig",
directory: paths.templates,
pattern: "**/*.html"
}))
// build site
.build(done);
}
// install bower dependencies
gulp.task("bower", function() {
return bower();
});
// download bootstrap themes for AsciiDoc
gulp.task("install-asciidoc-bs-themes", function(done) {
if (fs.existsSync(paths.target_asciidoctor_bs_themes)) {
done();
return;
}
return request("https://github.com/nerk/asciidoctor-bs-themes/archive/92dd167181d3c4ea48061ad4cba40ebc99d7151a.tar.gz")
.pipe(source("asciidoctor-bs-themes.tar.gz"))
.pipe(streamify(decompress({ strip: 1 })))
.pipe(gulp.dest(paths.target_asciidoctor_bs_themes));
});
// copy svg icons
gulp.task("icons", function() {
return gulp.src(path.join(paths.entypo, "**/*.svg"))
.pipe(flatten())
.pipe(rename(function(path) {
// rename 'resize-100%.svg' because the maven-scm-publish-plugin has
// problems with the percent sign which it considers an escape character
if (path.basename === "resize-100%") {
path.basename = "resize-100"
}
}))
.pipe(replace(/id="[^"]+"/, 'id="icon"')) // set id of all icons to a fixed value so we can reference it easier
.pipe(gulp.dest(path.join(paths.target_icons, "entypo")));
});
// copy required javascripts
gulp.task("scripts", ["bower"], function() {
return gulp.src(paths.bootstrap_js)
.pipe(gulp.dest(paths.target_scripts));
});
// build docs
gulp.task("site-docs", function(done) {
buildDocs(done);
})
// build site
gulp.task("site", ["icons", "scripts", "site-docs", "install-asciidoc-bs-themes"], function(done) {
build(done);
});
// build site in development mode
gulp.task("site-dev", ["site"], function(done) {
buildDocs(function() {
build(done, true);
}, true);
});
// start a web server, watch source directory and rebuild if necessary
gulp.task("watch", ["site-dev"], function() {
// start web server
var app = connect();
app.use(compress());
app.use(contextPathDev, serveStatic(paths.site, {
"index": ["index.html"]
}));
app.listen(devPort, function() {
gutil.log("Listening on port", gutil.colors.cyan("4000"), "...");
});
return gulp.watch([paths.src + "/**/*", paths.templates + "/**/*"], {}, function() {
gutil.log("Rebuilding ...");
var start = process.hrtime();
build(function() {
gutil.log("Finished", "'" + gutil.colors.cyan("rebuilding") + "'",
"after", gutil.colors.magenta(prettyHrtime(process.hrtime(start))));
}, true);
});
});
// update the list of people who have contributed to vertx repositories
gulp.task("update-contributors", function() {
return updateContributors(githubConfig.client_id, githubConfig.client_secret,
contributors.full_time_developers.concat(contributors.contributors))
.pipe(inject.wrap("// AUTO-GENERATED FILE. DO NOT EDIT! CALL `gulp update-contributors` INSTEAD.\n" +
"// CREATED: " + Date() + "\nmodule.exports = { contributors: ", " };"))
.pipe(gulp.dest(path.join(paths.src_gen, "main", "community")));
});
// clean target directory
gulp.task("clean", function(cb) {
del([paths.site], cb);
});
// default task
gulp.task("default", ["site"]);