Exemplo n.º 1
0
 public function run()
 {
     $watcher = new ResourceWatcher();
     foreach ($this->monitor as $k => $monitor) {
         $closure = $monitor[1];
         $closure->bindTo($this->bindTo);
         foreach ($monitor[0] as $i => $dir) {
             $watcher->track("fs.{$k}.{$i}", $dir, FilesystemEvent::MODIFY);
             $this->printTaskInfo("watching <info>{$dir}</info> for changes...");
             $watcher->addListener("fs.{$k}.{$i}", $closure);
         }
     }
     $watcher->start();
     return Result::success($this);
 }
Exemplo n.º 2
0
 /**
  * @param string $message
  *
  * @return string
  */
 public function ask($message)
 {
     $runAgainText = "Press <Enter> to reexecute, press any other key and <Enter> to stop...";
     if ($message != $runAgainText) {
         return parent::ask($message);
     }
     /** @var \mageekguy\atoum\writers\std\out $outputWriter */
     $outputWriter = $this->getOutputWriter();
     $watcher = new ResourceWatcher();
     $onEvent = function (FilesystemEvent $event) use($watcher, $outputWriter) {
         $outputWriter->write($event->getResource()->getId() . " has been modified." . PHP_EOL);
         $watcher->stop();
     };
     foreach ($this->configuration->getWatchedFiles() as $watchedFile) {
         $watcher->track($watchedFile, $watchedFile);
         $watcher->addListener($watchedFile, $onEvent);
     }
     foreach ($this->getRunner()->getTestPaths() as $path) {
         $watcher->track($path, $path);
         $watcher->addListener($path, $onEvent);
     }
     $outputWriter->write('Waiting for a file to change to run the test(s)... (Use CTRL+C to stop)' . PHP_EOL);
     $watcher->start();
     return '';
 }
Exemplo n.º 3
0
 public function run()
 {
     if (!class_exists('Lurker\\ResourceWatcher')) {
         return Result::errorMissingPackage($this, 'ResourceWatcher', 'henrikbjorn/lurker');
     }
     $watcher = new ResourceWatcher();
     foreach ($this->monitor as $k => $monitor) {
         $closure = $monitor[1];
         $closure->bindTo($this->bindTo);
         foreach ($monitor[0] as $i => $dir) {
             $watcher->track("fs.{$k}.{$i}", $dir, FilesystemEvent::MODIFY);
             $this->printTaskInfo('Watching {dir} for changes...', ['dir' => $dir]);
             $watcher->addListener("fs.{$k}.{$i}", $closure);
         }
     }
     $watcher->start();
     return Result::success($this);
 }
