| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::JavaScript::Minifier; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1170
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use JavaScript::Minifier::XS qw( minify ); |
|
5
|
|
|
|
|
|
|
use Dist::Zilla::File::FromCode; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Minify JavaScript in your dist. |
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::FileGatherer'; |
|
12
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::FileInjector'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use namespace::autoclean; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has finder => ( |
|
18
|
|
|
|
|
|
|
is => 'ro', |
|
19
|
|
|
|
|
|
|
isa => 'Str', |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has output_regex => ( |
|
24
|
|
|
|
|
|
|
is => 'ro', |
|
25
|
|
|
|
|
|
|
isa => 'Str', |
|
26
|
|
|
|
|
|
|
default => '/\.js$/.min.js/', |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has output => ( |
|
31
|
|
|
|
|
|
|
is => 'ro', |
|
32
|
|
|
|
|
|
|
isa => 'Str', |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub gather_files |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
|
|
|
|
|
|
my($self, $arg) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $list = sub { |
|
41
|
|
|
|
|
|
|
defined $self->finder |
|
42
|
|
|
|
|
|
|
? @{ $self->zilla->find_files($self->finder) } |
|
43
|
|
|
|
|
|
|
: grep { $_->name =~ /\.js$/ && $_->name !~ /\.min\./ } @{ $self->zilla->files }; |
|
44
|
|
|
|
|
|
|
}; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if(defined $self->output) |
|
47
|
|
|
|
|
|
|
{ |
|
48
|
|
|
|
|
|
|
my $min_file; |
|
49
|
|
|
|
|
|
|
$min_file = Dist::Zilla::File::FromCode->new({ |
|
50
|
|
|
|
|
|
|
name => $self->output, |
|
51
|
|
|
|
|
|
|
code => sub { |
|
52
|
|
|
|
|
|
|
my @list = $list->(); |
|
53
|
|
|
|
|
|
|
$self->log("compressing " . join(', ', map { $_->name } @list) . " => " . $min_file->name); |
|
54
|
|
|
|
|
|
|
minify(join("\n", map { $_->content } @list)); |
|
55
|
|
|
|
|
|
|
}, |
|
56
|
|
|
|
|
|
|
}); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->add_file($min_file); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
else |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
|
|
|
|
|
|
foreach my $file ($list->()) { |
|
63
|
|
|
|
|
|
|
my $min_file; |
|
64
|
|
|
|
|
|
|
$min_file = Dist::Zilla::File::FromCode->new({ |
|
65
|
|
|
|
|
|
|
name => do { |
|
66
|
|
|
|
|
|
|
my $min_filename = $file->name; |
|
67
|
|
|
|
|
|
|
eval q{ $min_filename =~ s} . $self->output_regex; |
|
68
|
|
|
|
|
|
|
$min_filename; |
|
69
|
|
|
|
|
|
|
}, |
|
70
|
|
|
|
|
|
|
code => sub { |
|
71
|
|
|
|
|
|
|
$self->log("compressing " . $file->name . " => " . $min_file->name); |
|
72
|
|
|
|
|
|
|
minify($file->content); |
|
73
|
|
|
|
|
|
|
}, |
|
74
|
|
|
|
|
|
|
}); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$self->add_file($min_file); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=encoding UTF-8 |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Dist::Zilla::Plugin::JavaScript::Minifier - Minify JavaScript in your dist. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 VERSION |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
version 0.02 |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
[JavaScript::Minifier] |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Compress JavaScript files in your distribution using L<JavaScript::Minifier::XS>. By default for |
|
106
|
|
|
|
|
|
|
each C<foo.js> file in your distribution this plugin will create a C<foo.min.js> |
|
107
|
|
|
|
|
|
|
which has been compressed. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 finder |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Specifies a L<FileFinder|Dist::Zilla::Role::FileFinder> for the JavaScript files that |
|
114
|
|
|
|
|
|
|
you want compressed. If this is not specified, it will compress all the JavaScript |
|
115
|
|
|
|
|
|
|
files that do not have a C<.min.> in their filenames. Roughly equivalent to |
|
116
|
|
|
|
|
|
|
this: |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
[FileFinder::ByName / JavaScriptFiles] |
|
119
|
|
|
|
|
|
|
file = *.js |
|
120
|
|
|
|
|
|
|
skip = .min. |
|
121
|
|
|
|
|
|
|
[JavaScript::Minifier] |
|
122
|
|
|
|
|
|
|
finder = JavaScriptFiles |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 output_regex |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Regular expression substitution used to generate the output filenames. By default |
|
127
|
|
|
|
|
|
|
this is |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
[JavaScript::Minifier] |
|
130
|
|
|
|
|
|
|
output_regex = /\.js$/.min.js/ |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
which generates a C<foo.min.js> for each C<foo.js>. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 output |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Output filename. Not used by default, but if specified, all JavaScript files are merged and |
|
137
|
|
|
|
|
|
|
compressed into a single file using this as the output filename. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 METHODS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 $plugin-E<gt>gather_files( $arg ) |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This method adds the compressed JavaScript files to your distribution. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Graham Ollis <plicease@cpan.org> |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Graham Ollis. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
154
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |