@@ -727,6 +727,78 @@ protected function updateChangeTime() {
727
727
728
728
}
729
729
730
+ /**
731
+ * Delete patterns and user-created directories and files in public/
732
+ */
733
+ protected function cleanPublic () {
734
+
735
+ // find all of the patterns in public/. sort by the children first
736
+ $ objects = new RecursiveIteratorIterator (new RecursiveDirectoryIterator (__DIR__ ."/../../public/patterns/ " ), RecursiveIteratorIterator::CHILD_FIRST );
737
+
738
+ // make sure dots are skipped
739
+ $ objects ->setFlags (FilesystemIterator::SKIP_DOTS );
740
+
741
+ // for each file figure out what to do with it
742
+ foreach ($ objects as $ name => $ object ) {
743
+
744
+ if ($ object ->isDir ()) {
745
+ // if this is a directory remove it
746
+ rmdir ($ name );
747
+ } else if ($ object ->isFile () && ($ object ->getFilename () != "README " )) {
748
+ // if this is a file remove it
749
+ unlink ($ name );
750
+ }
751
+
752
+ }
753
+
754
+ // scan source/ & public/ to figure out what directories might need to be cleaned up
755
+ $ sourceDirs = glob (__DIR__ ."/../../source/* " ,GLOB_ONLYDIR );
756
+ $ publicDirs = glob (__DIR__ ."/../../public/* " ,GLOB_ONLYDIR );
757
+
758
+ // make sure some directories aren't deleted
759
+ $ ignoreDirs = array ("listeners " ,"styleguide " );
760
+ foreach ($ ignoreDirs as $ ignoreDir ) {
761
+ $ key = array_search (__DIR__ ."/../../public/ " .$ ignoreDir ,$ publicDirs );
762
+ if ($ key !== false ){
763
+ unset($ publicDirs [$ key ]);
764
+ }
765
+ }
766
+
767
+ // compare source dirs against public. remove those dirs w/ an underscore in source/ from the public/ list
768
+ foreach ($ sourceDirs as $ sourceDir ) {
769
+ $ cleanDir = str_replace (__DIR__ ."/../../source/ " ,"" ,$ sourceDir );
770
+ if ($ cleanDir [0 ] == "_ " ) {
771
+ $ key = array_search (__DIR__ ."/../../public/ " .str_replace ("_ " ,"" ,$ cleanDir ),$ publicDirs );
772
+ if ($ key !== false ){
773
+ unset($ publicDirs [$ key ]);
774
+ }
775
+ }
776
+ }
777
+
778
+ // for the remaining dirs in public delete them and their files
779
+ foreach ($ publicDirs as $ dir ) {
780
+
781
+ $ objects = new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($ dir ), RecursiveIteratorIterator::CHILD_FIRST );
782
+
783
+ // make sure dots are skipped
784
+ $ objects ->setFlags (FilesystemIterator::SKIP_DOTS );
785
+
786
+ foreach ($ objects as $ name => $ object ) {
787
+
788
+ if ($ object ->isDir ()) {
789
+ rmdir ($ name );
790
+ } else if ($ object ->isFile ()) {
791
+ unlink ($ name );
792
+ }
793
+
794
+ }
795
+
796
+ rmdir ($ dir );
797
+
798
+ }
799
+
800
+ }
801
+
730
802
/**
731
803
* Copies a file from the given source path to the given public path.
732
804
* THIS IS NOT FOR PATTERNS
0 commit comments