Skip to content

Commit e1dce36

Browse files
committed
looser check of source & public dir. will now build
1 parent 2b8a581 commit e1dce36

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/PatternLab/Config.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,9 @@ public static function init($baseDir = "", $verbose = true) {
218218
self::$options["styleguideKitPath"] = self::$options["baseDir"].self::cleanDir(self::getStyleguideKitPath(self::$options["styleguideKitPath"]));
219219
}
220220

221-
// double-check a few directories are real
222-
// refactor this at some point. it's verbose
223-
if (!isset(self::$options["sourceDir"])) {
224-
Console::writeError("please make sure sourceDir is set in <path>./config/config.yml</path> by adding 'sourceDir=some/path'. sorry, stopping pattern lab... :(");
225-
} else if (!is_dir(self::$options["sourceDir"])) {
226-
Console::writeError("hrm... i can't seem to find the directory with your source files. are you sure they're at <path>".Console::getHumanReadablePath(self::$options["sourceDir"])."</path>? you can fix this in <path>./config/config.yml</path> by editing sourceDir. sorry, stopping pattern lab... :(");
227-
}
228-
if (!isset(self::$options["publicDir"])) {
229-
Console::writeError("please make sure publicDir is set in <path>./config/config.yml</path> by adding 'publicDir=some/path'. sorry, stopping pattern lab... :(");
230-
} else if (!is_dir(self::$options["publicDir"])) {
231-
Console::writeError("hrm... i can't seem to find the directory where you want to write your styleguide. are you sure it's at <path>".Console::getHumanReadablePath(self::$options["sourceDir"])."</path>? you can fix this in <path>./config/config.yml</path> by editing publicDir. sorry, stopping pattern lab... :(");
232-
}
233-
if (isset(self::$options["styleguideKitPath"]) && !is_dir(self::$options["styleguideKitPath"])) {
234-
Console::writeError("hrm... i can't seem to find the directory where your styleguide files are located. are you sure it's at <path>".Console::getHumanReadablePath(self::$options["styleguideKitPath"])."</path>? you can fix this in <path>./config/config.yml</path> by editing styleguideKitPath. sorry, stopping pattern lab... :(");
235-
}
236-
221+
// double-check a few directories are real and set-up
222+
FileUtil::checkPathFromConfig(self::$options["sourceDir"], self::$userConfigPath, "sourceDir");
223+
FileUtil::checkPathFromConfig(self::$options["publicDir"], self::$userConfigPath, "publicDir");
237224

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

src/PatternLab/FileUtil.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,42 @@
2020
use \Symfony\Component\Filesystem\Exception\IOExceptionInterface;
2121

2222
class FileUtil {
23-
23+
24+
/**
25+
* Check that a dir from the config exists and try to build it if needed
26+
* @param {String} directory to be checked/built
27+
* @param {String} the config path
28+
* @param {String} the config option that would help them
29+
*/
30+
public static function checkPathFromConfig($path, $configPath, $configOption = "") {
31+
32+
if (!isset($path)) {
33+
Console::writeError("please make sure ".$configOption." is set in <path>".Console::getHumanReadablePath($configPath)."</path> by adding '".$configOption."=some/path'. sorry, stopping pattern lab... :(");
34+
} else if (!is_dir($path)) {
35+
Console::writeWarning("i can't seem to find the directory <path>".Console::getHumanReadablePath($path)."</path>...");
36+
self::makeDir($path);
37+
Console::writeWarning("i created <path>".Console::getHumanReadablePath($path)."</path> just in case. you can edit this in <path>".Console::getHumanReadablePath($configPath)."</path> by editing ".$configOption."...");
38+
}
39+
40+
}
41+
42+
/**
43+
* Make a directory
44+
* @param {String} directory to be made
45+
*/
46+
public static function makeDir($dir) {
47+
$fs = new Filesystem();
48+
try {
49+
$fs->mkdir($dir);
50+
} catch (IOExceptionInterface $e) {
51+
Console::writeError("an error occurred while creating your directory at <path>".$e->getPath()."</path>...");
52+
}
53+
unset($fs);
54+
}
55+
2456
/**
2557
* Copies a file from the given source path to the given public path.
26-
* THIS IS NOT FOR PATTERNS
58+
* THIS IS NOT FOR PATTERNS
2759
* @param {String} the source file
2860
* @param {String} the public file
2961
*/

src/PatternLab/Template.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public static function init() {
4646
$styleguideKit = Config::getOption("styleguideKit");
4747
$styleguideKitPath = Config::getOption("styleguideKitPath");
4848

49+
if (!$styleguideKitPath || !is_dir($styleguideKitPath)) {
50+
Console::writeError("your styleguide won't render because i can't find your styleguide files. are you sure they're at <path>".Console::getHumanReadablePath($styleguideKitPath)."</path>? you can fix this in <path>./config/config.yml</path> by editing styleguideKitPath...");
51+
}
52+
4953
// load pattern-lab's resources
5054
$partialPath = $styleguideKitPath."/views/partials";
5155
$generalHeaderPath = $partialPath."/general-header.".$patternExtension;

0 commit comments

Comments
 (0)