ソースを参照

[AsseticBundle] added a --force option to assetic:dump --watch

Kris Wallsmith 14 年 前
コミット
84d5cbfba8
1 ファイル変更6 行追加5 行削除
  1. 6 5
      src/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php

+ 6 - 5
src/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php

@@ -36,6 +36,7 @@ class DumpCommand extends Command
             ->setDescription('Dumps all assets to the filesystem')
             ->addArgument('write_to', InputArgument::OPTIONAL, 'Override the configured asset root')
             ->addOption('watch', null, InputOption::VALUE_NONE, 'Check for changes every second, debug mode only')
+            ->addOption('force', null, InputOption::VALUE_NONE, 'Force an initial generation of all assets (used with --watch)')
         ;
     }
 
@@ -61,7 +62,7 @@ class DumpCommand extends Command
             throw new \RuntimeException('The --watch option is only available in debug mode.');
         }
 
-        $this->watch($output);
+        $this->watch($input, $output);
     }
 
     /**
@@ -72,17 +73,17 @@ class DumpCommand extends Command
      *
      * @param OutputInterface $output The command output
      */
-    private function watch(OutputInterface $output)
+    private function watch(InputInterface $input, OutputInterface $output)
     {
         $refl = new \ReflectionClass('Assetic\\AssetManager');
         $prop = $refl->getProperty('assets');
         $prop->setAccessible(true);
 
         $cache = sys_get_temp_dir().'/assetic_watch_'.substr(sha1($this->basePath), 0, 7);
-        if (file_exists($cache)) {
-            $previously = unserialize(file_get_contents($cache));
-        } else {
+        if ($input->getOption('force') || !file_exists($cache)) {
             $previously = array();
+        } else {
+            $previously = unserialize(file_get_contents($cache));
         }
 
         $error = '';