Skip to content

Commit b16f3f6

Browse files
committed
fix: cleaning up base path directory logic to make a little less prone to breaking
1 parent 0eace9e commit b16f3f6

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Diff for: src/PatternLab/Builder.php

+13-14
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,23 @@ protected function generateIndex() {
8282
* Handle missing index.html. Solves https://github.com/drupal-pattern-lab/patternlab-php-core/issues/14
8383
* Could also be used to re-add missing styleguidekit assets with a few edits?
8484
*
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)
9189
*/
9290
if (!file_exists(Config::getOption("publicDir")."/index.html")) {
9391
$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...");
9593

94+
$baseDir = Config::getOption("baseDir") . '/vendor';
9695
$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();
10099

101100
foreach ($finder as $file) {
102-
$src = dirname($file->getRealPath()) . DIRECTORY_SEPARATOR . 'dist'; /* [3] */
101+
$src = dirname($file->getRealPath()) . DIRECTORY_SEPARATOR . 'dist'; /* [1] */
103102
$dest= Config::getOption("publicDir");
104103

105104
if (is_dir($src)){
@@ -108,16 +107,16 @@ protected function generateIndex() {
108107
mkdir($dest, 0755);
109108
}
110109

111-
foreach ( /* [4] */
110+
foreach ( /* [2] */
112111
$iterator = new \RecursiveIteratorIterator(
113112
new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item
114113
) {
115114
if ($item->isDir()) {
116-
if(!is_dir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [5] */
115+
if(!is_dir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [3] */
117116
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
118117
}
119118
} else {
120-
if(!file_exists($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [6] */
119+
if(!file_exists($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [4] */
121120
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
122121
}
123122
}

0 commit comments

Comments
 (0)