@@ -82,24 +82,23 @@ protected function generateIndex() {
82
82
* Handle missing index.html. Solves https://github.com/drupal-pattern-lab/patternlab-php-core/issues/14
83
83
* Could also be used to re-add missing styleguidekit assets with a few edits?
84
84
*
85
- * 1. @TODO: What would be a better way to find our base vendor directory from here?
86
- * 2. Locate the current theme's styleguidekit assets via the patternlab-styleguidekit `type` in composer.json
87
- * 3. @TODO: Figure out a better way to future-proof path resolution for styleguidekit `dist` folder
88
- * 4. Recusirively copy files from styleguidekit to publicDir via https://stackoverflow.com/a/7775949
89
- * 5. Make sure we only try to create new directories if they don't already exist
90
- * 6. Only copy files if they are missing (vs changed, etc)
85
+ * 1. @TODO: Figure out a better way to future-proof path resolution for styleguidekit `dist` folder
86
+ * 2. Recusirively copy files from styleguidekit to publicDir via https://stackoverflow.com/a/7775949
87
+ * 3. Make sure we only try to create new directories if they don't already exist
88
+ * 4. Only copy files if they are missing (vs changed, etc)
91
89
*/
92
90
if (!file_exists (Config::getOption ("publicDir " )."/index.html " )) {
93
91
$ index = Console::getHumanReadablePath (Config::getOption ("publicDir " )).DIRECTORY_SEPARATOR ."index.html " ;
94
- Console::writeWarning ($ index . " is missing. No biggie. Grabbing a copy from your StyleguideKit... " );
92
+ Console::writeWarning ($ index . " is missing. No biggie. Grabbing a fresh copy from your StyleguideKit... " );
95
93
94
+ $ baseDir = Config::getOption ("baseDir " ) . '/vendor ' ;
96
95
$ finder = new Finder ();
97
- $ base = __DIR__ . " /../../../ " ; /* [1] */
98
- $ kit_path = Config:: getOption ( " styleguideKitPath " );
99
- $ finder ->files ()->name ("composer.json " )->in ($ base )->contains ('patternlab-styleguidekit ' )->sortByName (); /* [2] */
96
+
97
+ // Locate the current theme's styleguidekit assets via the patternlab-styleguidekit `type` in composer.json
98
+ $ finder ->files ()->name ("composer.json " )->in ($ baseDir )->contains ('patternlab-styleguidekit ' )->sortByName ();
100
99
101
100
foreach ($ finder as $ file ) {
102
- $ src = dirname ($ file ->getRealPath ()) . DIRECTORY_SEPARATOR . 'dist ' ; /* [3 ] */
101
+ $ src = dirname ($ file ->getRealPath ()) . DIRECTORY_SEPARATOR . 'dist ' ; /* [1 ] */
103
102
$ dest = Config::getOption ("publicDir " );
104
103
105
104
if (is_dir ($ src )){
@@ -108,16 +107,16 @@ protected function generateIndex() {
108
107
mkdir ($ dest , 0755 );
109
108
}
110
109
111
- foreach ( /* [4 ] */
110
+ foreach ( /* [2 ] */
112
111
$ iterator = new \RecursiveIteratorIterator (
113
112
new \RecursiveDirectoryIterator ($ src , \RecursiveDirectoryIterator::SKIP_DOTS ), \RecursiveIteratorIterator::SELF_FIRST ) as $ item
114
113
) {
115
114
if ($ item ->isDir ()) {
116
- if (!is_dir ($ dest . DIRECTORY_SEPARATOR . $ iterator ->getSubPathName ())) { /* [5 ] */
115
+ if (!is_dir ($ dest . DIRECTORY_SEPARATOR . $ iterator ->getSubPathName ())) { /* [3 ] */
117
116
mkdir ($ dest . DIRECTORY_SEPARATOR . $ iterator ->getSubPathName ());
118
117
}
119
118
} else {
120
- if (!file_exists ($ dest . DIRECTORY_SEPARATOR . $ iterator ->getSubPathName ())) { /* [6 ] */
119
+ if (!file_exists ($ dest . DIRECTORY_SEPARATOR . $ iterator ->getSubPathName ())) { /* [4 ] */
121
120
copy ($ item , $ dest . DIRECTORY_SEPARATOR . $ iterator ->getSubPathName ());
122
121
}
123
122
}
0 commit comments