Skip to content

Commit fae43db

Browse files
committed
Merge branch 'dev'
Conflicts: composer.json
2 parents 448e521 + cfe95fb commit fae43db

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ root = true
22

33
[*]
44
charset = utf-8
5-
indent_style = tab
5+
indent_style = space
66
trim_trailing_whitespace = false
77
end_of_line = lf
88
insert_final_newline = true

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
![license](https://img.shields.io/github/license/pattern-lab/plugin-php-reload.svg?maxAge=2592000)
2-
[![Packagist](https://img.shields.io/packagist/v/pattern-lab/plugin-reload.svg?maxAge=2592000)](https://packagist.org/packages/pattern-lab/plugin-reload) [![Gitter](https://img.shields.io/gitter/room/pattern-lab/php.svg?maxAge=2592000)](https://gitter.im/pattern-lab/php)
1+
![license](https://img.shields.io/github/license/pattern-lab/plugin-php-reload.svg)
2+
[![Packagist](https://img.shields.io/packagist/v/pattern-lab/plugin-reload.svg)](https://packagist.org/packages/pattern-lab/plugin-reload) [![Gitter](https://img.shields.io/gitter/room/pattern-lab/php.svg)](https://gitter.im/pattern-lab/php)
33

44
# Reload Plugin for Pattern Lab
55

6-
The Reload Plugin adds Web Socket-based automatic browser reload support to Pattern Lab. The Reload Plugin will automatically reload the Pattern Lab iFrame if you're using the `--watch` flag.
6+
The Reload Plugin adds Web Socket-based automatic browser reload support to Pattern Lab. The Reload Plugin will automatically reload the Pattern Lab iFrame if you're using the `--watch` flag or `--server --with-watch` flag combo.
77

88
## Installation
99

@@ -19,8 +19,12 @@ The Reload Plugin is automatically turned on when you install it. Simply "watch"
1919

2020
php core/console --watch
2121

22+
You can also run your server and watch your project at the same time:
23+
24+
php core/console --server --with-watch
25+
2226
## Disabling the Plugin
2327

2428
To disable the Reload Plugin you can either directly edit `./config/config.yml` or use the command line option:
2529

26-
php core/console --config --set reload.on=false
30+
php core/console --config --set plugins.reload.enabled=false

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pattern-lab/plugin-reload",
33
"description": "Automatic Browser Reload Support for Pattern Lab",
4-
"keywords": ["autoreload", "pattern lab"],
4+
"keywords": ["reload", "websocket", "pattern lab"],
55
"homepage": "http://patternlab.io",
66
"license": "MIT",
77
"type": "patternlab-plugin",
@@ -27,7 +27,6 @@
2727
"php": ">=5.4",
2828
"pattern-lab/core": "^2.4.0",
2929
"wrench/wrench": "^2.0.0",
30-
"cocur/background-process": "~0.5"
3130
},
3231
"extra": {
3332
"patternlab": {
@@ -37,10 +36,11 @@
3736
]
3837
},
3938
"onready": "PluginReload.init()",
40-
"callback": "",
4139
"config": {
42-
"reload": {
43-
"on": true
40+
"plugins": {
41+
"reload": {
42+
"enabled": true
43+
}
4444
}
4545
}
4646
}

src/PatternLab/Reload/PatternLabListener.php

Lines changed: 21 additions & 9 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

37-
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();
37+
if ((bool)Config::getOption("plugins.reload.enabled")) {
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)