1
1
<?php
2
2
3
3
/*!
4
- * Pattern Lab Watcher Class - v0.7.12
4
+ * Watcher Class
5
5
*
6
6
* Copyright (c) 2013-2014 Dave Olsen, http://dmolsen.com
7
7
* Licensed under the MIT license
16
16
17
17
namespace PatternLab ;
18
18
19
+ use \PatternLab \Builder ;
20
+ use \PatternLab \Config ;
21
+ use \PatternLab \Data ;
22
+ use \PatternLab \FileUtil ;
23
+ use \PatternLab \PatternData ;
24
+ use \PatternLab \Util ;
25
+
19
26
class Watcher extends Builder {
20
27
21
28
/**
@@ -42,7 +49,9 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
42
49
print "starting page auto-reload... \n" ;
43
50
}
44
51
45
- $ this ->noCacheBuster = $ noCacheBuster ;
52
+ if ($ noCacheBuster ) {
53
+ Config::$ options ["cacheBuster " ] = 0 ;
54
+ }
46
55
47
56
$ c = false ; // track that one loop through the pattern file listing has completed
48
57
$ o = new \stdClass (); // create an object to hold the properties
@@ -59,15 +68,15 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
59
68
$ cp = clone $ o ->patterns ;
60
69
61
70
// iterate over the patterns & related data and regenerate the entire site if they've changed
62
- $ patternObjects = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this -> sd ."/_patterns/ " ), \RecursiveIteratorIterator::SELF_FIRST );
71
+ $ patternObjects = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator (Config:: $ options [ " sourceDir " ] ."/_patterns/ " ), \RecursiveIteratorIterator::SELF_FIRST );
63
72
64
73
// make sure dots are skipped
65
74
$ patternObjects ->setFlags (\FilesystemIterator::SKIP_DOTS );
66
75
67
76
foreach ($ patternObjects as $ name => $ object ) {
68
77
69
78
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
70
- $ fileName = str_replace ($ this -> sd ."/_patterns " .DIRECTORY_SEPARATOR ,"" ,$ name );
79
+ $ fileName = str_replace (Config:: $ options [ " sourceDir " ] ."/_patterns " .DIRECTORY_SEPARATOR ,"" ,$ name );
71
80
$ fileNameClean = str_replace (DIRECTORY_SEPARATOR ."_ " ,DIRECTORY_SEPARATOR ,$ fileName );
72
81
73
82
if ($ object ->isFile () && (($ object ->getExtension () == "mustache " ) || ($ object ->getExtension () == "json " ) || ($ object ->getExtension () == "md " ))) {
@@ -133,26 +142,26 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
133
142
}
134
143
135
144
// iterate over the data files and regenerate the entire site if they've changed
136
- $ objects = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this -> sd ."/_data/ " ), \RecursiveIteratorIterator::SELF_FIRST );
145
+ $ objects = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator (Config:: $ options [ " sourceDir " ] ."/_data/ " ), \RecursiveIteratorIterator::SELF_FIRST );
137
146
138
147
// make sure dots are skipped
139
148
$ objects ->setFlags (\FilesystemIterator::SKIP_DOTS );
140
149
141
150
foreach ($ objects as $ name => $ object ) {
142
151
143
- $ fileName = str_replace ($ this -> sd ."/_data " .DIRECTORY_SEPARATOR ,"" ,$ name );
152
+ $ fileName = str_replace (Config:: $ options [ " sourceDir " ] ."/_data " .DIRECTORY_SEPARATOR ,"" ,$ name );
144
153
$ mt = $ object ->getMTime ();
145
154
146
155
if (!isset ($ o ->$ fileName )) {
147
156
$ o ->$ fileName = $ mt ;
148
157
if (($ fileName [0 ] != "_ " ) && $ object ->isFile ()) {
149
- $ this -> moveStaticFile ("_data/ " .$ fileName ,"" ,"_data " ,"data " );
158
+ FileUtil:: moveStaticFile ("_data/ " .$ fileName ,"" ,"_data " ,"data " );
150
159
}
151
160
} else if ($ o ->$ fileName != $ mt ) {
152
161
$ o ->$ fileName = $ mt ;
153
162
$ this ->updateSite ($ fileName ,"changed " );
154
163
if (($ fileName [0 ] != "_ " ) && $ object ->isFile ()) {
155
- $ this -> moveStaticFile ("_data/ " .$ fileName ,"" ,"_data " ,"data " );
164
+ FileUtil:: moveStaticFile ("_data/ " .$ fileName ,"" ,"_data " ,"data " );
156
165
}
157
166
}
158
167
@@ -161,23 +170,23 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
161
170
// iterate over all of the other files in the source directory and move them if their modified time has changed
162
171
if ($ moveStatic ) {
163
172
164
- $ objects = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this -> sd ."/ " ), \RecursiveIteratorIterator::SELF_FIRST );
173
+ $ objects = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator (Config:: $ options [ " sourceDir " ] ."/ " ), \RecursiveIteratorIterator::SELF_FIRST );
165
174
166
175
// make sure dots are skipped
167
176
$ objects ->setFlags (\FilesystemIterator::SKIP_DOTS );
168
177
169
178
foreach ($ objects as $ name => $ object ) {
170
179
171
180
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
172
- $ fileName = str_replace ($ this -> sd .DIRECTORY_SEPARATOR ,"" ,$ name );
181
+ $ fileName = str_replace (Config:: $ options [ " sourceDir " ] .DIRECTORY_SEPARATOR ,"" ,$ name );
173
182
if (($ fileName [0 ] != "_ " ) && (!in_array ($ object ->getExtension (),$ this ->ie )) && (!in_array ($ object ->getFilename (),$ this ->id ))) {
174
183
175
184
// catch directories that have the ignored dir in their path
176
185
$ ignoreDir = $ this ->ignoreDir ($ fileName );
177
186
178
187
// check to see if it's a new directory
179
- if (!$ ignoreDir && $ object ->isDir () && !isset ($ o ->$ fileName ) && !is_dir ($ this -> pd ."/ " .$ fileName )) {
180
- mkdir ($ this -> pd ."/ " .$ fileName );
188
+ if (!$ ignoreDir && $ object ->isDir () && !isset ($ o ->$ fileName ) && !is_dir (Config:: $ options [ " patternPublicDir " ] ."/ " .$ fileName )) {
189
+ mkdir (Config:: $ options [ " patternPublicDir " ] ."/ " .$ fileName );
181
190
$ o ->$ fileName = "dir created " ; // placeholder
182
191
print $ fileName ."/ directory was created... \n" ;
183
192
}
@@ -186,15 +195,15 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
186
195
if (file_exists ($ name )) {
187
196
188
197
$ mt = $ object ->getMTime ();
189
- if (!$ ignoreDir && $ object ->isFile () && !isset ($ o ->$ fileName ) && !file_exists ($ this -> pd ."/ " .$ fileName )) {
198
+ if (!$ ignoreDir && $ object ->isFile () && !isset ($ o ->$ fileName ) && !file_exists (Config:: $ options [ " patternPublicDir " ] ."/ " .$ fileName )) {
190
199
$ o ->$ fileName = $ mt ;
191
- $ this -> moveStaticFile ($ fileName ,"added " );
200
+ FileUtil:: moveStaticFile ($ fileName ,"added " );
192
201
if ($ object ->getExtension () == "css " ) {
193
202
$ this ->updateSite ($ fileName ,"changed " ,0 ); // make sure the site is updated for MQ reasons
194
203
}
195
204
} else if (!$ ignoreDir && $ object ->isFile () && isset ($ o ->$ fileName ) && ($ o ->$ fileName != $ mt )) {
196
205
$ o ->$ fileName = $ mt ;
197
- $ this -> moveStaticFile ($ fileName ,"changed " );
206
+ FileUtil:: moveStaticFile ($ fileName ,"changed " );
198
207
if ($ object ->getExtension () == "css " ) {
199
208
$ this ->updateSite ($ fileName ,"changed " ,0 ); // make sure the site is updated for MQ reasons
200
209
}
@@ -245,12 +254,17 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
245
254
* @return {String} the final message
246
255
*/
247
256
private function updateSite ($ fileName ,$ message ,$ verbose = true ) {
248
- $ this ->gatherData ();
249
- $ this ->gatherPatternInfo ();
250
- $ this ->generatePatterns ();
257
+
258
+ Data::gather ();
259
+ PatternData::gather ();
260
+
261
+ $ this ->generateIndex ();
262
+ $ this ->generateStyleguide ();
251
263
$ this ->generateViewAllPages ();
252
- $ this ->updateChangeTime ();
253
- $ this ->generateMainPages ();
264
+ $ this ->generatePatterns ();
265
+
266
+ Util::updateChangeTime ();
267
+
254
268
if ($ verbose ) {
255
269
if ($ message == "added " ) {
256
270
print $ fileName ." was added to Pattern Lab. Reload the website to see this change in the navigation... \n" ;
0 commit comments