-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatcher.php
38 lines (30 loc) · 994 Bytes
/
watcher.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
<?php
/**
* User: heropoo
* Datetime: 2021/10/13 00:05
*/
require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Finder\Finder;
use Yosymfony\ResourceWatcher\Crc32ContentHash;
use Yosymfony\ResourceWatcher\ResourceWatcher;
use Yosymfony\ResourceWatcher\ResourceCachePhpFile;
$project = $_SERVER['argv'][1] ?? die("Usage:\n\tphp watcher.php [project]\n");
$project_path = __DIR__ . '/docs/' . $project;
if (!is_dir($project_path)) {
die("$project is not exists!");
}
$finder = new Finder();
$finder->files()
->name('*.md')
->in($project_path);
$hashContent = new Crc32ContentHash();
$resourceCache = new ResourceCachePhpFile(__DIR__ . '/tmp/watcher-cache-' . $project . '.php');
$watcher = new ResourceWatcher($resourceCache, $finder, $hashContent);
$watcher->initialize();
while (1) {
if ($watcher->findChanges()->hasChanges()) {
echo exec('php builder.php ' . $project, $output, $result_code) . PHP_EOL;
}
echo "\r>_< ";
sleep(1);
}