summaryrefslogtreecommitdiff
path: root/bin/sharkey-icon-pack
blob: 0425462dc2786410460cd859bf597ce8bfa8070f (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
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env perl 
use v5.40;
use Path::Tiny;
use JSON::MaybeXS;
use Archive::Zip;
use Getopt::Long::Descriptive;
 
my ($opt,$usage) = describe_options(
    "%c %o [ file ... ]\n",
    'category=s''emojy category' ],
    'sensitive''mark emojis as sensitive' ],
    'output=s''zip file to write', { default => '/tmp/custom-emoji.zip' } ],
    'help|h''print usage message and exit', { shortcircuit => 1 } ],
    {
        getopt_conf => [qw( posix_default no_ignore_case )],
        show_defaults => 1,
    },
);
if ($opt->help) {
    print $usage->text;
    exit 0;
}
 
if (!@ARGV) {
    warn $usage->text;
    exit 1;
}
 
my $zip = Archive::Zip->new();
 
my @emojis;
 
for my $filename (@ARGV) {
    my $targetname = path($filename)->basename;
    $targetname =~ s/[^\w.]+/_/g;
    if ($targetname !~ /^\w/) {
        $targetname = "0$targetname";
    }
 
    $zip->addFile({
        filename => $filename,
        zipName => $targetname,
        compressionLevel => 0,
    });
 
    push @emojis, {
        downloaded => builtin::true,
        fileName => $targetname,
        emoji => {
            name => $filename =~ s/\..+$//r,
            category => $opt->category,
            localOnly => builtin::false,
            isSensitive => !! $opt->sensitive,
        },
    };
}
 
$zip->addString(
    JSON::MaybeXS->new(
        ascii => 1,
        pretty => 0,
    )->encode({
        metaVersion => 2,
        emojis => \@emojis,
    }),
    'meta.json',
);
 
unless ($zip->writeToFileNamed($opt->output) == Archive::Zip::AZ_OK) {
    die "Failed to write zip file\n";
}