@@ -4,13 +4,12 @@ const connect = require("gulp-connect");
44const fs = require ( "fs" ) ;
55const generator = require ( "@antora/site-generator-default" ) ;
66const gulp = require ( "gulp" ) ;
7- const open = require ( "gulp-open" ) ;
87const yaml = require ( "yaml-js" ) ;
98
109let filename = "dev-site.yml" ;
1110let args = [ "--playbook" , filename ] ;
1211
13- function build ( cb ) {
12+ gulp . task ( " build" , function ( cb ) {
1413 /**
1514 * Use the '@antora/site-generator-default' node module to build.
1615 * It's analogous to `$ antora --playbook local-antora-playbook.yml`.
@@ -20,36 +19,44 @@ function build(cb) {
2019 * a separate process for each run. So if a build error occurs with the `gulp`
2120 * command it can be useful to check if it also happens with the CLI command.
2221 */
23- generator ( args , process . env ) . catch ( err => { console . log ( err ) ; } )
24- connect . reload ( )
25- cb ( ) ;
26- }
22+ generator ( args , process . env )
23+ . then ( ( ) => {
24+ cb ( ) ;
25+ } )
26+ . catch ( err => {
27+ console . log ( err ) ;
28+ cb ( ) ;
29+ } ) ;
30+ } ) ;
2731
28- function watch ( ) {
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 ( ) {
2942 let json_content = fs . readFileSync ( `${ __dirname } /${ filename } ` , "UTF-8" ) ;
3043 let yaml_content = yaml . load ( json_content ) ;
31- let sources = yaml_content . content . sources . map ( source => [
32- `${ source . url } /**/*.yml` ,
33- `${ source . url } /**/*.adoc` ,
44+ let dirs = yaml_content . content . sources . map ( source => [
45+ `${ source . url } /**/** .yml` ,
46+ `${ source . url } /**/** .adoc` ,
3447 `${ source . url } /**/**.hbs`
3548 ] ) ;
36- sources . push ( [ "dev-site.yml" ] ) ;
37- sources = [ ] . concat . apply ( [ ] , sources ) // Flatten the array
38- gulp . watch ( sources , build )
39- }
49+ dirs . push ( [ "dev-site.yml" ] ) ;
50+ gulp . watch ( dirs , [ "preview" ] ) ;
51+ } ) ;
4052
41- function serve ( ) {
53+ gulp . task ( "connect" , function ( ) {
4254 connect . server ( {
4355 port : 5353 ,
4456 name : "Dev Server" ,
4557 livereload : true ,
4658 root : "gh-pages"
4759 } ) ;
48- }
49-
50- function browse ( ) {
51- gulp . src ( "gh-pages/index.html" ) . pipe ( open ( { uri : 'http://localhost:5353' } ) )
52- }
60+ } ) ;
5361
54- exports . build = build ;
55- exports . default = gulp . parallel ( serve , watch , browse )
62+ gulp . task ( "default" , [ "connect" , "watch" , "build" ] ) ;
0 commit comments