blob: 09058ad60381a47fb639fdc94ef02eb6c94dc111 (
plain)
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
50
51
52
53
54
55
56
57
|
#!/usr/bin/env php8.1
<?php
require __DIR__.'/../init.php';
if ($argc <= 1) {
usage();
exit(1);
}
$input_dir = null;
array_shift($argv);
while (count($argv) > 0) {
switch ($argv[0]) {
case '-i':
array_shift($argv);
$input_dir = array_shift($argv);
break;
default:
cli::die('unsupported argument: '.$argv[0]);
}
}
if (is_null($input_dir))
cli::die("input directory has not been specified");
$hashes = [];
foreach (['css', 'js'] as $type) {
$entries = glob_recursive($input_dir.'/dist-'.$type.'/*.'.$type);
if (empty($entries)) {
cli::error("warning: no files found in $input_dir/dist-$type");
continue;
}
foreach ($entries as $file)
$hashes[$type.'/'.basename($file)] = get_hash($file);
}
echo "<?php\n\n";
echo "return ".var_export($hashes, true).";\n";
function usage(): void {
global $argv;
echo <<<EOF
usage: {$argv[0]} [OPTIONS]
Options:
-i input htdocs directory
EOF;
}
function get_hash(string $path): string {
return substr(sha1(file_get_contents($path)), 0, 8);
}
|