From a68940c6cc7a17a4fae1fcf4864365b028aea651 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Mon, 2 Jan 2017 16:14:45 +0100 Subject: [PATCH] Add cpack and jpack scripts --- cpack | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ jpack | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100755 cpack create mode 100755 jpack diff --git a/cpack b/cpack new file mode 100755 index 0000000..443f2d9 --- /dev/null +++ b/cpack @@ -0,0 +1,79 @@ +#! /usr/bin/perl + +# Best practice +use strict; +use warnings; + +# Load POSIX +use POSIX qw(EXIT_SUCCESS EXIT_FAILURE); + +# Load CSS::Packer +use CSS::Packer; + +# Init compress +my $compress = 'pretty'; + +# Filter options +@ARGV = map { if ($_ eq '-p' || $_ eq '--pretty') { $compress = 'pretty'; (); } elsif ($_ eq '-m' || $_ eq '--minify') { $compress = 'minify'; (); } else { $_; } } @ARGV; + +# Show usage with invalid argument or stdin opened to a tty +if (scalar(@ARGV) || -t STDIN) { + print "Usage: $0 [-p|--pretty|-m|--minify] < input.css > output.css\n"; + exit EXIT_FAILURE; +} + +# Instantiate packer object +my $packer = CSS::Packer->init(); + +# Load input in variable +my $input = do { local $/; }; + +# Minify input with required compression +$packer->minify(\$input, compress => $compress); + +# Show result +print $input; + +# Exit with success +exit EXIT_SUCCESS; + +__END__ + +=head1 NAME + +Cpack - A simple perl CSS minifier + +=head1 VERSION + +Version 0.01 + +=head1 DESCRIPTION + +A fast pure Perl CSS minifier script. + +=head1 AUTHOR + +Raphaël Gertz (Rapsys) << >>. + +=head1 COPYRIGHT & LICENSE + +Copyright 2016 - 2017 Raphaël Gertz, all rights reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +=head1 SEE ALSO + +L + +=cut diff --git a/jpack b/jpack new file mode 100755 index 0000000..8434435 --- /dev/null +++ b/jpack @@ -0,0 +1,90 @@ +#! /usr/bin/perl + +# Best practice +use strict; +use warnings; + +# Load POSIX +use POSIX qw(EXIT_SUCCESS EXIT_FAILURE); + +# Load CSS::Packer +use JavaScript::Packer; + +# Init compress +my $compress = 'best'; #clean, shrink, obfuscate or best + +#TODO: see how to handle theses options in a hash + +# Init copyright +my $copyright = ''; + +# Init remove_copyright +my $remove_copyright = 1; + +# Init no_compress_comment +my $no_compress_comment = 1; + +# Filter options +@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; + +# Show usage with invalid argument or stdin opened to a tty +if (scalar(@ARGV) || -t STDIN) { + print "Usage: $0 [-c|--clean|-s|--shrink|-o|--obfuscate|-b|--best] < input.js > output.js\n"; + exit EXIT_FAILURE; +} + +# Instantiate packer object +my $packer = JavaScript::Packer->init(); + +# Load input in variable +my $input = do { local $/; }; + +# Minify input with required compression +$packer->minify(\$input, { copyright => $copyright, remove_copyright => $remove_copyright, no_compress_comment => $no_compress_comment, compress => $compress }); + +# Show result +print $input; + +# Exit with success +exit EXIT_SUCCESS; + +__END__ + +=head1 NAME + +Jpack - A simple perl JavaScript minifier + +=head1 VERSION + +Version 0.01 + +=head1 DESCRIPTION + +A fast pure Perl JavaScript minifier script. + +=head1 AUTHOR + +Raphaël Gertz (Rapsys) << >>. + +=head1 COPYRIGHT & LICENSE + +Copyright 2016 - 2017 Raphaël Gertz, all rights reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +=head1 SEE ALSO + +L + +=cut -- 2.41.0