12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #!/usr/bin/perl
- use local::lib;
- use v5.10;
- use strict;
- use warnings;
- use File::Find qw( find );
- use FindBin qw( $RealBin );
- use Mojo::File qw( path );
- use Mojo::UserAgent ();
- use Mojo::Util qw( trim );
- use YAML::Tiny ();
- $| = 1;
- my ($command, @args) = (lc(shift // ''), @ARGV);
- $command || die <<'EOF';
- syntax: dev-util <command> [command args]
- commands:
- svg-import <path> update svg source from font-awesome
- perl-upgrades reports on newer versions of perl modules
- EOF
- if ($command eq 'svg-import') {
- my ($source_path) = @args;
- my $svg_path = $RealBin . '/web/svg';
- my $fa_path = $svg_path . '/font-awesome';
- my $templates_path = "$RealBin/web/templates";
- # update svg icons from font-awesome pro
- $source_path =~ s{/$}{};
- foreach my $dir (qw( svgs advanced-options/raw-svg )) {
- if (-d "$source_path/$dir") {
- $source_path .= "/$dir";
- last;
- }
- }
- die "failed to find font-awesome pro icons\n" unless -d "$source_path/solid";
- my $mapping = YAML::Tiny->read("$fa_path/mapping.yaml")->[0];
- foreach my $output_name (sort keys %{$mapping}) {
- my $input_file = "$source_path/" . $mapping->{$output_name} . '.svg';
- my $output_file = "$fa_path/$output_name.svg";
- my $input = path($input_file)->slurp;
- $input =~ s/<!--.*-->//sg;
- $input = trim($input);
- my $output = -e $output_file ? path($output_file)->slurp : '';
- if ($input eq $output) {
- say "inline-svg: $output_name unchanged";
- } else {
- path($output_file)->spurt($input);
- say "inline-svg: $output_name \e[34mupdated\e[0m";
- }
- }
- } elsif ($command eq 'perl-upgrades') {
- my $ua = Mojo::UserAgent->new();
- foreach my $line (split(/\n/, path('cpanfile')->slurp)) {
- next unless $line =~ /^\s*requires '([^']+)', '==([^']+)';/;
- my ($module, $installed_version) = ($1, $2);
- print "$module $installed_version: ";
- my $res = $ua->get("http://cpanmetadb.plackperl.org/v1.0/package/$module")->result;
- die $res->message unless $res->is_success;
- my $cpan = YAML::Tiny->read_string($res->body)->[0];
- if ($cpan->{version} eq $installed_version) {
- say 'ok';
- } else {
- (my $dist = $module) =~ s/::/-/g;
- say "\e[34m", $cpan->{version}, "\e[0m - https://metacpan.org/changes/distribution/$dist";
- }
- }
- }
|