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);
     }
 }
 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);
     }
 }
Пример #3
0
 /**
  * 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...");
             }
         }
     }
 }
 /**
  * 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]);
     }
 }