1
1
var gulp = require ( 'gulp' ) ;
2
2
var watch = require ( 'gulp-watch' ) ;
3
3
var gutil = require ( 'gulp-util' ) ;
4
- var Dgeni = require ( 'dgeni' ) ;
5
4
var path = require ( 'path' ) ;
6
5
var del = require ( 'del' ) ;
7
6
8
7
var docShredder = require ( './public/doc-shredder/doc-shredder' ) ;
9
8
10
- var shredOptions = {
9
+ var _shredOptions = {
11
10
basePath : path . resolve ( './public/docs' ) ,
12
11
sourceDir : "_examples" ,
13
12
destDir : "_fragments"
@@ -21,32 +20,49 @@ a ‘partial’ shredder. It only shred’s files in directories changed during
21
20
the current session.
22
21
*/
23
22
23
+ gulp . task ( 'serve-and-sync' , function ( cb ) {
24
+ execCommands ( [ 'harp server' ] , { } , cb ) ;
24
25
25
- gulp . task ( 'shred-full' , [ 'shred-clean' ] , function ( ) {
26
- docShredder . shred ( shredOptions ) ;
26
+ var browserSync = require ( 'browser-sync' ) . create ( ) ;
27
+ browserSync . init ( {
28
+ proxy : 'localhost:9000' ,
29
+ files : "public/docs/**/*/**/*" ,
30
+ logFileChanges : true ,
31
+ reloadDelay : 500
32
+ } ) ;
33
+
34
+ shredWatch ( _shredOptions , function ( ) {
35
+ browserSync . reload ( ) ;
36
+ } ) ;
27
37
} ) ;
28
38
29
39
gulp . task ( 'serve-and-watch' , function ( cb ) {
30
- var pattern = path . join ( shredOptions . basePath , shredOptions . sourceDir , "**/*.*" ) ;
31
-
32
- execCommands ( [ 'harp server' ] )
33
-
34
- watch ( [ pattern ] , function ( event , done ) {
35
- console . log ( 'Event type: ' + event . event ) ; // added, changed, or deleted
36
- console . log ( 'Event path: ' + event . path ) ; // The path of the modified file
37
- docShredder . shredSingleDir ( shredOptions , event . path ) ;
38
- } ) ;
40
+ execCommands ( [ 'harp server' ] , { } , cb ) ;
41
+ shredWatch ( _shredOptions ) ;
42
+ } ) ;
39
43
44
+ gulp . task ( 'shred-full' , [ 'shred-clean' ] , function ( ) {
45
+ docShredder . shred ( _shredOptions ) ;
40
46
} ) ;
41
47
42
48
gulp . task ( 'shred-clean' , function ( cb ) {
43
- var cleanPath = path . join ( shredOptions . basePath , shredOptions . destDir , '**/*.*' )
49
+ var cleanPath = path . join ( _shredOptions . basePath , _shredOptions . destDir , '**/*.*' )
44
50
del ( [ cleanPath , '!**/*.ovr.*' ] , function ( err , paths ) {
45
51
// console.log('Deleted files/folders:\n', paths.join('\n'));
46
52
cb ( ) ;
47
53
} ) ;
48
54
} ) ;
49
55
56
+ function shredWatch ( shredOptions , postShredAction ) {
57
+ var pattern = path . join ( shredOptions . basePath , shredOptions . sourceDir , "**/*.*" ) ;
58
+ watch ( [ pattern ] , function ( event , done ) {
59
+ console . log ( 'Event type: ' + event . event ) ; // added, changed, or deleted
60
+ console . log ( 'Event path: ' + event . path ) ; // The path of the modified file
61
+ docShredder . shredSingleDir ( shredOptions , event . path ) . then ( function ( ) {
62
+ postShredAction && postShredAction ( ) ;
63
+ } ) ;
64
+ } ) ;
65
+ }
50
66
51
67
// added options are: shouldLog
52
68
// cb is function(err, stdout, stderr);
0 commit comments