1
0
mirror of https://github.com/pattern-lab/patternlab-php.git synced 2025-01-17 14:18:30 +01:00

Merge branch 'feature-patternonlygenerate' into dev

This commit is contained in:
Dave Olsen 2014-03-06 09:37:34 -05:00
commit fc9c47e74b
3 changed files with 104 additions and 71 deletions

View File

@ -15,13 +15,19 @@
* php builder/builder.php -gc
* In addition to the -g flag features it will also generate CSS for each pattern. Resource instensive.
*
* php builder.php -gp
* Generates only the patterns a site. Does NOT clean public/ when generating the site.
*
* php builder.php -w
* Generates the site like the -g flag and then watches for changes in the 'source' directories &
* files. Will re-generate files if they've changed.
*
* php builder.php -wr
* In addition to the -w flag features it will also automatically start the auto-reload server.
*
*
* php builder.php -wp
* Similar to the -w flag but it only generates and then watches the patterns. Does NOT clean public/ when generating the site.
*
* php builder.php -v
* Prints out the current version of Pattern Lab.
*
@ -50,7 +56,7 @@ if (php_sapi_name() != 'cli') {
}
// grab the arguments from the command line
$args = getopt("gwcrv");
$args = getopt("gwcrvp");
// load Pattern Lab's config, if first time set-up move files appropriately too
$co = new PatternLab\Configurer;
@ -66,14 +72,22 @@ if (isset($args["v"])) {
if (isset($args["g"]) || isset($args["w"])) {
$g = new PatternLab\Generator($config);
$c = false;
// set some default values
$enableCSS = false;
$moveStatic = true;
// check to see if CSS for patterns should be parsed & outputted
if (isset($args["c"]) && !isset($args["w"])) {
$c = true;
$enableCSS = true;
}
$g->generate($c);
// check to see if we should just generate the patterns
if (isset($args["p"])) {
$moveStatic = false;
}
$g->generate($enableCSS,$moveStatic);
// have some fun
if (!isset($args["w"])) {
@ -86,13 +100,15 @@ if (isset($args["g"]) || isset($args["w"])) {
if (isset($args["w"])) {
$w = new PatternLab\Watcher($config);
$a = false;
// set some default values
$reload = false;
if (isset($args["r"])) {
$a = true;
$reload = true;
}
$w->watch($a);
$w->watch($reload,$moveStatic);
}
@ -105,12 +121,16 @@ if (!isset($args["g"]) && !isset($args["w"]) && !isset($args["v"])) {
print " Iterates over the 'source' directories & files and generates the entire site a single time.\n";
print " It also cleans the 'public' directory.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -gc\n";
print " In addition to the -g flag features it will also generate CSS for each pattern. Resource instensive.\n\n";
print " In addition to the -g flag features it will also generate CSS for each pattern. Resource intensive.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -gp\n";
print " Generates only the patterns a site. Does NOT clean public/ when generating the site.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -w\n";
print " Generates the site like the -g flag and then watches for changes in the 'source' directories &\n";
print " files. Will re-generate files if they've changed.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -wr\n";
print " In addition to the -w flag features it will also automatically start the auto-reload server.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -wp\n";
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";
print " php ".$_SERVER["PHP_SELF"]." -v\n";
print " Prints out the current version of Pattern Lab.\n\n";

View File

@ -28,8 +28,9 @@ class Generator extends Builder {
/**
* Pulls together a bunch of functions from builder.lib.php in an order that makes sense
* @param {Boolean} decide if CSS should be parsed and saved. performance hog.
* @param {Boolean} decide if static files like CSS and JS should be moved
*/
public function generate($enableCSS = false) {
public function generate($enableCSS = false, $moveStatic = true) {
$timePL = true; // track how long it takes to generate a PL site
@ -58,7 +59,7 @@ class Generator extends Builder {
$this->gatherPatternInfo();
// clean the public directory to remove old files
if ($this->cleanPublic == "true") {
if (($this->cleanPublic == "true") && $moveStatic) {
$this->cleanPublic();
}
@ -83,29 +84,34 @@ class Generator extends Builder {
}
// iterate over all of the other files in the source directory
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
// make sure dots are skipped
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
foreach($objects as $name => $object) {
// move all of the files unless pattern only is set
if ($moveStatic) {
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
// iterate over all of the other files in the source directory
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
// make sure dots are skipped
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
foreach($objects as $name => $object) {
// catch directories that have the ignored dir in their path
$ignoreDir = $this->ignoreDir($fileName);
// check to see if it's a new directory
if (!$ignoreDir && $object->isDir() && !is_dir($this->pd."/".$fileName)) {
mkdir($this->pd."/".$fileName);
}
// check to see if it's a new file or a file that has changed
if (!$ignoreDir && $object->isFile() && (!file_exists($this->pd."/".$fileName))) {
$this->moveStaticFile($fileName);
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
// catch directories that have the ignored dir in their path
$ignoreDir = $this->ignoreDir($fileName);
// check to see if it's a new directory
if (!$ignoreDir && $object->isDir() && !is_dir($this->pd."/".$fileName)) {
mkdir($this->pd."/".$fileName);
}
// check to see if it's a new file or a file that has changed
if (!$ignoreDir && $object->isFile() && (!file_exists($this->pd."/".$fileName))) {
$this->moveStaticFile($fileName);
}
}
}

View File

@ -30,8 +30,10 @@ class Watcher extends Builder {
/**
* Watch the source/ directory for any changes to existing files. Will run forever if given the chance.
* @param {Boolean} decide if the reload server should be turned on
* @param {Boolean} decide if static files like CSS and JS should be moved
*/
public function watch($reload = false) {
public function watch($reload = false, $moveStatic = true) {
// automatically start the auto-refresh tool
if ($reload) {
@ -155,55 +157,60 @@ class Watcher extends Builder {
}
// iterate over all of the other files in the source directory and move them if their modified time has changed
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
// make sure dots are skipped
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
foreach($objects as $name => $object) {
if ($moveStatic) {
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/"), \RecursiveIteratorIterator::SELF_FIRST);
// make sure dots are skipped
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
foreach($objects as $name => $object) {
// catch directories that have the ignored dir in their path
$ignoreDir = $this->ignoreDir($fileName);
// check to see if it's a new directory
if (!$ignoreDir && $object->isDir() && !isset($o->$fileName) && !is_dir($this->pd."/".$fileName)) {
mkdir($this->pd."/".$fileName);
$o->$fileName = "dir created"; // placeholder
print $fileName."/ directory was created...\n";
}
// check to see if it's a new file or a file that has changed
if (file_exists($name)) {
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
$fileName = str_replace($this->sd.DIRECTORY_SEPARATOR,"",$name);
if (($fileName[0] != "_") && (!in_array($object->getExtension(),$this->ie)) && (!in_array($object->getFilename(),$this->id))) {
$mt = $object->getMTime();
if (!$ignoreDir && $object->isFile() && !isset($o->$fileName) && !file_exists($this->pd."/".$fileName)) {
$o->$fileName = $mt;
$this->moveStaticFile($fileName,"added");
if ($object->getExtension() == "css") {
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
}
} else if (!$ignoreDir && $object->isFile() && isset($o->$fileName) && ($o->$fileName != $mt)) {
$o->$fileName = $mt;
$this->moveStaticFile($fileName,"changed");
if ($object->getExtension() == "css") {
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
}
} else if (!isset($o->fileName)) {
$o->$fileName = $mt;
// catch directories that have the ignored dir in their path
$ignoreDir = $this->ignoreDir($fileName);
// check to see if it's a new directory
if (!$ignoreDir && $object->isDir() && !isset($o->$fileName) && !is_dir($this->pd."/".$fileName)) {
mkdir($this->pd."/".$fileName);
$o->$fileName = "dir created"; // placeholder
print $fileName."/ directory was created...\n";
}
// check to see if it's a new file or a file that has changed
if (file_exists($name)) {
$mt = $object->getMTime();
if (!$ignoreDir && $object->isFile() && !isset($o->$fileName) && !file_exists($this->pd."/".$fileName)) {
$o->$fileName = $mt;
$this->moveStaticFile($fileName,"added");
if ($object->getExtension() == "css") {
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
}
} else if (!$ignoreDir && $object->isFile() && isset($o->$fileName) && ($o->$fileName != $mt)) {
$o->$fileName = $mt;
$this->moveStaticFile($fileName,"changed");
if ($object->getExtension() == "css") {
$this->updateSite($fileName,"changed",0); // make sure the site is updated for MQ reasons
}
} else if (!isset($o->fileName)) {
$o->$fileName = $mt;
}
} else {
unset($o->$fileName);
}
} else {
unset($o->$fileName);
}
}
}
$c = true;
// taking out the garbage. basically killing mustache after each run.