Skip to content

Commit eec2713

Browse files
committed
gulpfile.js: working with gulp 4.0, auto-opens browser
1 parent 2459547 commit eec2713

1 file changed

Lines changed: 22 additions & 29 deletions

File tree

gulpfile.js

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ const connect = require("gulp-connect");
44
const fs = require("fs");
55
const generator = require("@antora/site-generator-default");
66
const gulp = require("gulp");
7+
const open = require("gulp-open");
78
const yaml = require("yaml-js");
89

910
let filename = "dev-site.yml";
1011
let args = ["--playbook", filename];
1112

12-
gulp.task("build", function(cb) {
13+
function build(cb) {
1314
/**
1415
* Use the '@antora/site-generator-default' node module to build.
1516
* It's analogous to `$ antora --playbook local-antora-playbook.yml`.
@@ -19,44 +20,36 @@ gulp.task("build", function(cb) {
1920
* a separate process for each run. So if a build error occurs with the `gulp`
2021
* command it can be useful to check if it also happens with the CLI command.
2122
*/
22-
generator(args, process.env)
23-
.then(() => {
24-
cb();
25-
})
26-
.catch(err => {
27-
console.log(err);
28-
cb();
29-
});
30-
});
23+
generator(args, process.env).catch(err => { console.log(err); })
24+
connect.reload()
25+
cb();
26+
}
3127

32-
gulp.task("preview", ["build"], function() {
33-
/**
34-
* Remove the line gulp.src('README.adoc')
35-
* This is placeholder code to follow the gulp-connect
36-
* example. Could not make it work any other way.
37-
*/
38-
gulp.src("README.adoc").pipe(connect.reload());
39-
});
40-
41-
gulp.task("watch", function() {
28+
function watch() {
4229
let json_content = fs.readFileSync(`${__dirname}/${filename}`, "UTF-8");
4330
let yaml_content = yaml.load(json_content);
44-
let dirs = yaml_content.content.sources.map(source => [
45-
`${source.url}/**/**.yml`,
46-
`${source.url}/**/**.adoc`,
31+
let sources = yaml_content.content.sources.map(source => [
32+
`${source.url}/**/*.yml`,
33+
`${source.url}/**/*.adoc`,
4734
`${source.url}/**/**.hbs`
4835
]);
49-
dirs.push(["dev-site.yml"]);
50-
gulp.watch(dirs, ["preview"]);
51-
});
36+
sources.push(["dev-site.yml"]);
37+
sources = [].concat.apply([], sources) // Flatten the array
38+
gulp.watch(sources, build)
39+
}
5240

53-
gulp.task("connect", function() {
41+
function serve() {
5442
connect.server({
5543
port: 5353,
5644
name: "Dev Server",
5745
livereload: true,
5846
root: "gh-pages"
5947
});
60-
});
48+
}
49+
50+
function browse() {
51+
gulp.src("gh-pages/index.html").pipe(open({uri: 'http://localhost:5353'}))
52+
}
6153

62-
gulp.task("default", ["connect", "watch", "build"]);
54+
exports.build = build;
55+
exports.default = gulp.parallel(serve, watch, browse)

0 commit comments

Comments
 (0)