@@ -104,8 +104,55 @@ const asset_copier = () => {
104
104
}
105
105
} ) ;
106
106
107
- //we need to special case patterns/**/*.md|.json|.pattern-extensions
107
+ //we need to special case patterns/**/*.md|.json|.pattern-extensions as well as the global structures
108
108
if ( options . watch ) {
109
+
110
+ // watch global structures, such as _data/* and _meta/
111
+ const globalSources = [ assetDirectories . source . data , assetDirectories . source . meta ]
112
+ const globalPaths = globalSources . map ( globalSource => path . join (
113
+ basePath ,
114
+ globalSource ,
115
+ '*'
116
+ ) ) ;
117
+
118
+ _ . each ( globalPaths , ( globalPath ) => {
119
+
120
+ if ( patternlab . config . debug ) {
121
+ console . log ( `Pattern Lab is watching ${ globalPath } for changes` ) ;
122
+ }
123
+
124
+ const globalWatcher = chokidar . watch (
125
+ path . resolve ( globalPath ) ,
126
+ {
127
+ ignored : / ( ^ | [ \/ \\ ] ) \. ./ ,
128
+ ignoreInitial : true ,
129
+ awaitWriteFinish : {
130
+ stabilityThreshold : 200 ,
131
+ pollInterval : 100
132
+ }
133
+ }
134
+ ) ;
135
+
136
+ //watch for changes and rebuild
137
+ globalWatcher . on ( 'addDir' , ( p ) => {
138
+ patternlab . events . emit ( 'patternlab-global-change' , {
139
+ file : p
140
+ } )
141
+ } )
142
+ . on ( 'add' , ( p ) => {
143
+ patternlab . events . emit ( 'patternlab-global-change' , {
144
+ file : p
145
+ } ) ;
146
+ } ) . on ( 'change' , ( p ) => {
147
+ console . log ( 145 , 'global change watch' )
148
+ patternlab . events . emit ( 'patternlab-global-change' , {
149
+ file : p
150
+ } ) ;
151
+ } ) ;
152
+
153
+ } ) ;
154
+
155
+ // watch patterns
109
156
const baseFileExtensions = [ '.json' , '.yml' , '.yaml' , '.md' ] ;
110
157
const patternWatches = baseFileExtensions . concat ( patternlab . engines . getSupportedFileExtensions ( ) ) . map (
111
158
dotExtension => path . join (
@@ -143,7 +190,7 @@ const asset_copier = () => {
143
190
} ) . on ( 'change' , ( p ) => {
144
191
patternlab . events . emit ( 'patternlab-pattern-change' , {
145
192
file : p
146
- } ) ;
193
+ } ) ;
147
194
} ) ;
148
195
} ) ;
149
196
}
0 commit comments