コード例 #1
0
ファイル: GulpCompiler.php プロジェクト: oktopost/aquarium
 /**
  * @param IGulpAction[] $actions
  * @param CompilerSetup $setup
  * @return ResourceCollection
  */
 private function compile(array $actions, CompilerSetup $setup)
 {
     if (!$setup->CompileTarget->hasAny()) {
         return clone $setup->Unchanged;
     }
     if (!$actions) {
         return clone $setup->Unchanged->add($setup->CompileTarget);
     }
     $commands = [];
     $compiledCollection = clone $setup->CompileTarget;
     foreach ($actions as $action) {
         $action->setTargetDir($this->config->TargetDirectory);
         $map = $action->getMap($setup->Package, $compiledCollection);
         $commands[] = $action->getCommand($setup->Package, $compiledCollection);
         $map->apply($compiledCollection);
     }
     foreach ($commands as $command) {
         $this->execute($setup->Package, [$command]);
     }
     if ($this->config->IsAddTimestamp) {
         foreach ($compiledCollection->get() as $compiledFile) {
             $timestampFile = $this->timeHelper->findFileWithTimestamp($compiledFile);
             if ($timestampFile && (new FileSystem())->isFilesSame($timestampFile, $compiledFile)) {
                 // Make sure on next compilation this file will not be affected.
                 touch($timestampFile);
                 $compiledCollection->replace($compiledFile, $timestampFile);
                 continue;
             }
             if ($timestampFile) {
                 unlink($timestampFile);
             }
             $timestampName = $this->timeHelper->generateTimestampForFile($compiledFile);
             $compiledCollection->replace($compiledFile, $timestampName);
             rename($compiledFile, $timestampName);
         }
     }
     $compiledCollection->add($setup->Unchanged);
     return $compiledCollection;
 }
コード例 #2
0
ファイル: PreCompiler.php プロジェクト: oktopost/aquarium
 /**
  * @param Package $p
  * @param IGulpAction[] $actions
  * @param ResourceCollection $collection
  * @return CompilerSetup
  */
 private function preCompileActions(Package $p, array $actions, ResourceCollection $collection)
 {
     $modifiedCollection = clone $collection;
     /** @var ResourceMap $modifiedMap */
     $modifiedMap = new ResourceMap();
     // Detect changes.
     foreach ($actions as $action) {
         $action->setTargetDir($this->config->TargetDirectory);
         $map = $action->getMap($p, $modifiedCollection);
         $map->apply($modifiedCollection);
         $modifiedMap->modify($map);
     }
     $modified = $this->getModified($modifiedMap);
     $setup = $this->preCompileHelper->getRecompileTargets($p, $modifiedMap, $modified);
     // All resource files that have an unmodified target resource.
     $unmodifiedSourceFiles = [];
     foreach ($setup->Unchanged as $unmodifiedTarget) {
         $data = $modifiedMap->getMapFor($unmodifiedTarget);
         $unmodifiedSourceFiles = array_merge($unmodifiedSourceFiles, is_array($data) ? $data : [$data]);
     }
     // Upend source resource files that were not used to create any package.
     foreach ($collection as $resource) {
         // File will be used to recompile.
         if ($setup->CompileTarget->hasResource($resource)) {
             continue;
         }
         // File used for a library that was not modified.
         if (in_array($resource, $unmodifiedSourceFiles)) {
             continue;
         }
         // Else file is not modified at all.
         $setup->CompileTarget->add($resource);
     }
     // Rename target files to target files with timestamp.
     if ($this->config->IsAddTimestamp) {
         foreach ($setup->Unchanged->get() as $unchanged) {
             $setup->Unchanged->replace($unchanged, $this->timestampHelper->findFileWithTimestamp($unchanged));
         }
     }
     return $setup;
 }