Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit b0ae375

Browse files
committed
reflecting the changes to builder
1 parent 88eba30 commit b0ae375

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

core/lib/PatternLab/Watcher.php

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*!
4-
* Pattern Lab Watcher Class - v0.7.12
4+
* Watcher Class
55
*
66
* Copyright (c) 2013-2014 Dave Olsen, http://dmolsen.com
77
* Licensed under the MIT license
@@ -16,6 +16,13 @@
1616

1717
namespace PatternLab;
1818

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+
1926
class Watcher extends Builder {
2027

2128
/**
@@ -42,7 +49,9 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
4249
print "starting page auto-reload...\n";
4350
}
4451

45-
$this->noCacheBuster = $noCacheBuster;
52+
if ($noCacheBuster) {
53+
Config::$options["cacheBuster"] = 0;
54+
}
4655

4756
$c = false; // track that one loop through the pattern file listing has completed
4857
$o = new \stdClass(); // create an object to hold the properties
@@ -59,15 +68,15 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
5968
$cp = clone $o->patterns;
6069

6170
// 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);
6372

6473
// make sure dots are skipped
6574
$patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
6675

6776
foreach($patternObjects as $name => $object) {
6877

6978
// 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);
7180
$fileNameClean = str_replace(DIRECTORY_SEPARATOR."_",DIRECTORY_SEPARATOR,$fileName);
7281

7382
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
133142
}
134143

135144
// 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);
137146

138147
// make sure dots are skipped
139148
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
140149

141150
foreach($objects as $name => $object) {
142151

143-
$fileName = str_replace($this->sd."/_data".DIRECTORY_SEPARATOR,"",$name);
152+
$fileName = str_replace(Config::$options["sourceDir"]."/_data".DIRECTORY_SEPARATOR,"",$name);
144153
$mt = $object->getMTime();
145154

146155
if (!isset($o->$fileName)) {
147156
$o->$fileName = $mt;
148157
if (($fileName[0] != "_") && $object->isFile()) {
149-
$this->moveStaticFile("_data/".$fileName,"","_data","data");
158+
FileUtil::moveStaticFile("_data/".$fileName,"","_data","data");
150159
}
151160
} else if ($o->$fileName != $mt) {
152161
$o->$fileName = $mt;
153162
$this->updateSite($fileName,"changed");
154163
if (($fileName[0] != "_") && $object->isFile()) {
155-
$this->moveStaticFile("_data/".$fileName,"","_data","data");
164+
FileUtil::moveStaticFile("_data/".$fileName,"","_data","data");
156165
}
157166
}
158167

@@ -161,23 +170,23 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
161170
// iterate over all of the other files in the source directory and move them if their modified time has changed
162171
if ($moveStatic) {
163172

164-
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
173+
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(Config::$options["sourceDir"]."/"), \RecursiveIteratorIterator::SELF_FIRST);
165174

166175
// make sure dots are skipped
167176
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
168177

169178
foreach($objects as $name => $object) {
170179

171180
// 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);
173182
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
174183

175184
// catch directories that have the ignored dir in their path
176185
$ignoreDir = $this->ignoreDir($fileName);
177186

178187
// 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);
181190
$o->$fileName = "dir created"; // placeholder
182191
print $fileName."/ directory was created...\n";
183192
}
@@ -186,15 +195,15 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
186195
if (file_exists($name)) {
187196

188197
$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)) {
190199
$o->$fileName = $mt;
191-
$this->moveStaticFile($fileName,"added");
200+
FileUtil::moveStaticFile($fileName,"added");
192201
if ($object->getExtension() == "css") {
193202
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
194203
}
195204
} else if (!$ignoreDir && $object->isFile() && isset($o->$fileName) && ($o->$fileName != $mt)) {
196205
$o->$fileName = $mt;
197-
$this->moveStaticFile($fileName,"changed");
206+
FileUtil::moveStaticFile($fileName,"changed");
198207
if ($object->getExtension() == "css") {
199208
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
200209
}
@@ -245,12 +254,17 @@ public function watch($reload = false, $moveStatic = true, $noCacheBuster = fals
245254
* @return {String} the final message
246255
*/
247256
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();
251263
$this->generateViewAllPages();
252-
$this->updateChangeTime();
253-
$this->generateMainPages();
264+
$this->generatePatterns();
265+
266+
Util::updateChangeTime();
267+
254268
if ($verbose) {
255269
if ($message == "added") {
256270
print $fileName." was added to Pattern Lab. Reload the website to see this change in the navigation...\n";

0 commit comments

Comments
 (0)