Exemplo n.º 4
0
 /**
  * @return string
  */
 public function runAgain()
 {
     /** @var \mageekguy\atoum\writers\std\out $outputWriter */
     $outputWriter = $this->runner->getOutputWriter();
     $watcher = new ResourceWatcher();
     $onEvent = function (FilesystemEvent $event) use($watcher, $outputWriter) {
         $outputWriter->write((string) $event->getResource() . " has been modified." . PHP_EOL);
         $watcher->stop();
     };
     foreach ($this->configuration->getWatchedFiles() as $watchedFile) {
         $watcher->track($watchedFile, $watchedFile);
         $watcher->addListener($watchedFile, $onEvent);
     }
     foreach ($this->runner->getRunner()->getTestPaths() as $path) {
         $watcher->track($path, $path);
         $watcher->addListener($path, $onEvent);
     }
     $outputWriter->write('Waiting for a file to change to run the test(s)... (Use CTRL+C to stop)' . PHP_EOL);
     $watcher->start();
     return '';
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->app = $this->getApplication()->getApplication();
     $this->input = $input;
     $this->output = $output;
     if (false == ($themes = $this->getThemes())) {
         $output->writeln("<error>No valid theme to install.</error>");
         exit(1);
     }
     $staticDir = $this->getStaticDir();
     $output->writeln("<comment>The static folder will be '{$staticDir}'</comment>");
     $output->writeln('');
     $themeData = [];
     $filesystem = new Filesystem();
     $doMirror = function ($sourceDir, $destDir) use($filesystem, $themeData) {
         $filesystem->mirror($sourceDir, $destDir, null, ['override' => true, 'delete' => true]);
     };
     foreach ($themes as $theme) {
         $destDir = $staticDir . DIRECTORY_SEPARATOR . $theme->getName();
         if (!is_dir($destDir) && !mkdir($destDir, 0777, true)) {
             $output->writeln("<error>Unable to read or create the folder '{$destDir}'</error>");
         }
         $sourceDir = $theme->getStaticDir();
         if (!is_dir($sourceDir)) {
             continue;
         }
         $doMirror($sourceDir, $destDir);
         $output->writeln("  <info>Theme '{$theme->getName()}' is successfully installed.</info>");
         $themeData[$theme->getName()] = ['source_dir' => $sourceDir, 'dest_dir' => $destDir];
     }
     if ($input->getOption('watch')) {
         $watcher = new ResourceWatcher();
         $output->writeln('');
         $output->writeln('<comment>Started watching static resources...</comment>');
         $callback = function (FilesystemEvent $event) use($themeData, $doMirror, $output) {
             $themeName = $event->getTrackedResource()->getTrackingId();
             $typeLabel = self::$watcherTypes[$event->getType()];
             $data = $themeData[$themeName];
             $doMirror($data['source_dir'], $data['dest_dir']);
             $output->writeln("  - {$event->getResource()} {$typeLabel}: <info>updated {$themeName} static resources.<info>");
         };
         foreach ($themeData as $name => $data) {
             $watcher->track($name, $data['source_dir'], FilesystemEvent::ALL);
             $watcher->addListener($name, $callback);
         }
         $watcher->start();
     }
     return 0;
 }
Exemplo n.º 6
0
 public function testTrackingFunctionally()
 {
     $file = tempnam(sys_get_temp_dir(), 'sf2_resource_watcher_');
     $event = null;
     $watcher = new ResourceWatcher();
     $watcher->trackByListener($file, function ($firedEvent) use(&$event) {
         $event = $firedEvent;
     });
     usleep(2000000);
     touch($file);
     $watcher->start(1, 1);
     $this->assertNotNull($event);
     $this->assertSame($file, (string) $event->getResource());
     $this->assertSame(FilesystemEvent::MODIFY, $event->getType());
     $watcher->stop();
     unlink($file);
     $watcher->start(1, 1);
     $this->assertNotNull($event);
     $this->assertSame($file, (string) $event->getResource());
     $this->assertSame(FilesystemEvent::DELETE, $event->getType());
 }
Exemplo n.º 7
0
<?php

use Lucid\Lucid;
use Lurker\Event\FilesystemEvent;
use Lurker\ResourceWatcher;
define('BIN_PATH', dirname($_SERVER['PWD'] . '/' . $_SERVER['SCRIPT_FILENAME']));
define('ROOT_PATH', realpath(BIN_PATH . '/../'));
include ROOT_PATH . '/bootstrap.php';
ob_end_clean();
$scssConfig = (include ROOT_PATH . '/config/scss.php');
$jsConfig = (include ROOT_PATH . '/config/javascript.php');
$watcher = new ResourceWatcher();
$scssEvent = function (FilesystemEvent $event) {
    $cmd = ' php bin/lucid.php compile-sass';
    app('logger')->info('Recompiling scss: ' . $cmd);
    shell_exec($cmd);
};
for ($i = 0; $i < count($scssConfig['importPaths']); $i++) {
    $watcher->track('scss' . strval($i), $scssConfig['importPaths'][$i]);
    $watcher->addListener('scss' . strval($i), $scssEvent);
}
$jsEvent = function (FilesystemEvent $event) {
    $cmd = 'php bin/lucid.php compile-javascript';
    app('logger')->info('Recompiling javascript: ' . $cmd);
    shell_exec($cmd);
};
$jsPaths = array_keys($jsConfig['include']);
for ($i = 0; $i < count($jsPaths); $i++) {
    $watcher->track('js' . strval($i), $jsPaths[$i]);
    $watcher->addListener('js' . strval($i), $jsEvent);
}