Example #1
0
 /**
  * Build a development collection.
  *
  * @param  \Basset\Collection  $collection
  * @param  string  $group
  * @return void
  * @throws \Basset\Exceptions\BuildNotRequiredException
  */
 public function buildAsDevelopment(Collection $collection, $group)
 {
     // Get the assets of the given group from the collection. The collection is also responsible
     // for handling any ordering of the assets so that we just need to build them.
     $assets = $collection->getAssetsWithoutRaw($group);
     $entry = $this->manifest->make($identifier = $collection->getIdentifier());
     // If the collection definition has changed when compared to the manifest entry or if the
     // collection is being forcefully rebuilt then we'll reset the development assets.
     if ($this->collectionDefinitionHasChanged($assets, $entry, $group) or $this->force) {
         $entry->resetDevelopmentAssets($group);
     } else {
         $assets = $assets->filter(function ($asset) use($entry) {
             return !$entry->hasDevelopmentAsset($asset) or $asset->getBuildPath() != $entry->getDevelopmentAsset($asset);
         });
     }
     if (!$assets->isEmpty()) {
         foreach ($assets as $asset) {
             $path = "{$this->buildPath}/{$identifier}/{$asset->getBuildPath()}";
             // If the build directory does not exist we'll attempt to recursively create it so we can
             // build the asset to the directory.
             !$this->files->exists($directory = dirname($path)) and $this->files->makeDirectory($directory, 0777, true);
             $this->files->put($path, $this->gzip($asset->build()));
             // Add the development asset to the manifest entry so that we can save the built asset
             // to the manifest.
             $entry->addDevelopmentAsset($asset);
         }
     } else {
         throw new BuildNotRequiredException();
     }
 }