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

Commit fc9c47e

Browse files
committed
Merge branch 'feature-patternonlygenerate' into dev
2 parents 3712052 + f92d779 commit fc9c47e

File tree

3 files changed

+103
-70
lines changed

3 files changed

+103
-70
lines changed

core/builder.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@
1515
* php builder/builder.php -gc
1616
* In addition to the -g flag features it will also generate CSS for each pattern. Resource instensive.
1717
*
18+
* php builder.php -gp
19+
* Generates only the patterns a site. Does NOT clean public/ when generating the site.
20+
*
1821
* php builder.php -w
1922
* Generates the site like the -g flag and then watches for changes in the 'source' directories &
2023
* files. Will re-generate files if they've changed.
2124
*
2225
* php builder.php -wr
2326
* In addition to the -w flag features it will also automatically start the auto-reload server.
24-
*
27+
*
28+
* php builder.php -wp
29+
* Similar to the -w flag but it only generates and then watches the patterns. Does NOT clean public/ when generating the site.
30+
*
2531
* php builder.php -v
2632
* Prints out the current version of Pattern Lab.
2733
*
@@ -50,7 +56,7 @@
5056
}
5157

5258
// grab the arguments from the command line
53-
$args = getopt("gwcrv");
59+
$args = getopt("gwcrvp");
5460

