public function run() { // find the value given to the command $init = Console::findCommandOption("i|init"); $starterkit = Console::findCommandOptionValue("f|install"); if ($init) { $patternEngine = Config::getOption("patternExtension"); $starterkit = "pattern-lab/starterkit-" . $patternEngine . "-base"; } if ($starterkit) { // download the starterkit $f = new Fetch(); $f->fetchStarterKit($starterkit); } else { Console::writeHelpCommand($this->command); } }
public function run() { // find the value given to the command $package = Console::findCommandOptionValue("p|package"); if ($package) { // if <prompt> was passed ask the user for the package name if ($package == "prompt") { $prompt = "what is the name of the package you want to fetch?"; $options = "(ex. pattern-lab/plugin-kss)"; $package = Console::promptInput($prompt, $options); } // make sure it looks like a valid package if (strpos($package, "/") === false) { Console::writeError("that wasn't a valid package name. it should look like <info>pattern-lab/plugin-kss</info>..."); } // run composer via fetch $f = new Fetch(); $f->fetchPackage($package); } else { Console::writeHelpCommand($this->command); } }
protected function starterKitSuggestions() { Console::writeLine(""); $composerPath = Config::getOption("baseDir") . "/composer.json"; if (file_exists($composerPath)) { $json = file_get_contents($composerPath); $data = json_decode($json, true); if ($jsonErrorMessage = JSON::hasError()) { JSON::lastErrorMsg(Console::getHumanReadablePath($oldStyleAnnotationsPath), $jsonErrorMessage, $data); } if (isset($data["extra"]) && isset($data["extra"]["patternlab"]) && isset($data["extra"]["patternlab"]["starterKitSuggestions"])) { $starterKitSuggestions = $data["extra"]["patternlab"]["starterKitSuggestions"]; Console::writeInfo("suggested starterkits that work with this edition:", false, true); foreach ($starterKitSuggestions as $i => $suggestion) { $num = $i + 1; Console::writeLine($num . ": " . $suggestion, true); } // hack around installer util feature in Console::promptInput InstallerUtil::$isInteractive = true; // prompt for input on the suggestions Console::writeLine(""); $prompt = "choose an option or hit return to cancel:"; $options = "(ex. 1)"; $input = Console::promptInput($prompt, $options, "1"); $result = (int) $input - 1; if (isset($starterKitSuggestions[$result])) { Console::writeLine(""); $f = new Fetch(); $result = $f->fetchStarterKit($starterKitSuggestions[$result]); } } else { Console::writeWarning("this edition has no starterkits to suggested...", false, true); } } else { Console::writeError("can't find composer.json to get suggestions...", false, true); } }
/** * Ask questions after the create package is done * @param {Object} a script event object from composer */ public static function postCreateProjectCmd($event) { // see if there is an extra component $extra = $event->getComposer()->getPackage()->getExtra(); if (isset($extra["patternlab"])) { self::init(); Console::writeLine(""); // see if we have any starterkits to suggest if (isset($extra["patternlab"]["starterKitSuggestions"]) && is_array($extra["patternlab"]["starterKitSuggestions"])) { $suggestions = $extra["patternlab"]["starterKitSuggestions"]; // suggest starterkits Console::writeInfo("suggested starterkits that work with this edition:", false, true); foreach ($suggestions as $i => $suggestion) { // write each suggestion $num = $i + 1; Console::writeLine($num . ": " . $suggestion, true); } // prompt for input on the suggestions Console::writeLine(""); $prompt = "choose an option or hit return to skip:"; $options = "(ex. 1)"; $input = Console::promptInput($prompt, $options); $result = (int) $input - 1; if (isset($suggestions[$result])) { Console::writeLine(""); $f = new Fetch(); $result = $f->fetchStarterKit($suggestions[$result]); if ($result) { Console::writeLine(""); $g = new Generator(); $g->generate(array("foo" => "bar")); Console::writeLine(""); Console::writeInfo("type <desc>php core/console --server</desc> to start the built-in server and see Pattern Lab...", false, true); } } else { Console::writeWarning("you will need to install a StarterKit before using Pattern Lab..."); } } } }
/** * Run any migrations found in core/migrations that match the approved types * @param {String} the filename of the migration * @param {String} the path of the source directory * @param {String} the path to the destination * @param {Boolean} moving a single file or a directory */ protected function runMigration($filename, $sourcePath, $destinationPath, $singleFile) { $filename = str_replace(".json", "", $filename); print "starting the " . $filename . " migration...\n"; if ($singleFile) { copy($sourcePath . $fileName, $destinationPath . $fileName); } else { if (strpos($sourcePath, "pattern-lab/") !== false) { $sourcePath = str_replace(__DIR__ . "/../../../", "", rtrim($sourcePath, "/")); $f = new Fetch(); $f->fetch("starterkit", $sourcePath); } else { $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourcePath), \RecursiveIteratorIterator::SELF_FIRST); $objects->setFlags(\FilesystemIterator::SKIP_DOTS); foreach ($objects as $object) { // clean-up the file name and make sure it's not one of the pattern lab files or to be ignored $fileName = str_replace($sourcePath, "", $object->getPathname()); // check to see if it's a new directory if ($object->isDir() && !is_dir($destinationPath . $fileName)) { mkdir($destinationPath . $fileName); } else { if ($object->isFile()) { copy($sourcePath . $fileName, $destinationPath . $fileName); } } } } } print "completed the " . $filename . " migration...\n"; }
/** * Prompt the user to install a starterkit * @param {Array} the starterkit suggestions */ protected static function promptStarterKitInstall($starterKitSuggestions) { Console::writeLine(""); // suggest starterkits Console::writeInfo("suggested starterkits that work with this edition:", false, true); foreach ($starterKitSuggestions as $i => $suggestion) { $num = $i + 1; Console::writeLine($num . ": " . $suggestion, true); } // prompt for input on the suggestions Console::writeLine(""); $prompt = "choose an option or hit return to skip:"; $options = "(ex. 1)"; $input = Console::promptInput($prompt, $options, "1"); $result = (int) $input - 1; if (isset($starterKitSuggestions[$result])) { Console::writeLine(""); $f = new Fetch(); $result = $f->fetchStarterKit($starterKitSuggestions[$result]); } }