This repository has been archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdev-util
executable file
·79 lines (65 loc) · 2.42 KB
/
dev-util
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
72
73
74
75
76
77
78
79
#!/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";
}
}
}