Пример #1
0
 /**
  * Run the PL tasks when a package is removed
  * @param  {Object}     a script event object from composer
  */
 public static function prePackageUninstall(PackageEvent $event)
 {
     // make sure pattern lab has been loaded
     if (class_exists("\\PatternLab\\Config")) {
         InstallerUtil::prePackageUninstallCmd($event);
     }
 }
 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
 /**
  * Fetch a package from GitHub
  * @param  {String}    the command option to provide the rule for
  * @param  {String}    the path to the package to be downloaded
  *
  * @return {String}    the modified file contents
  */
 public function fetchStarterKit($starterkit = "")
 {
     // double-checks options was properly set
     if (empty($starterkit)) {
         Console::writeError("please provide a path for the starterkit before trying to fetch it...");
     }
     // figure out the options for the GH path
     list($org, $repo, $tag) = $this->getPackageInfo($starterkit);
     // set default attributes
     $sourceDir = Config::getOption("sourceDir");
     $tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "pl-sk";
     $tempDirSK = $tempDir . DIRECTORY_SEPARATOR . "pl-sk-archive";
     $tempDirDist = $tempDirSK . DIRECTORY_SEPARATOR . $repo . "-" . $tag . DIRECTORY_SEPARATOR . "dist";
     $tempComposerFile = $tempDirSK . DIRECTORY_SEPARATOR . $repo . "-" . $tag . DIRECTORY_SEPARATOR . "composer.json";
     //get the path to the GH repo and validate it
     $tarballUrl = "https://github.com/" . $org . "/" . $repo . "/archive/" . $tag . ".tar.gz";
     Console::writeInfo("downloading the starterkit...");
     // try to download the given package
     if (!($package = @file_get_contents($tarballUrl))) {
         $error = error_get_last();
         Console::writeError("the starterkit wasn't downloaded because:\n\n  " . $error["message"]);
     }
     // Create temp directory if doesn't exist
     $fs = new Filesystem();
     try {
         $fs->mkdir($tempDir, 0775);
     } catch (IOExceptionInterface $e) {
         Console::writeError("Error creating temporary directory at " . $e->getPath());
     }
     // write the package to the temp directory
     $tempFile = tempnam($tempDir, "pl-sk-archive.tar.gz");
     file_put_contents($tempFile, $package);
     Console::writeInfo("finished downloading the starterkit...");
     // make sure the temp dir exists before copying into it
     if (!is_dir($tempDirSK)) {
         mkdir($tempDirSK);
     }
     // extract, if the zip is supposed to be unpacked do that (e.g. stripdir)
     $zippy = Zippy::load();
     $zippy->addStrategy(new UnpackFileStrategy());
     $zippy->getAdapterFor('tar.gz')->open($tempFile)->extract($tempDirSK);
     if (!is_dir($tempDirDist)) {
         // try without repo dir
         $tempDirDist = $tempDirSK . DIRECTORY_SEPARATOR . "dist";
     }
     // thrown an error if temp/dist/ doesn't exist
     if (!is_dir($tempDirDist)) {
         Console::writeError("the starterkit needs to contain a dist/ directory before it can be installed...");
     }
     // check for composer.json. if it exists use it for determining things. otherwise just mirror dist/ to source/
     if (file_exists($tempComposerFile)) {
         $tempComposerJSON = json_decode(file_get_contents($tempComposerFile), true);
         // see if it has a patternlab section that might define the files to move
         if (isset($tempComposerJSON["extra"]) && isset($tempComposerJSON["extra"]["patternlab"])) {
             Console::writeInfo("installing the starterkit...");
             InstallerUtil::parseComposerExtraList($tempComposerJSON["extra"]["patternlab"], $starterkit, $tempDirDist);
             Console::writeInfo("installed the starterkit...");
         } else {
             $this->mirrorDist($sourceDir, $tempDirDist);
         }
     } else {
         $this->mirrorDist($sourceDir, $tempDirDist);
     }
     // remove the temp files
     Console::writeInfo("cleaning up the temp files...");
     $fs = new Filesystem();
     $fs->remove($tempFile);
     $fs->remove($tempDirSK);
     Console::writeInfo("the starterkit installation is complete...");
     return true;
 }
Пример #4
0
 protected function starterKitPathPrompt()
 {
     // need to figure this out long-term
     InstallerUtil::$isInteractive = true;
     $input = Console::promptInput("Tell me the path to the starterkit you want to watch.", "e.g. vendor/pattern-lab/starterkit-mustache-demo/dist", "baz", false);
     // set-up the full starterkit path
     $starterKitPath = Config::getOption("baseDir") . $input;
     if (!is_dir($starterKitPath)) {
         Console::writeWarning("that doesn't seem to be a real directory. let's try again...");
         $starterKitPath = $this->starterKitPathPrompt();
     }
     return $starterKitPath;
 }