Example #1
0
 /**
  * {@inheritdoc}
  */
 public function install(PackageInterface $package)
 {
     $tmpFileName = $this->config->getCacheDir() . '/tmp/' . $package->getName();
     if ($this->zipArchive->open($tmpFileName) !== true) {
         throw new RuntimeException(sprintf('Unable to open zip file %s.', $tmpFileName));
     }
     $dirName = trim($this->zipArchive->getNameIndex(0), '/');
     $info = $package->getInfo();
     $files = $this->filterZipFiles($this->zipArchive, isset($info['ignore']) ? $info['ignore'] : array(), isset($info['main']) ? (array) $info['main'] : array());
     foreach ($files as $i => $file) {
         $stat = $this->zipArchive->statIndex($i);
         $fileName = $this->config->getInstallDir() . '/' . str_replace($dirName, $package->getName(), $file);
         if (substr($fileName, -1) != '/') {
             $fileContent = $this->zipArchive->getStream($file);
             $this->filesystem->write($fileName, $fileContent);
             $this->filesystem->touch($fileName, $stat['mtime']);
         }
     }
     // adjust timestamp for directories
     foreach ($files as $i => $file) {
         $stat = $this->zipArchive->statIndex($i);
         $fileName = $this->config->getInstallDir() . '/' . str_replace($dirName, $package->getName(), $file);
         if (is_dir($fileName) && substr($fileName, -1) == '/') {
             $this->filesystem->touch($fileName, $stat['mtime']);
         }
     }
     $this->zipArchive->close();
     // create .bower.json metadata file
     // XXX we still need to add some other info
     $dotBowerContent = array_merge($package->getInfo(), array('version' => $package->getVersion()));
     $dotBowerJson = str_replace('\\/', '/', Json::encode($dotBowerContent));
     $this->filesystem->write($this->config->getInstallDir() . '/' . $package->getName() . '/.bower.json', $dotBowerJson);
 }
Example #2
0
 /**
  * Get remote bower.json file (or package.json file)
  *
  * @param  string $version
  * @return string
  */
 private function getDepBowerJson($version)
 {
     list($repoUser, $repoName) = explode('/', $this->clearGitURL($this->url));
     $contents = $this->githubClient->api('repo')->contents();
     if ($contents->exists($repoUser, $repoName, 'bower.json', $version)) {
         $json = $contents->download($repoUser, $repoName, 'bower.json', $version);
     } else {
         $isPackageJson = true;
         if ($contents->exists($repoUser, $repoName, 'package.json', $version)) {
             $json = $contents->download($repoUser, $repoName, 'package.json', $version);
         } elseif ($version != 'master') {
             return $this->getDepBowerJson('master');
         }
         // try anyway. E.g. exists() return false for Modernizr, but then it downloads :-|
         $json = $contents->download($repoUser, $repoName, 'package.json', $version);
     }
     if (substr($json, 0, 3) == "") {
         $json = substr($json, 3);
     }
     // for package.json, remove dependencies (see the case of Modernizr)
     if (isset($isPackageJson)) {
         $array = json_decode($json, true);
         if (isset($array['dependencies'])) {
             unset($array['dependencies']);
         }
         $json = Json::encode($array);
     }
     return $json;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function updateBowerJsonFile2(array $old, array $new)
 {
     $json = Json::encode(array_merge($old, $new));
     $file = getcwd() . '/' . $this->stdBowerFileName;
     return $this->filesystem->write($file, $json);
 }
 /**
  * writelnJson
  *
  * @param mixed $jsonPart
  */
 public function writelnJsonText($jsonPart)
 {
     $this->output->writeln(sprintf('<fg=cyan>%s</fg=cyan>', Json::encode($jsonPart)));
 }