dev-util 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/perl
  2. use local::lib;
  3. use v5.10;
  4. use strict;
  5. use warnings;
  6. use File::Find qw( find );
  7. use FindBin qw( $RealBin );
  8. use Mojo::File qw( path );
  9. use Mojo::UserAgent ();
  10. use Mojo::Util qw( trim );
  11. use YAML::Tiny ();
  12. $| = 1;
  13. my ($command, @args) = (lc(shift // ''), @ARGV);
  14. $command || die <<'EOF';
  15. syntax: dev-util <command> [command args]
  16. commands:
  17. svg-import <path> update svg source from font-awesome
  18. perl-upgrades reports on newer versions of perl modules
  19. EOF
  20. if ($command eq 'svg-import') {
  21. my ($source_path) = @args;
  22. my $svg_path = $RealBin . '/web/svg';
  23. my $fa_path = $svg_path . '/font-awesome';
  24. my $templates_path = "$RealBin/web/templates";
  25. # update svg icons from font-awesome pro
  26. $source_path =~ s{/$}{};
  27. foreach my $dir (qw( svgs advanced-options/raw-svg )) {
  28. if (-d "$source_path/$dir") {
  29. $source_path .= "/$dir";
  30. last;
  31. }
  32. }
  33. die "failed to find font-awesome pro icons\n" unless -d "$source_path/solid";
  34. my $mapping = YAML::Tiny->read("$fa_path/mapping.yaml")->[0];
  35. foreach my $output_name (sort keys %{$mapping}) {
  36. my $input_file = "$source_path/" . $mapping->{$output_name} . '.svg';
  37. my $output_file = "$fa_path/$output_name.svg";
  38. my $input = path($input_file)->slurp;
  39. $input =~ s/<!--.*-->//sg;
  40. $input = trim($input);
  41. my $output = -e $output_file ? path($output_file)->slurp : '';
  42. if ($input eq $output) {
  43. say "inline-svg: $output_name unchanged";
  44. } else {
  45. path($output_file)->spurt($input);
  46. say "inline-svg: $output_name \e[34mupdated\e[0m";
  47. }
  48. }
  49. } elsif ($command eq 'perl-upgrades') {
  50. my $ua = Mojo::UserAgent->new();
  51. foreach my $line (split(/\n/, path('cpanfile')->slurp)) {
  52. next unless $line =~ /^\s*requires '([^']+)', '==([^']+)';/;
  53. my ($module, $installed_version) = ($1, $2);
  54. print "$module $installed_version: ";
  55. my $res = $ua->get("http://cpanmetadb.plackperl.org/v1.0/package/$module")->result;
  56. die $res->message unless $res->is_success;
  57. my $cpan = YAML::Tiny->read_string($res->body)->[0];
  58. if ($cpan->{version} eq $installed_version) {
  59. say 'ok';
  60. } else {
  61. (my $dist = $module) =~ s/::/-/g;
  62. say "\e[34m", $cpan->{version}, "\e[0m - https://metacpan.org/changes/distribution/$dist";
  63. }
  64. }
  65. }