Skip to content

Commit 8913c0a

Browse files
committed
add live-reload command
1 parent 6bec94d commit 8913c0a

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/Ubiquity/devtools/cmd/Command.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* This class is part of Ubiquity
1111
*
1212
* @author jc
13-
* @version 1.0.0
13+
* @version 1.0.2
1414
*
1515
*/
1616
class Command {
@@ -269,6 +269,17 @@ public static function serve() {
269269
'Starts a reactPHP server at 127.0.0.1:8080' => 'Ubiquity serve -t=react'
270270
], 'servers');
271271
}
272+
273+
public static function liveReload() {
274+
return new Command("livereload", "path", "Start the live reload server.", ['live-reload','live'], [
275+
"p" => Parameter::create("port", "Sets the listen port number.", [], 35729),
276+
"i" => Parameter::create("include", "Include file matching pattern .", []),
277+
"e" => Parameter::create("exclude", "Exclude file matching pattern .", [])
278+
], [
279+
'Starts the live-reload server at 127.0.0.1:35729' => 'Ubiquity live-reload',
280+
'Starts the live-reload server at 127.0.0.1:35800 excluding log files' => 'Ubiquity live-reload -p=35800 -e=logs/*'
281+
], 'servers');
282+
}
272283

273284
public static function selfUpdate() {
274285
return new Command("self-update", "", "Updates Ubiquity framework for the current project.", [], [], [], 'installation');
@@ -668,6 +679,7 @@ public static function getCommands() {
668679

669680
self::project(),
670681
self::serve(),
682+
self::liveReload(),
671683
self::bootstrap(),
672684
self::help(),
673685
self::version(),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
namespace Ubiquity\devtools\debug;
3+
4+
5+
use Ubiquity\utils\http\URequest;
6+
7+
/**
8+
* Class for debug in dev mode.
9+
* Ubiquity\devtools\debug$Debug
10+
* This class is part of Ubiquity
11+
*
12+
* @author jc
13+
* @version 1.0.0
14+
*
15+
*/
16+
class Debug {
17+
public static function liveReload(int $port=35729):string{
18+
if(!URequest::isAjax()) {
19+
return '<script>document.write(\'<script src="http://\' + (location.host || \'localhost\').split(\':\')[0] +
20+
\':' . $port . '/livereload.js?snipver=2"></\' + \'script>\')</script>';
21+
}
22+
}
23+
24+
public static function hasLiveReload():bool{
25+
\exec('livereloadx --version', $foo, $exitCode);
26+
return $exitCode === 0;
27+
}
28+
29+
}

src/Ubiquity/devtools/utils/FileUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public static function cleanPathname($path){
6767
$path=$path.DS;
6868
}
6969
}
70-
return $path;
70+
return \realpath($path);
7171
}
7272
}

0 commit comments

Comments
 (0)