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

Commit ea984c3

Browse files
committed
better handling of deleted files and folders
1 parent 070f66c commit ea984c3

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

core/lib/PatternLab/Builder.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ protected function generateMainPages() {
214214
$styleGuideHead = $this->mv->render($this->mainPageHead,$sd);
215215
$styleGuideFoot = $this->mv->render($this->mainPageFoot,$sd);
216216
$styleGuidePage = $styleGuideHead.$this->mfs->render('viewall',$sd).$styleGuideFoot;
217-
file_put_contents($this->pd."/styleguide/html/styleguide.html",$styleGuidePage);
217+
218+
if (!file_exists($this->pd."/styleguide/html/styleguide.html")) {
219+
print "ERROR: the main style guide wasn't written out. make sure public/styleguide exists. can copy core/styleguide\n";
220+
} else {
221+
file_put_contents($this->pd."/styleguide/html/styleguide.html",$styleGuidePage);
222+
}
218223

219224
}
220225

@@ -223,6 +228,11 @@ protected function generateMainPages() {
223228
*/
224229
protected function generatePatterns() {
225230

231+
// make sure patterns exists
232+
if (!is_dir($this->pd."/patterns")) {
233+
mkdir($this->pd."/patterns");
234+
}
235+
226236
// make sure the pattern header & footer are added
227237
$this->addPatternHF = true;
228238

@@ -1172,21 +1182,25 @@ protected function updateChangeTime() {
11721182
*/
11731183
protected function cleanPublic() {
11741184

1175-
// find all of the patterns in public/. sort by the children first
1176-
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->pd."/patterns/"), \RecursiveIteratorIterator::CHILD_FIRST);
1177-
1178-
// make sure dots are skipped
1179-
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
1180-
1181-
// for each file figure out what to do with it
1182-
foreach($objects as $name => $object) {
1185+
// make sure patterns exists before trying to clean it
1186+
if (is_dir($this->pd."/patterns")) {
1187+
1188+
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->pd."/patterns/"), \RecursiveIteratorIterator::CHILD_FIRST);
1189+
1190+
// make sure dots are skipped
1191+
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
11831192

1184-
if ($object->isDir()) {
1185-
// if this is a directory remove it
1186-
rmdir($name);
1187-
} else if ($object->isFile() && ($object->getFilename() != "README")) {
1188-
// if this is a file remove it
1189-
unlink($name);
1193+
// for each file figure out what to do with it
1194+
foreach($objects as $name => $object) {
1195+
1196+
if ($object->isDir()) {
1197+
// if this is a directory remove it
1198+
rmdir($name);
1199+
} else if ($object->isFile() && ($object->getFilename() != "README")) {
1200+
// if this is a file remove it
1201+
unlink($name);
1202+
}
1203+
11901204
}
11911205

11921206
}

core/lib/PatternLab/Generator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public function generate($enableCSS = false, $moveStatic = true, $noCacheBuster
7171
// render out the index and style guide
7272
$this->generateMainPages();
7373

74+
// make sure data exists
75+
if (!is_dir($this->pd."/data")) {
76+
mkdir($this->pd."/data");
77+
}
78+
7479
// iterate over the data files and regenerate the entire site if they've changed
7580
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd."/_data/"), \RecursiveIteratorIterator::SELF_FIRST);
7681

core/lib/PatternLab/Migrator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function migrate($diffVersion = false) {
5959

6060
if (!is_dir($destinationPath)) {
6161
mkdir($destinationPath);
62-
$this->runMigration($filename, $sourcePath, $destinationPath, false);
6362
}
6463

6564
} else if ($checkType == "fileExists") {
@@ -70,6 +69,11 @@ public function migrate($diffVersion = false) {
7069

7170
} else if (($checkType == "versionDiffDir") && $diffVersion) {
7271

72+
// make sure the destination path exists
73+
if (!is_dir($destinationPath)) {
74+
mkdir($destinationPath);
75+
}
76+
7377
$this->runMigration($filename, $sourcePath, $destinationPath, false);
7478

7579
} else if (($checkType == "versionDiffFile") && $diffVersion) {

0 commit comments

Comments
 (0)