summaryrefslogtreecommitdiff
path: root/vendor/mervick/material-design-icons/scripts/updatedemo.php
blob: bc7411467489c1bec23cf69537bf563c04a24a06 (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
58
59
60
61
<?php

$path = __DIR__ . '/../bower_components/material-design-icons';
$out = __DIR__ . '/../demo/js/data.js';
$codepoints = __DIR__ . '/../bower_components/material-design-icons/iconfont/codepoints';
$oldcodepoints = __DIR__ . '/../fonts/codepoints';

$start_js = 'window.data = ';
$end_js = ';';

//$categories = file_get_contents($out);
//$categories = substr(substr($categories, strlen($start_js)), 0, - strlen($end_js));
//$categories = json_decode($categories, true);
//$categories = $categories ?: [];

$categories = $icons = $old_icons = [];
$count = $count_cats = 0;

foreach (file($codepoints, FILE_IGNORE_NEW_LINES) as $code) {
    $code = explode(' ', $code, 2);
    $icons[$code[0]] = $code[1];
}
foreach (file($oldcodepoints, FILE_IGNORE_NEW_LINES) as $code) {
    $code = explode(' ', $code, 2);
    $old_icons[$code[0]] = $code[1];
}

foreach (array_diff(scandir($path), ['.', '..'])  as $category) {
    if (is_dir("$path/$category/svg/production")) {
        $count_cats ++;
        $categories[$category] = [];
        foreach (array_diff(scandir("$path/$category/svg/production"), ['.', '..']) as $file) {
            if (preg_match('/^ic_(.+?)_\d+px\.svg$/', $file, $match)) {
                $icon = $match[1];
                if (isset($icons[$icon])) {
                    if (!in_array($icons[$icon], $categories[$category])) {
                        $categories[$category][$icon] = $icons[$icon];
                        $count ++;
                    }
                }
            }
        }
    }
}

$new = 0;

foreach ($categories as &$category) {
    foreach ($category as $icon => &$code) {
        $c = $code;
        $code = [$c, !isset($old_icons[$icon])];
        if (!isset($old_icons[$icon])) {
            $new ++;
        }
    }
}


file_put_contents($out, $start_js . json_encode($categories) . $end_js);

echo "Found $count icons, ($new new) in $count_cats categories\n";