root/trunk/build/minifier.pl

Revision 4196, 1.3 kB (checked in by takayama, 3 months ago)

* Set svn keywords

  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6my $copyright;
7my $year = (localtime(time))[5] + 1900;
8
9if (($ENV{BUILD_PACKAGE} || 'MTOS') ne 'MTOS') {
10    $copyright = "Movable Type (r) (C) 2001-$year Six Apart, Ltd. All Rights Reserved";
11} else {
12    $copyright = "Movable Type (r) Open Source (C) 2001-$year Six Apart, Ltd.";
13}
14
15my %types = (
16    css => 'CSS::Minifier',
17    js => 'JavaScript::Minifier',
18);
19
20my $file = shift or die "Usage $0 <file>\n";
21die "File not found: $file\n" unless ( -e $file );
22
23my ( $ext ) = ( $file =~ m/\.(.*)$/ );
24
25unless ( defined $ext && exists( $types{ lc( $ext ) } ) ) {
26    die "$0 can only handle filetypes: ".join( ',', keys %types );
27} else {
28    $ext = lc( $ext );
29    eval( "use $types{$ext} qw( minify )" );
30    if ( $@ ) {
31        # don't die here, so it won't interrupt make
32        warn sprintf( "WARNING, %s FILES CAN'T BE MINIFIED, %s IS NOT INSTALLED, skipped\n", $ext, $types{$ext} );
33        exit 0;
34    }
35}
36
37open( INFILE, $file ) or die $!;
38my $data = join( '', <INFILE> );
39close( INFILE );
40
41open( OUTFILE, '>', $file ) or die $!;
42print OUTFILE minify(
43    input => $data,
44    copyright => qq|$copyright
45 * This file is combined from multiple sources.  Consult the source files for their
46 * respective licenses and copyrights.
47|,
48);
49close( OUTFILE );
50
51exit 0;
Note: See TracBrowser for help on using the browser.