#!/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"; }