#!/usr/bin/perl

use strict;
use XML::DOM;

my $index = 'index_skinned.html';
my $output = 'index.html';
my $jsOutput = 'MooseCompiled.js';

my $parse = XML::DOM::Parser->new();

open fh, $index;
open output, '>'.$output;
open js, '>'.$jsOutput;

while(<fh>) {
	my $line = $_;
	if($line =~ m/\<script/i and $line =~ m/src=/i and not($line =~ /\-\-/)) {
		my $scriptNode = $parse->parse($line);
		my $src= $scriptNode->getFirstChild()->getAttribute('src');
		if($src !~ m/Configuration\.js/i) {
			print 'Adding... '.$src;
			open jsfile, $src;
			while(<jsfile>) {
				print js $_;
			}
			close jsfile;
			print " Done.\n";
		} else {
			print output $line;
		}
	} else {
		print output $line;
	}
}

print qq(<script type="text/javascript" src="$jsOutput"></script>\n);
close js;
close output;
close fh;
