Exemplo n.º 1
0
 /**
  * Initializes a package template in the provided directory.
  *
  * @throws InvalidPathException
  *
  * @param $vendor
  * @param $package
  * @param $directory
  */
 public function initialize($vendor, $package, $directory)
 {
     if (!$this->files->exists($directory) || !$this->files->isDirectory($directory)) {
         throw new InvalidPathException("{$directory} does not exist or is not a valid directory.");
     }
     $packageComposer = new Package();
     $packageComposer->setVendor($vendor);
     $packageComposer->setPackage($package);
     $packageComposer->setDescription('Give your package template a good description');
     $packageComposer->setLicense(user_config('configuration.license', ''));
     $packageComposer->setAuthors(user_config('configuration.authors', []));
     $writer = new ConfigurationWriter($packageComposer->toArray());
     $writer['config'] = (object) ['vendor-dir' => '_newup_vendor'];
     $writer->save($directory . '/composer.json');
     $this->renderer->setData('package', $package);
     $this->renderer->setData('vendor', $vendor);
     $packageClass = $this->renderer->render('template');
     if (!$this->files->exists($directory . '/_newup/')) {
         $this->files->makeDirectory($directory . '/_newup/');
     }
     if ($this->shouldCreateTemplateDirectory && $this->files->exists($directory . '/_template') == false) {
         $this->files->makeDirectory($directory . '/_template');
     }
     $this->files->put($directory . '/_newup/Package.php', $packageClass);
 }
Exemplo n.º 2
0
 /**
  * Updates a given package.
  *
  * This is the wrong method if you are looking
  * for something like 'composer update'. Look
  * at the 'configurePackage' method instead.
  *
  * @throws ComposerException
  * @param $packageName
  * @return mixed
  */
 public function updatePackage($packageName)
 {
     if (!$this->packageExists($packageName)) {
         return false;
     }
     $newPackageLocation = $this->resolvePackagePath($packageName);
     $oldPackageLocation = $this->normalizePath($newPackageLocation . '_{updating_in_progress}');
     $installationInstructionsPath = $this->normalizePath($oldPackageLocation . DIRECTORY_SEPARATOR . '_newup_install_instructions');
     if ($this->files->exists($oldPackageLocation)) {
         $this->files->deleteDirectory($oldPackageLocation, false);
     }
     $this->files->makeDirectory($oldPackageLocation, 0755, true);
     $this->files->copyDirectory($newPackageLocation, $oldPackageLocation);
     $this->files->deleteDirectory($newPackageLocation, false);
     // Retrieve the old installation instructions that were stored
     // when the package template was first installed.
     $installInstructions = $this->files->get($installationInstructionsPath);
     // Write updated initiated here in case of early failures.
     $this->writePackageUpdateInitiated($newPackageLocation, $installInstructions);
     try {
         $this->addPackage($installInstructions);
         // Write updated initiated here in case of failures during configuration.
         $this->writePackageUpdateInitiated($newPackageLocation, $installInstructions);
         $this->configurePackage($packageName);
         $this->files->deleteDirectory($oldPackageLocation, false);
         $this->log->info('Updated package template', ['package' => $packageName]);
         // If we are at this point of the update process, we can safely assume that
         // it is okay to remove the update initiated file.
         $this->removePackageUpdateInitiatedFile($newPackageLocation);
         return true;
     } catch (\Exception $e) {
         // There was an issue updating the package. We will rollback.
         $this->files->deleteDirectory($newPackageLocation, false);
         $this->files->makeDirectory($newPackageLocation, 0755, true);
         $this->files->copyDirectory($oldPackageLocation, $newPackageLocation);
         $this->files->deleteDirectory($oldPackageLocation, false);
         $this->log->debug('Package updated failed', ['package' => $packageName, 'message' => $e->getMessage(), 'exception' => $e]);
         throw new ComposerException('There was an unexpected failure during the package update process.', $e->getCode(), $e);
     }
 }
Exemplo n.º 3
0
 /**
  * Creates the file tree in the given directory.
  *
  * @param  $destinationDirectory
  * @return array
  */
 public function generate($destinationDirectory)
 {
     $destinationDirectory = $destinationDirectory;
     $generatedPaths = [];
     $this->resolveAutomaticallyIgnoredPaths($destinationDirectory);
     foreach ($this->getPaths() as $pathKey => $path) {
         $fullPath = $destinationDirectory . DIRECTORY_SEPARATOR . $path['path'];
         if (!$this->shouldBeIgnored($path['path'])) {
             if ($path['type'] == 'dir') {
                 $this->fileSystem->makeDirectory($fullPath, 0755, true, true);
             } else {
                 // There are two steps here:
                 // 1st: Recursively create the directory structure for the file (it might not exist)
                 // 2nd: Create an empty file using `touch()` since we are guaranteed the directory structure exists.
                 $this->fileSystem->makeDirectory(dirname($fullPath), 0755, true, true);
                 touch($fullPath);
             }
             $generatedPaths[$pathKey] = $path + ['full' => $fullPath];
         }
     }
     $this->removeFilesAndDirectories($destinationDirectory);
     return $generatedPaths;
 }