-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeethoven.php
executable file
·69 lines (54 loc) · 1.5 KB
/
beethoven.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env php
<?php
DEFINE('MASTER', "composer.json");
DEFINE('JSON5', "composer.5.json");
DEFINE('NL', PHP_EOL);
$action = $argv[1];
function done($ret = 1)
{
exit($ret);
}
require_once __DIR__ . "/vendor/autoload.php";
if (! function_exists('json5_decode')) {
echo "Beethoven is missing the json5_decode() function";
done(0);
}
if (!file_exists(MASTER)) {
echo MASTER . " - not found", NL;
done(1);
}
copy(MASTER, "." . MASTER . "~");
if (!file_exists(JSON5)) {
copy(MASTER, JSON5);
echo JSON5 . " - created for humans", NL;
done(0);
}
$master = json_decode(file_get_contents(MASTER));
try {
$json = json5_decode(file_get_contents(JSON5));
} catch (JsonException $e) {
echo "Not valid json5 (". JSON5 . ")". NL;
exit(1);
}
if (json_encode($json) != json_encode($master)) {
if (filemtime(MASTER) > filemtime(JSON5)) {
echo MASTER . " is more recent than " . JSON5, NL;
echo "Automatic updating of ". MASTER. " is suspended until they match", NL;
echo "To manually update run> ${BASH_SOURCE[0]} update", NL;
done(1);
} else {
echo JSON5 . " is more recent than " . MASTER, NL;
$action = "update";
// if ($action != "update") {
// echo "Update needed: run", NL;
// echo "run> beethoven update", NL;
// done(1);
// }
}
}
if ($action == "update") {
echo "Updating...", NL;
file_put_contents(MASTER, json_encode($json, JSON_PRETTY_PRINT));
}
done(0)
?>