File: JSBeautifier.pm

package info (click to toggle)
libjavascript-beautifier-perl 0.25-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 204 kB
  • sloc: perl: 1,004; makefile: 7
file content (76 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download | duplicates (3)
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
package Code::TidyAll::Plugin::JSBeautifier;

use File::Slurp::Tiny qw(write_file);
use IPC::Run3 qw(run3);
use Moo;
use Try::Tiny;
extends 'Code::TidyAll::Plugin';

our $VERSION = '0.21';

sub _build_cmd {'js_beautify'}

sub transform_file {
    my ( $self, $file ) = @_;

    try {
        my $cmd = join( " ", $self->cmd, '-o', $self->argv, $file );

        my $output;
        run3( $cmd, \undef, \$output, \$output );
        #write_file( $file, $output );
    }
    catch {
        die sprintf(
            "%s exited with error - possibly bad arg list '%s'\n    $_", $self->cmd,
            $self->argv
        );
    };
}

1;

# ABSTRACT: Use JavaScript::Beautifier with tidyall

__END__

=pod

=head1 NAME

Code::TidyAll::Plugin::JSBeautifier - Use JavaScript::Beautifier with tidyall

=head1 SYNOPSIS

This module requires L<Code::TidyAll>.

   In the .tidyallrc configuration file add:

   [JSBeautifier]
   select = static/**/*.js

Then run

   tidyall -a

=head1 DESCRIPTION

Runs C<js_beautify> of L<JavaScript::Beautifier>, a JavaScript tidier implemented in Perl.

=head1 INSTALLATION

    cpanm Code::TidyAll

=head1 CONFIGURATION

=over

=item argv

Arguments to pass to js_beautify

=item cmd

Full path to js_beautify

=back