5561
// load Pattern Lab's config, if first time set-up move files appropriately too
5662
$co = new PatternLab\Configurer;
@@ -66,14 +72,22 @@
6672
if (isset($args["g"]) || isset($args["w"])) {
6773

6874
$g = new PatternLab\Generator($config);
69-
$c = false;
75+
76+
// set some default values
77+
$enableCSS = false;
78+
$moveStatic = true;
7079

7180
// check to see if CSS for patterns should be parsed & outputted
7281
if (isset($args["c"]) && !isset($args["w"])) {
73-
$c = true;
82+
$enableCSS = true;
83+
}
84+
85+
// check to see if we should just generate the patterns
86+
if (isset($args["p"])) {
87+
$moveStatic = false;
7488
}
7589

76-
$g->generate($c);
90+
$g->generate($enableCSS,$moveStatic);
7791

7892
// have some fun
7993
if (!isset($args["w"])) {
@@ -86,13 +100,15 @@
86100
if (isset($args["w"])) {
87101

88102
$w = new PatternLab\Watcher($config);
89-
$a = false;
103+
104+
// set some default values
105+
$reload = false;
90106

91107
if (isset($args["r"])) {
92-
$a = true;
108+
$reload = true;
93109
}
94110

95-
$w->watch($a);
111+
$w->watch($reload,$moveStatic);
96112

97113
}
98114

@@ -105,12 +121,16 @@
105121
print " Iterates over the 'source' directories & files and generates the entire site a single time.\n";
106122
print " It also cleans the 'public' directory.\n\n";
107123
print " php ".$_SERVER["PHP_SELF"]." -gc\n";
108-
print " In addition to the -g flag features it will also generate CSS for each pattern. Resource instensive.\n\n";
124+
print " In addition to the -g flag features it will also generate CSS for each pattern. Resource intensive.\n\n";
125+
print " php ".$_SERVER["PHP_SELF"]." -gp\n";
126+
print " Generates only the patterns a site. Does NOT clean public/ when generating the site.\n\n";
109127
print " php ".$_SERVER["PHP_SELF"]." -w\n";
110128
print " Generates the site like the -g flag and then watches for changes in the 'source' directories &\n";
111129
print " files. Will re-generate files if they've changed.\n\n";
112130
print " php ".$_SERVER["PHP_SELF"]." -wr\n";
113131
print " In addition to the -w flag features it will also automatically start the auto-reload server.\n\n";
132+
print " php ".$_SERVER["PHP_SELF"]." -wp\n";
133+
print " Similar to the -w flag but it only generates and then watches the patterns. Does NOT clean public/ when generating the site.\n\n";
114134
print " php ".$_SERVER["PHP_SELF"]." -v\n";
115135
print " Prints out the current version of Pattern Lab.\n\n";
116136

core/lib/PatternLab/Generator.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public function __construct($config = array()) {
2828
/**
2929
* Pulls together a bunch of functions from builder.lib.php in an order that makes sense
3030
* @param {Boolean} decide if CSS should be parsed and saved. performance hog.
31+
* @param {Boolean} decide if static files like CSS and JS should be moved
3132
*/
32-
public function generate($enableCSS = false) {
33+
public function generate($enableCSS = false, $moveStatic = true) {
3334

3435
$timePL = true; // track how long it takes to generate a PL site
3536

@@ -58,7 +59,7 @@ public function generate($enableCSS = false) {
5859
$this->gatherPatternInfo();
5960

6061
// clean the public directory to remove old files
61-
if ($this->cleanPublic == "true") {
62+
if (($this->cleanPublic == "true") && $moveStatic) {
6263
$this->cleanPublic();
6364
}
6465

@@ -83,29 +84,34 @@ public function generate($enableCSS = false) {
8384

8485
}
8586

86-
// iterate over all of the other files in the source directory
87-
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
88-
89-
// make sure dots are skipped
90-
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
91-
92-
foreach($objects as $name => $object) {
87+
// move all of the files unless pattern only is set
88+
if ($moveStatic) {
9389

94-
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
95-
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
96-
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
97-
98-
// catch directories that have the ignored dir in their path
99-
$ignoreDir = $this->ignoreDir($fileName);
100-
101-
// check to see if it's a new directory
102-
if (!$ignoreDir && $object->isDir() && !is_dir($this->pd."/".$fileName)) {
103-
mkdir($this->pd."/".$fileName);
104-
}
90+
// iterate over all of the other files in the source directory
91+
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
92+
93+
// make sure dots are skipped
94+
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
95+
96+
foreach($objects as $name => $object) {
10597

106-
// check to see if it's a new file or a file that has changed
107-
if (!$ignoreDir && $object->isFile() && (!file_exists($this->pd."/".$fileName))) {
108-
$this->moveStaticFile($fileName);
98+
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
99+
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
100+
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
101+
102+
// catch directories that have the ignored dir in their path
103+
$ignoreDir = $this->ignoreDir($fileName);
104+
105+
// check to see if it's a new directory
106+
if (!$ignoreDir && $object->isDir() && !is_dir($this->pd."/".$fileName)) {
107+
mkdir($this->pd."/".$fileName);
108+
}
109+
110+
// check to see if it's a new file or a file that has changed
111+
if (!$ignoreDir && $object->isFile() && (!file_exists($this->pd."/".$fileName))) {
112+
$this->moveStaticFile($fileName);
113+
}
114+
109115
}
110116

111117
}

core/lib/PatternLab/Watcher.php

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public function __construct($config = array()) {
3030

3131
/**
3232
* Watch the source/ directory for any changes to existing files. Will run forever if given the chance.
33+
* @param {Boolean} decide if the reload server should be turned on
34+
* @param {Boolean} decide if static files like CSS and JS should be moved
3335
*/
34-
public function watch($reload = false) {
36+
public function watch($reload = false, $moveStatic = true) {
3537

3638
// automatically start the auto-refresh tool
3739
if ($reload) {
@@ -155,55 +157,60 @@ public function watch($reload = false) {
155157
}
156158

157159
// iterate over all of the other files in the source directory and move them if their modified time has changed
158-
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
159-
160-
// make sure dots are skipped
161-
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
162-
163-
foreach($objects as $name => $object) {
160+
if ($moveStatic) {
164161

165-
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
166-
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
167-
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
168-
169-
// catch directories that have the ignored dir in their path
170-
$ignoreDir = $this->ignoreDir($fileName);
171-
172-
// check to see if it's a new directory
173-
if (!$ignoreDir && $object->isDir() && !isset($o->$fileName) && !is_dir($this->pd."/".$fileName)) {
174-
mkdir($this->pd."/".$fileName);
175-
$o->$fileName = "dir created"; // placeholder
176-
print $fileName."/ directory was created...\n";
177-
}
162+
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
163+
164+
// make sure dots are skipped
165+
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
166+
167+
foreach($objects as $name => $object) {
178168

179-
// check to see if it's a new file or a file that has changed
180-
if (file_exists($name)) {
169+
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
170+
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
171+
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
181172

182-
$mt = $object->getMTime();
183-
if (!$ignoreDir && $object->isFile() && !isset($o->$fileName) && !file_exists($this->pd."/".$fileName)) {
184-
$o->$fileName = $mt;
185-
$this->moveStaticFile($fileName,"added");
186-
if ($object->getExtension() == "css") {
187-
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
188-
}
189-
} else if (!$ignoreDir && $object->isFile() && isset($o->$fileName) && ($o->$fileName != $mt)) {
190-
$o->$fileName = $mt;
191-
$this->moveStaticFile($fileName,"changed");
192-
if ($object->getExtension() == "css") {
193-
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
173+
// catch directories that have the ignored dir in their path
174+
$ignoreDir = $this->ignoreDir($fileName);
175+
176+
// check to see if it's a new directory
177+
if (!$ignoreDir && $object->isDir() && !isset($o->$fileName) && !is_dir($this->pd."/".$fileName)) {
178+
mkdir($this->pd."/".$fileName);
179+
$o->$fileName = "dir created"; // placeholder
180+
print $fileName."/ directory was created...\n";
181+
}
182+
183+
// check to see if it's a new file or a file that has changed
184+
if (file_exists($name)) {
185+
186+
$mt = $object->getMTime();
187+
if (!$ignoreDir && $object->isFile() && !isset($o->$fileName) && !file_exists($this->pd."/".$fileName)) {
188+
$o->$fileName = $mt;
189+
$this->moveStaticFile($fileName,"added");
190+
if ($object->getExtension() == "css") {
191+
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
192+
}
193+
} else if (!$ignoreDir && $object->isFile() && isset($o->$fileName) && ($o->$fileName != $mt)) {
194+
$o->$fileName = $mt;
195+
$this->moveStaticFile($fileName,"changed");
196+
if ($object->getExtension() == "css") {
197+
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
198+
}
199+
} else if (!isset($o->fileName)) {
200+
$o->$fileName = $mt;
194201
}
195-
} else if (!isset($o->fileName)) {
196-
$o->$fileName = $mt;
202+
203+
} else {
204+
unset($o->$fileName);
197205
}
198206

199-
} else {
200-
unset($o->$fileName);
201207
}
202208

203209
}
204210

205211
}
206212

213+
207214
$c = true;
208215

209216
// taking out the garbage. basically killing mustache after each run.

0 commit comments

Comments
 (0)