Skip to content

Commit 468958c

Browse files
committed
updating to match the new process spawner
1 parent 1eb9d32 commit 468958c

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/PatternLab/Reload/PatternLabListener.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
namespace PatternLab\Reload;
1414

15-
use \Cocur\BackgroundProcess\BackgroundProcess;
1615
use \PatternLab\Config;
1716
use \PatternLab\Console;
17+
use \PatternLab\Console\ProcessSpawnerEvent;
1818
use \PatternLab\Data;
1919

2020
class PatternLabListener extends \PatternLab\Listener {
@@ -25,20 +25,32 @@ class PatternLabListener extends \PatternLab\Listener {
2525
public function __construct() {
2626

2727
// add listener
28-
$this->addListener("watcher.start","initServer");
28+
$this->addListener("processSpawner.getPluginProcesses","addProcess");
2929

3030
}
3131

3232
/**
33-
* Initialize the web socket server
33+
* Add command to initialize the websocket server
3434
*/
35-
public function initServer() {
35+
public function addProcess(ProcessSpawnerEvent $event) {
3636

3737
if ((bool)Config::getOption("reload.on")) {
38-
$php = isset($_SERVER["_"]) ? $_SERVER["_"] : Config::getOption("phpBin");
39-
$path = __DIR__."/AutoReloadServer.php";
40-
$process = new BackgroundProcess($php." ".$path);
41-
$process->run();
38+
39+
// only run this command if watch is going to be used
40+
if (Console::findCommand("w|watch") || Console::findCommandOption("with-watch")) {
41+
42+
// set-up the command
43+
$pathPHP = Console::getPathPHP();
44+
$pathReload = __DIR__."/AutoReloadServer.php";
45+
$command = "exec ".$pathPHP." ".$pathReload;
46+
47+
// send the processes on their way
48+
$processes = array();
49+
$processes[] = array("command" => $command, "timeout" => null, "idle" => 600, "output" => false);
50+
$event->addPluginProcesses($processes);
51+
52+
}
53+
4254
}
4355

4456
}

0 commit comments

Comments
 (0)