forked from craftcms/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyicons.php
More file actions
114 lines (96 loc) · 2.6 KB
/
Copy pathcopyicons.php
File metadata and controls
114 lines (96 loc) · 2.6 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
use craft\helpers\Search;
require dirname(__DIR__) . '/vendor/autoload.php';
$app = require(dirname(__DIR__) . '/bootstrap/console.php');
$lightIcons = [
'earth-africa',
'earth-americas',
'earth-asia',
'earth-europe',
'earth-oceania',
'envelope',
'files',
'folder-open',
'globe',
'image',
'map-location',
'newspaper',
'pen-to-square',
'plug',
'signs-post',
'sitemap',
'sliders',
'tags',
'user-group',
];
$styles = [
'globe' => 'regular',
'grip-dots' => 'custom',
];
$kitDir = dirname(__DIR__) . '/node_modules/@awesome.me/kit-ddaed3f5c5';
$kitSvgsDir = "$kitDir/icons/svgs";
$iconsDir = dirname(__DIR__) . '/src/icons';
$metaPath = "$kitDir/icons/metadata/icons.json";
$meta = json_decode(file_get_contents($metaPath), true);
$index = [];
$aliasesPhp = <<<PHP
<?php
PHP;
$skipped = 0;
$wrote = 0;
foreach ($lightIcons as $name) {
$iconPath = "$iconsDir/light/$name.svg";
echo "Writing light/$name.svg ... ";
file_put_contents($iconPath, $meta[$name]['svg']['light']['raw']);
echo "done\n";
$wrote++;
}
foreach ($meta as $name => $info) {
if (isset($info['svg']['custom'])) {
$style = 'custom';
} elseif (isset($info['svg']['brands'])) {
$style = 'brands';
} else {
$style = $styles[$name] ?? 'solid';
}
$dir = match ($style) {
'custom' => 'custom-icons',
default => $style,
};
$iconPath = "$iconsDir/$dir/$name.svg";
echo "Writing $dir/$name.svg ... ";
file_put_contents($iconPath, $info['svg'][$style]['raw']);
echo "done\n";
$wrote++;
if ($style !== 'custom') {
$terms = $meta[$name]['search']['terms'] ?? [];
$index[$name] = [
'name' => sprintf(" %s ", Search::normalizeKeywords($name)),
'terms' => sprintf(" %s ", Search::normalizeKeywords($terms)),
'pro' => empty($meta[$name]['free']),
'styles' => $meta[$name]['styles'] ?? [],
];
}
if ($style !== 'solid') {
$aliasesPhp .= <<<PHP
Craft::setAlias('@appicons/$name.svg', "@craft/icons/$dir/$name.svg");
PHP;
}
}
echo "Finished writing $wrote icons ($skipped skipped).\n";
echo 'Copying LICENSE.txt ... ';
copy("$kitDir/LICENSE.txt", "$iconsDir/LICENSE.txt");
echo "done\n";
echo 'Writing index ... ';
ksort($index);
$indexPath = "$iconsDir/index.php";
$arr = var_export($index, true);
$indexContents = <<<PHP
<?php
return $arr;
PHP;
file_put_contents($indexPath, $indexContents);
echo "done\n";
echo 'Writing aliases ... ';
file_put_contents("$iconsDir/aliases.php", $aliasesPhp);
echo "done\n";