Lines 29-58
$nproc ||= qx{nproc};
Link Here
|
29 |
|
29 |
|
30 |
my @files = @ARGV; |
30 |
my @files = @ARGV; |
31 |
|
31 |
|
32 |
pod2usage("--no-write can only be passed with a single file") if $no_write && @files > 1; |
32 |
pod2usage("--no-write can only be passed with a single file") if $no_write && @files != 1; |
33 |
|
33 |
|
34 |
pod2usage("--perl, --js and --tt can only be passed without any other files in parameter") |
34 |
pod2usage("--perl, --js and --tt can only be passed without any other files in parameter") |
35 |
if @files && ( $perl_files || $js_files || $tt_files ); |
35 |
if @files && ( $perl_files || $js_files || $tt_files ); |
36 |
|
36 |
|
37 |
push @files, get_perl_files() if $perl_files; |
37 |
my $exceptions = { |
38 |
push @files, get_js_files() if $js_files; |
38 |
pl => [qw(Koha/Schema/Result Koha/Schema.pm)], |
39 |
push @files, get_tt_files() if $tt_files; |
39 |
js => [ |
40 |
|
40 |
qw(koha-tmpl/intranet-tmpl/lib koha-tmpl/intranet-tmpl/js/Gettext.js koha-tmpl/opac-tmpl/lib Koha/ILL/Backend/) |
41 |
unless (@files) { |
41 |
], |
42 |
push @files, get_perl_files(); |
42 |
tt => [qw(Koha/ILL/Backend/ *doc-head-open.inc misc/cronjobs/rss)], |
43 |
push @files, get_js_files(); |
43 |
}; |
44 |
push @files, get_tt_files(); |
44 |
|
|
|
45 |
if (@files) { |
46 |
|
47 |
# This is inefficient if the list of files is long but most of the time we will have only one |
48 |
@files = map { |
49 |
my $file = $_; |
50 |
my $filetype = get_filetype($file); |
51 |
my $cmd = sprintf q{git ls-files %s %s}, $file, build_git_exclude($filetype); |
52 |
my $output = qx{$cmd}; |
53 |
chomp $output; |
54 |
$output ? $file : (); |
55 |
} @files; |
56 |
} else { |
57 |
push @files, get_perl_files() if $perl_files; |
58 |
push @files, get_js_files() if $js_files; |
59 |
push @files, get_tt_files() if $tt_files; |
60 |
|
61 |
unless (@files) { |
62 |
push @files, get_perl_files(); |
63 |
push @files, get_js_files(); |
64 |
push @files, get_tt_files(); |
65 |
} |
45 |
} |
66 |
} |
46 |
|
67 |
|
47 |
my @exceptions = qw( |
68 |
if ( $no_write && !@files ) { |
48 |
misc/cronjobs/rss/lastAcquired.tt |
|
|
49 |
misc/cronjobs/rss/lastAcquired-1.0.tt |
50 |
misc/cronjobs/rss/lastAcquired-2.0.tt |
51 |
misc/cronjobs/rss/longestUnseen.tt |
52 |
misc/cronjobs/rss/mostReserved.tt |
53 |
); |
54 |
|
69 |
|
55 |
@files = array_minus( @files, @exceptions ); |
70 |
# File should not be tidy, but we need to return the content or we risk data loss |
|
|
71 |
print read_file(@ARGV); |
72 |
exit; |
73 |
} |
56 |
|
74 |
|
57 |
my $nb_files = scalar @files; |
75 |
my $nb_files = scalar @files; |
58 |
my $pm = Parallel::ForkManager->new($nproc); |
76 |
my $pm = Parallel::ForkManager->new($nproc); |
Lines 93-99
sub tidy {
Link Here
|
93 |
|
111 |
|
94 |
my $filetype = get_filetype($file); |
112 |
my $filetype = get_filetype($file); |
95 |
|
113 |
|
96 |
if ( $filetype eq 'perl' ) { |
114 |
if ( $filetype eq 'pl' ) { |
97 |
return tidy_perl($file); |
115 |
return tidy_perl($file); |
98 |
} elsif ( $filetype eq 'js' ) { |
116 |
} elsif ( $filetype eq 'js' ) { |
99 |
return tidy_js($file); |
117 |
return tidy_js($file); |
Lines 104-126
sub tidy {
Link Here
|
104 |
} |
122 |
} |
105 |
} |
123 |
} |
106 |
|
124 |
|
|
|
125 |
sub build_git_exclude { |
126 |
my ($filetype) = @_; |
127 |
return join( " ", map( "':(exclude)$_'", @{ $exceptions->{$filetype} } ) ); |
128 |
} |
129 |
|
107 |
sub get_perl_files { |
130 |
sub get_perl_files { |
108 |
my @files; |
131 |
my $cmd = sprintf q{git ls-files '*.pl' '*.pm' '*.t' svc opac/svc %s}, build_git_exclude('pl'); |
109 |
push @files, qx{git ls-files '*.pl' '*.pm' '*.t' ':(exclude)Koha/Schema/Result'}; |
132 |
my @files = qx{$cmd}; |
110 |
push @files, qx{git ls-files svc opac/svc}; # Files without extension |
|
|
111 |
chomp for @files; |
133 |
chomp for @files; |
112 |
return @files; |
134 |
return @files; |
113 |
} |
135 |
} |
114 |
|
136 |
|
115 |
sub get_js_files { |
137 |
sub get_js_files { |
116 |
my @files = |
138 |
my $cmd = sprintf q{git ls-files '*.js' '*.ts' '*.vue' %s}, build_git_exclude('js'); |
117 |
qx{git ls-files '*.js' '*.ts' '*.vue' ':(exclude)koha-tmpl/intranet-tmpl/lib' ':(exclude)koha-tmpl/intranet-tmpl/js/Gettext.js' ':(exclude)koha-tmpl/opac-tmpl/lib' ':(exclude)Koha/ILL/Backend/'}; |
139 |
my @files = qx{$cmd}; |
118 |
chomp for @files; |
140 |
chomp for @files; |
119 |
return @files; |
141 |
return @files; |
120 |
} |
142 |
} |
121 |
|
143 |
|
122 |
sub get_tt_files { |
144 |
sub get_tt_files { |
123 |
my @files = qx{git ls-files '*.tt' '*.inc' ':(exclude)Koha/ILL/Backend/' ':(exclude)*doc-head-open.inc'}; |
145 |
my $cmd = sprintf q{git ls-files '*.tt' '*.inc' %s}, build_git_exclude('js'); |
|
|
146 |
my @files = qx{$cmd}; |
124 |
chomp for @files; |
147 |
chomp for @files; |
125 |
return @files; |
148 |
return @files; |
126 |
} |
149 |
} |
Lines 181-188
sub tidy_tt {
Link Here
|
181 |
|
204 |
|
182 |
sub get_filetype { |
205 |
sub get_filetype { |
183 |
my ($file) = @_; |
206 |
my ($file) = @_; |
184 |
return 'perl' if $file =~ m{^svc} || $file =~ m{^opac/svc}; |
207 |
return 'pl' if $file =~ m{^svc} || $file =~ m{^opac/svc}; |
185 |
return 'perl' if $file =~ m{\.pl$} || $file =~ m{\.pm} || $file =~ m{\.t$}; |
208 |
return 'pl' if $file =~ m{\.pl$} || $file =~ m{\.pm} || $file =~ m{\.t$}; |
186 |
|
209 |
|
187 |
return 'js' if $file =~ m{\.js$} || $file =~ m{\.ts$} || $file =~ m{\.vue$}; |
210 |
return 'js' if $file =~ m{\.js$} || $file =~ m{\.ts$} || $file =~ m{\.vue$}; |
188 |
|
211 |
|
Lines 217-222
tidy.pl [options] [files]
Link Here
|
217 |
|
240 |
|
218 |
This script will tidy the different files present in the git repository. |
241 |
This script will tidy the different files present in the git repository. |
219 |
|
242 |
|
|
|
243 |
If the file is an exception and should be tidy, it will be skipped. |
244 |
However if only one file is passed with --no-write then the content of the file will be print to STDOUT. |
245 |
|
220 |
=head1 EXAMPLES |
246 |
=head1 EXAMPLES |
221 |
|
247 |
|
222 |
Tidy everything: |
248 |
Tidy everything: |
223 |
- |
|
|