public function testFirstTimeWithExistingResources() { $finder = new Finder(); $finder->files()->name('*.txt')->in($this->tmpDir); $this->fs->dumpFile($this->tmpDir . '/file1.txt', 'test'); $rc = new ResourceCacheMemory(); $rw = new ResourceWatcher($rc); $rw->setFinder($finder); $this->assertCount(0, $rw->getNewResources()); $this->assertCount(0, $rw->getUpdatedResources()); $this->assertCount(0, $rw->getDeletedResources()); $this->assertFalse($rw->hasChanges()); }
public function processCommand() { $this->watch = $this->getRoute()->getMatchedParam('watch', false); $this->fileSystem = new Filesystem(); $this->setUpServer(); $command = sprintf('php -S %s:%d -t %s %s', 'localhost', '8000', $this->getPath() . '/' . $this->getPHPoole()->getOption('output.dir'), sprintf('%s/.phpoole/router.php', $this->getPath())); $this->wlAnnonce(sprintf('Starting server (http://%s:%d)...', 'localhost', '8000')); $process = new Process($command); if (!$process->isStarted()) { // write changes cache if ($this->watch) { $finder = new Finder(); $finder->files()->name('*.md')->name('*.html')->in([$this->getPath() . '/' . $this->getPHPoole()->getOption('content.dir'), $this->getPath() . '/' . $this->getPHPoole()->getOption('layouts.dir')]); if (is_dir($this->getPath() . '/' . $this->getPHPoole()->getOption('themes.dir'))) { $finder->in($this->getPath() . '/' . $this->getPHPoole()->getOption('themes.dir')); } $resourceCache = new ResourceCacheMemory(); $resourceWatcher = new ResourceWatcher($resourceCache); $resourceWatcher->setFinder($finder); $this->fileSystem->dumpFile($this->getPath() . '/.phpoole/watch.flag', ''); } // start server try { $process->start(); Plateform::openBrowser('http://localhost:8000'); while ($process->isRunning()) { // watch changes? if ($this->watch) { $resourceWatcher->findChanges(); if ($resourceWatcher->hasChanges()) { $this->fileSystem->dumpFile($this->getPath() . '/.phpoole/changes.flag', ''); // re-generate $this->wlAlert('Changes detected!'); $callable = new Build(); call_user_func($callable, $this->getRoute(), $this->getConsole()); } } usleep(1000000); // 1 s } } catch (ProcessFailedException $e) { $this->tearDownServer(); echo $e->getMessage(); exit(2); } } }
/** * Reparse a site. * * @param \Yosymfony\Spress\Core\IO\IOInterface $io * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Yosymfony\ResourceWatcher\ResourceWatcher $rw */ protected function reParse(IOInterface $io, InputInterface $input, ResourceWatcher $rw) { $rw->findChanges(); if ($rw->hasChanges() === false) { return; } $io->write(sprintf('<comment>Rebuilding site... (%s new, %s updated and %s deleted resources)</comment>', count($rw->getNewResources()), count($rw->getUpdatedResources()), count($rw->getDeletedResources()))); $spress = $this->buildSpress($io, $input); $spress->parse(); $io->write('<success>Site ready.</success>'); }
/** * Reparse a site. * * @param \Yosymfony\Spress\Core\IO\IOInterface $io * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Yosymfony\ResourceWatcher\ResourceWatcher $rw */ protected function reParse(IOInterface $io, InputInterface $input, ResourceWatcher $rw) { $rw->findChanges(); if ($rw->hasChanges() === false) { return; } $this->rebuildingSiteMessage($io, $rw->getNewResources(), $rw->getUpdatedResources(), $rw->getDeletedResources()); $spress = $this->buildSpress($io, $input); $resultData = $spress->parse(); $this->resultMessage($io, $resultData); }