forked from redhat-developer-demos/knative-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
62 lines (55 loc) · 1.77 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
"use strict";
const connect = require("gulp-connect");
const fs = require("fs");
const generator = require("@antora/site-generator-default");
const gulp = require("gulp");
const yaml = require("yaml-js");
let filename = "dev-site.yml";
let args = ["--playbook", filename];
gulp.task("build", function(cb) {
/**
* Use the '@antora/site-generator-default' node module to build.
* It's analogous to `$ antora --playbook local-antora-playbook.yml`.
* Having access to the generator in code may be useful for other
* reasons in the future (i.e to implement custom features).
* NOTE: As opposed to building with the CLI, this method doesn't use
* a separate process for each run. So if a build error occurs with the `gulp`
* command it can be useful to check if it also happens with the CLI command.
*/
generator(args, process.env)
.then(() => {
cb();
})
.catch(err => {
console.log(err);
cb();
});
});
gulp.task("preview", ["build"], function() {
/**
* Remove the line gulp.src('README.adoc')
* This is placeholder code to follow the gulp-connect
* example. Could not make it work any other way.
*/
gulp.src("README.adoc").pipe(connect.reload());
});
gulp.task("watch", function() {
let json_content = fs.readFileSync(`${__dirname}/${filename}`, "UTF-8");
let yaml_content = yaml.load(json_content);
let dirs = yaml_content.content.sources.map(source => [
`${source.url}/**/**.yml`,
`${source.url}/**/**.adoc`,
`${source.url}/**/**.hbs`
]);
dirs.push(["dev-site.yml"]);
gulp.watch(dirs, ["preview"]);
});
gulp.task("connect", function() {
connect.server({
port: 5353,
name: "Dev Server",
livereload: true,
root: "gh-pages"
});
});
gulp.task("default", ["connect", "watch", "build"]);