/** * Compile an asset collection. * * @param Basset\Collection $collection * @return void */ protected function compile(Collection $collection) { $force = isset($_SERVER['CLI']['FORCE']); // If the compile path does not exist attempt to create it. if (!File::exists($this->compilePath)) { File::mkdir($this->compilePath); } $groups = $collection->getAssets(); if (empty($groups)) { echo "The collection '{$collection->getName()}' has no assets to compile.\n"; } foreach ($groups as $group => $assets) { $path = $this->compilePath . '/' . $collection->getCompiledName($group); // We only compile a collection if a compiled file doesn't exist yet or if a change to one of the assets // in the collection is detected by comparing the last modified times. if (File::exists($path) and File::modified($path) >= $collection->lastModified($group)) { // If the force flag has been set then we'll recompile, otherwise this collection does not need // to be changed. if (!$force) { echo "The {$group}s for the collection '{$collection->getName()}' do not need to be compiled.\n"; continue; } } $compiled = $collection->compile($group); echo "Successfully compiled {$collection->getCompiledName($group)}\n"; File::put($path, $compiled); } }