Skip to content

Commit 283010d

Browse files
committed
correcting for a bad saved full path
1 parent 94d7b43 commit 283010d

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

config/config.yml.default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ cacheBusterOn: "true"
3737
exportDir: "export"
3838
publicDir: "public"
3939
sourceDir: "source"
40+
styleguideKitPath: ""

src/PatternLab/Config.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ public static function getOptions() {
7474
return self::$options;
7575
}
7676

77+
/**
78+
* Review the given styleguideKitPath to handle pre-2.1.0 backwards compatibility
79+
* @param {String} styleguideKitPath from config.yml
80+
*
81+
* @return {String} the final, post-2.1.0-style styleguideKitPath
82+
*/
83+
protected static function getStyleguideKitPath($styleguideKitPath) {
84+
85+
$styleguideKitPathFinal = "";
86+
if ($styleguideKitPath[0] == DIRECTORY_SEPARATOR) {
87+
if (strpos($styleguideKitPath, DIRECTORY_SEPARATOR."vendor".DIRECTORY_SEPARATOR === 0)) {
88+
$styleguideKitPathFinal = $styleguideKitPath; // mistaken set-up, pass to final for clean-up
89+
} else if (strpos($styleguideKitPath, self::$options["baseDir"]) === 0) {
90+
$styleguideKitPathFinal = str_replace(self::$options["baseDir"], "", $styleguideKitPath); // just need to peel off the base
91+
} else if (strpos($styleguideKitPath, DIRECTORY_SEPARATOR."vendor") !== false) {
92+
$parts = explode(DIRECTORY_SEPARATOR."vendor".DIRECTORY_SEPARATOR, $styleguideKitPath); // set on another machine's config.yml? try to be smart about it
93+
$styleguideKitPathFinal = "vendor".DIRECTORY_SEPARATOR.$parts[1];
94+
Console::writeInfo("Please double-check the styleguideKitPath option in <path>./config/config.yml</path>. It should be a path relative to the root of your Pattern Lab project...");
95+
}
96+
}
97+
98+
Console::writeInfo($styleguideKitPathFinal);
99+
return $styleguideKitPathFinal;
100+
101+
}
102+
77103
/**
78104
* Adds the config options to a var to be accessed from the rest of the system
79105
* If it's an old config or no config exists this will update and generate it.
@@ -172,17 +198,20 @@ public static function init($baseDir = "", $verbose = true) {
172198
}
173199

174200
// set-up the various dirs
175-
self::$options["configDir"] = self::$userConfigDir;
176-
self::$options["coreDir"] = is_dir(self::$options["baseDir"]."_core") ? self::$options["baseDir"]."_core" : self::$options["baseDir"]."core";
177-
self::$options["exportDir"] = isset(self::$options["exportDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["exportDir"]) : self::$options["baseDir"]."exports";
178-
self::$options["publicDir"] = isset(self::$options["publicDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["publicDir"]) : self::$options["baseDir"]."public";
179-
self::$options["scriptsDir"] = isset(self::$options["scriptsDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["scriptsDir"]) : self::$options["baseDir"]."scripts";
180-
self::$options["sourceDir"] = isset(self::$options["sourceDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["sourceDir"]) : self::$options["baseDir"]."source";
181-
self::$options["componentDir"] = self::$options["publicDir"]."/patternlab-components";
182-
self::$options["dataDir"] = self::$options["sourceDir"]."/_data";
183-
self::$options["patternExportDir"] = self::$options["exportDir"]."/patterns";
184-
self::$options["patternPublicDir"] = self::$options["publicDir"]."/patterns";
185-
self::$options["patternSourceDir"] = self::$options["sourceDir"]."/_patterns";
201+
self::$options["configDir"] = self::$userConfigDir;
202+
self::$options["coreDir"] = is_dir(self::$options["baseDir"]."_core") ? self::$options["baseDir"]."_core" : self::$options["baseDir"]."core";
203+
self::$options["exportDir"] = isset(self::$options["exportDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["exportDir"]) : self::$options["baseDir"]."exports";
204+
self::$options["publicDir"] = isset(self::$options["publicDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["publicDir"]) : self::$options["baseDir"]."public";
205+
self::$options["scriptsDir"] = isset(self::$options["scriptsDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["scriptsDir"]) : self::$options["baseDir"]."scripts";
206+
self::$options["sourceDir"] = isset(self::$options["sourceDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["sourceDir"]) : self::$options["baseDir"]."source";
207+
self::$options["componentDir"] = self::$options["publicDir"]."/patternlab-components";
208+
self::$options["dataDir"] = self::$options["sourceDir"]."/_data";
209+
self::$options["patternExportDir"] = self::$options["exportDir"]."/patterns";
210+
self::$options["patternPublicDir"] = self::$options["publicDir"]."/patterns";
211+
self::$options["patternSourceDir"] = self::$options["sourceDir"]."/_patterns";
212+
213+
// handle a pre-2.1.0 styleguideKitPath before saving it
214+
self::$options["styleguideKitPath"] = self::$options["baseDir"].self::cleanDir(self::getStyleguideKitPath(self::$options["styleguideKitPath"]));
186215

187216
// make sure styleguideExcludes is set to an array even if it's empty
188217
if (is_string(self::$options["styleGuideExcludes"])) {

src/PatternLab/InstallerUtil.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,11 @@ protected static function packagesInstall($installerInfo) {
610610
// address other specific needs based on type
611611
if ($type == "patternlab-patternengine") {
612612
self::scanForPatternEngineRule($pathBase);
613-
} else if ($type == "patternlab-starterkit") {
614-
Config::updateConfigOption("starterKit",$name);
615-
Config::updateConfigOption("starterKitPath",$pathBase);
616613
} else if (($type == "patternlab-styleguidekit") && (strpos($name,"-assets-") === false)) {
614+
$dir = str_replace(Config::getOption("baseDir"), "", $pathBase);
615+
$dir = ($dir[strlen($dir)-1] == DIRECTORY_SEPARATOR) ? rtrim($dir, DIRECTORY_SEPARATOR) : $dir;
617616
Config::updateConfigOption("styleguideKit",$name);
618-
Config::updateConfigOption("styleguideKitPath",$pathBase);
617+
Config::updateConfigOption("styleguideKitPath",$dir);
619618
}
620619

621620
}

0 commit comments

Comments
 (0)