forked from pantheon-systems/documentation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
watch.php
49 lines (35 loc) · 1.07 KB
/
watch.php
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
38
39
40
41
42
43
44
45
46
47
48
49
<?php
$buildScriptPath = __DIR__.'/bin/sculpin generate --env=dev';
$startPaths = [
__DIR__.'/app/config/*',
__DIR__.'/source/*',
];
$lastTime = time();
while (true) {
$files = recursiveGlob($startPaths);
foreach ($files as $file) {
$time = filemtime($file);
if ($time > $lastTime) {
$lastTime = time();
echo sprintf("%s was changed. Building...\n", $file);
echo shell_exec($buildScriptPath)."\n";
echo shell_exec("mplayer /usr/share/sounds/gnome/default/alerts/drip.ogg </dev/null >/dev/null 2>&1 &")."\n"; //Written for Fedora/Gnome. Adjust for your local setup
}
}
sleep(1);
}
function recursiveGlob(array $paths)
{
$files = [];
foreach ($paths as $path) {
$files = array_merge($files, glob($path));
foreach ($files as $file) {
if (is_dir($file)) {
$dirPath = $file.'/*';
$dirFiles = recursiveGlob([$dirPath]);
$files = array_merge($files, $dirFiles);
}
}
}
return $files;
}