Listing of jsMerge.pl


#!/usr/bin/perl -w #------------------------------------------------------------------------------ # jsMerge: combine a series of included javascript files #------------------------------------------------------------------------------ use strict; sub printFile($); my $x = "//--------------------------------------------------------------------------\n"; #------------------------------------------------------------------------------ # open the file #------------------------------------------------------------------------------ open (INPUT, $ARGV[0]) || die "Couldn't open the project file\n"; open (OUTPUT, ">" . $ARGV[1]) || die "Couldn't open the input file\n"; #------------------------------------------------------------------------------ # Loop through the file looking for lines like this # <script language="JavaScript" src="http://jangombert.com/AgeGauge/JSON.js"></script> #------------------------------------------------------------------------------ print "Processing: " . $ARGV[0] . "\n"; while (<INPUT>) { if (/<script.*src=.*script>/) { s/\"><\/script>.*//s; s/^.*\///; print OUTPUT "\n<script language=\"Javascript\">\n"; print OUTPUT $x; print OUTPUT "// included source: " . $_ . "\n"; print OUTPUT $x; printFile($_); print OUTPUT "</script>\n"; } elsif (!/^\s*\/\//) { print OUTPUT $_; } } exit(0); #------------------------------------------------------------------------------ # print single file with 4 character indent #------------------------------------------------------------------------------ sub printFile($) { my ($file) = @_; print " " . $file . "\n"; open (FILE, $file) || die "Couldn't open the included file: $file\n"; while (<FILE>) { if (!/^\s*\/\//) { print OUTPUT $_; } } close (FILE); }