diff options
author | dakkar <dakkar@thenautilus.net> | 2025-01-15 17:26:00 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2025-01-15 17:26:00 +0000 |
commit | f2fa9e5ac3fd762738237274a9ad5f0220b7c204 (patch) | |
tree | ab1bd2913450caad875483e47c6e41bc2207084c /bin | |
parent | icon/emoji packer (diff) | |
download | misc-scripts-f2fa9e5ac3fd762738237274a9ad5f0220b7c204.tar.gz misc-scripts-f2fa9e5ac3fd762738237274a9ad5f0220b7c204.tar.bz2 misc-scripts-f2fa9e5ac3fd762738237274a9ad5f0220b7c204.zip |
better emoji packer
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/sharkey-icon-pack | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/bin/sharkey-icon-pack b/bin/sharkey-icon-pack index 8c2aec5..0425462 100755 --- a/bin/sharkey-icon-pack +++ b/bin/sharkey-icon-pack @@ -2,11 +2,14 @@ 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', 'icon category' ], + [ '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 )], @@ -18,27 +21,51 @@ if ($opt->help) { exit 0; } +if (!@ARGV) { + warn $usage->text; + exit 1; +} + +my $zip = Archive::Zip->new(); + my @emojis; -for my $file (@ARGV) { +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 => $file, + fileName => $targetname, emoji => { - name => $file =~ s/\..+$//r, + name => $filename =~ s/\..+$//r, category => $opt->category, localOnly => builtin::false, - isSensitive => builtin::false, + isSensitive => !! $opt->sensitive, }, }; } -path('meta.json')->spew_raw( +$zip->addString( JSON::MaybeXS->new( ascii => 1, pretty => 0, - )->encode({ - metaVersion => 2, - emojis => \@emojis, - }), + )->encode({ + metaVersion => 2, + emojis => \@emojis, + }), + 'meta.json', ); + +unless ($zip->writeToFileNamed($opt->output) == Archive::Zip::AZ_OK) { + die "Failed to write zip file\n"; +} |