/** * Common init sequence */ protected static function init() { // start the timer Timer::start(); // initialize the console to print out any issues Console::init(); // initialize the config for the pluginDir $baseDir = __DIR__ . "/../../../../../"; Config::init($baseDir, false); // make sure the source dir is set-up $sourceDir = Config::getOption("sourceDir"); if (!is_dir($sourceDir)) { FileUtil::makeDir($sourceDir); } // make sure the public dir is set-up $publicDir = Config::getOption("publicDir"); if (!is_dir($publicDir)) { FileUtil::makeDir($publicDir); } Dispatcher::init(); }
/** * Generates the data that powers the index page */ protected function generateIndex() { // bomb if missing index.html if (!file_exists(Config::getOption("publicDir") . "/index.html")) { $index = Console::getHumanReadablePath(Config::getOption("publicDir")) . DIRECTORY_SEPARATOR . "index.html"; Console::writeError("<path>" . $index . "</path> is missing. grab a copy from your StyleguideKit..."); } // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); // note the start of the operation $dispatcherInstance->dispatch("builder.generateIndexStart"); // default var $dataDir = Config::getOption("publicDir") . "/styleguide/data"; // double-check that the data directory exists if (!is_dir($dataDir)) { FileUtil::makeDir($dataDir); } $output = ""; // load and write out the config options $config = array(); $exposedOptions = Config::getOption("exposedOptions"); foreach ($exposedOptions as $exposedOption) { $config[$exposedOption] = Config::getOption($exposedOption); } $output .= "var config = " . json_encode($config) . ";\n"; // load the ish Controls $ishControls = array(); $controlsToHide = array(); $ishControlsHide = Config::getOption("ishControlsHide"); if ($ishControlsHide) { foreach ($ishControlsHide as $controlToHide) { $controlsToHide[$controlToHide] = "true"; } } $ishControls["ishControlsHide"] = $controlsToHide; $output .= "var ishControls = " . json_encode($ishControls) . ";\n"; // load and write out the items for the navigation $niExporter = new NavItemsExporter(); $navItems = $niExporter->run(); $output .= "var navItems = " . json_encode($navItems) . ";\n"; // load and write out the items for the pattern paths $patternPaths = array(); $ppdExporter = new PatternPathDestsExporter(); $patternPaths = $ppdExporter->run(); $output .= "var patternPaths = " . json_encode($patternPaths) . ";\n"; // load and write out the items for the view all paths $viewAllPaths = array(); $vapExporter = new ViewAllPathsExporter(); $viewAllPaths = $vapExporter->run($navItems); $output .= "var viewAllPaths = " . json_encode($viewAllPaths) . ";\n"; // gather plugin package information $packagesInfo = array(); $componentDir = Config::getOption("componentDir"); if (!is_dir($componentDir)) { mkdir($componentDir); } $componentPackagesDir = $componentDir . "/packages"; if (!is_dir($componentDir . "/packages")) { mkdir($componentDir . "/packages"); } $finder = new Finder(); $finder->files()->name("*.json")->in($componentPackagesDir); $finder->sortByName(); foreach ($finder as $file) { $filename = $file->getFilename(); if ($filename[0] != "_") { $javascriptPaths = array(); $packageInfo = json_decode(file_get_contents($file->getPathname()), true); foreach ($packageInfo["templates"] as $templateKey => $templatePath) { $templatePathFull = $componentDir . "/" . $packageInfo["name"] . "/" . $templatePath; $packageInfo["templates"][$templateKey] = file_exists($templatePathFull) ? file_get_contents($templatePathFull) : ""; } foreach ($packageInfo["javascripts"] as $key => $javascriptPath) { $javascriptPaths[] = "patternlab-components/" . $packageInfo["name"] . "/" . $javascriptPath; } $packageInfo["javascripts"] = $javascriptPaths; $packagesInfo[] = $packageInfo; } } $output .= "var plugins = " . json_encode($packagesInfo) . ";"; // write out the data file_put_contents($dataDir . "/patternlab-data.js", $output); // note the end of the operation $dispatcherInstance->dispatch("builder.generateIndexEnd"); }