Fix version
[packer] / jpack
1 #! /usr/bin/perl
2
3 # Best practice
4 use strict;
5 use warnings;
6
7 # Load POSIX
8 use POSIX qw(EXIT_SUCCESS EXIT_FAILURE);
9
10 # Load CSS::Packer
11 use JavaScript::Packer;
12
13 # Init compress
14 my $compress = 'best'; #clean, shrink, obfuscate or best
15
16 #TODO: see how to handle theses options in a hash
17
18 # Init copyright
19 my $copyright = '';
20
21 # Init remove_copyright
22 my $remove_copyright = 1;
23
24 # Init no_compress_comment
25 my $no_compress_comment = 1;
26
27 # Filter options
28 @ARGV = map { if ($_ eq '-c' || $_ eq '--clean') { $compress = 'clean'; (); } elsif ($_ eq '-s' || $_ eq '--shrink') { $compress = 'shrink'; (); } elsif ($_ eq '-o' || $_ eq '--obfuscate') { $compress = 'obfuscate'; (); } elsif ($_ eq '-b' || $_ eq '--best') { $compress = 'best'; (); } else { $_; } } @ARGV;
29
30 # Show usage with invalid argument or stdin opened to a tty
31 if (scalar(@ARGV) || -t STDIN) {
32 print "Usage: $0 [-c|--clean|-s|--shrink|-o|--obfuscate|-b|--best] < input.js > output.js\n";
33 exit EXIT_FAILURE;
34 }
35
36 # Instantiate packer object
37 my $packer = JavaScript::Packer->init();
38
39 # Load input in variable
40 my $input = do { local $/; <STDIN> };
41
42 # Minify input with required compression
43 $packer->minify(\$input, { copyright => $copyright, remove_copyright => $remove_copyright, no_compress_comment => $no_compress_comment, compress => $compress });
44
45 # Show result
46 print $input;
47
48 # Exit with success
49 exit EXIT_SUCCESS;
50
51 __END__
52
53 =head1 NAME
54
55 Jpack - A simple perl JavaScript minifier
56
57 =head1 VERSION
58
59 Version 0.1
60
61 =head1 DESCRIPTION
62
63 A fast pure Perl JavaScript minifier script.
64
65 =head1 AUTHOR
66
67 Raphaël Gertz (Rapsys) << <git at rapsys.eu> >>.
68
69 =head1 COPYRIGHT & LICENSE
70
71 Copyright 2016 - 2017 Raphaël Gertz, all rights reserved.
72
73 This program is free software: you can redistribute it and/or modify
74 it under the terms of the GNU General Public License as published by
75 the Free Software Foundation, either version 3 of the License, or
76 (at your option) any later version.
77
78 This program is distributed in the hope that it will be useful,
79 but WITHOUT ANY WARRANTY; without even the implied warranty of
80 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81 GNU General Public License for more details.
82
83 You should have received a copy of the GNU General Public License
84 along with this program. If not, see <http://www.gnu.org/licenses/>.
85
86 =head1 SEE ALSO
87
88 L<JavaScript::Packer>
89
90 =cut