-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch
37 lines (31 loc) · 857 Bytes
/
watch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
// Format and check args
@[$_, $src, $dst, $opt] = $_SERVER['argv'];
if (!$src || !$dst)
return terminate(['Usage: php watch <source> <destination> [options]', '', 'Options:', ' d - shows defined paragraph number']);
// Check source file and load it
if (!is_file($src))
return terminate('Soruce file doesn\'t exist!');
$last_contents = null;
while (true)
{
// If file has changed, recompile
if ($last_contents != file_get_contents($src))
{
print exec("php compile $src $dst $opt") . PHP_EOL;
$last_contents = file_get_contents($src);
}
sleep(1);
}
/**
* Prints formatted exit message.
*
* @param string|string[] $message
* @return string
*/
function terminate($message)
{
if (is_array($message))
$message = implode(PHP_EOL, $message);
return print PHP_EOL . $message . PHP_EOL;
}