-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmerge_fonts.php
executable file
·55 lines (48 loc) · 1.63 KB
/
merge_fonts.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
#!/usr/local/bin/php
<?php
if (count($argv) < 3) {
die("Usage: merge_fonts.php <from folder> <to json>\n");
}
error_reporting(E_ALL);
ini_set('display_errors', 1);
$fromFolder = $argv[1];
if (!file_exists($fromFolder)) {
die("Folder not found: $fromFolder\n");
}
$toFilename = $argv[2];
if (file_exists($toFilename)) {
$existing = json_decode(file_get_contents($toFilename), true);
if (!$existing) {
die("Could not parse file: $toFilename\n");
}
} else {
$existing = array();
}
if (!isset($existing['providers'])) {
$existing['providers'] = array();
}
function mergeFiles($fromFolder) {
global $existing;
global $toFilename;
foreach (new DirectoryIterator($fromFolder) as $fileInfo) {
if ($fileInfo->isDot()) continue;
if ($fileInfo->isDir()) continue;
if ($fileInfo->getExtension() != 'json') continue;
$fileName = $fileInfo->getFilename();
$contents = json_decode(file_get_contents($fileInfo->getRealPath()), true);
if (!$contents) {
echo "Could not parse: $fileName\n";
continue;
}
if (!isset($contents['providers'])) {
echo "Has no providers list: $fileName\n";
continue;
}
$existing['providers'] = array_merge($existing['providers'], $contents['providers']);
$providerCount = count($contents['providers']);
echo " Merged $providerCount providers from $fileName into $toFilename\n";
}
}
echo " Merging $fromFolder into $toFilename\n";
mergeFiles($fromFolder);
file_put_contents($toFilename, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));