User:Lupin/jscat

These simple scripts join javascript files together and split them up. I use them for popups.js.

jscat

 * 1) !/bin/bash


 * 1) usage:
 * 2) jscat *.js	   cat js files for later uncatting
 * 3) jscat -l *.js	   cat js files, stripping out NOLITE chunks

if [ "$1" == "-l" ]; then striplite=1 shift fi

function docat { if [ "$striplite" == "1" ]; then out=$(sed -e '/^\/\/ *$/,/^\/\/<\/NOLITE> *$/d' "$1") else out=$(cat "$1") fi   echo "$out" t=$(echo "$out" | tail -1); if [ -n "$t" ]; then echo fi }

for i in "$@"; do    out=$(docat "$i") if [ $(echo "$out" | grep -c '[^[:space:]]') -eq '0' ]; then echo Empty "$i" >&2; continue; fi   echo // STARTFILE: "$i" echo "$out"; echo // ENDFILE: "$i" done

jsuncat

 * 1) !/usr/bin/env perl


 * 1) usage: jsuncat < popupsdev.js

my $file=''; while (<>) { if ( m/^\/\/ STARTFILE: (.*)$/ ) { $file=$1; die "File $file exists; aborting." if -e "$file"; print "Starting $file..."; open(FILE, ">$file"); } elsif ( m/^\/\/ ENDFILE: $file/ ) { close(FILE); print "done.\n"; $file=''; } else { print FILE if "$file" =~ /./; } }

if ( "$file" =~ /./ ) { warn "\nWARNING: unclosed file $file\n"; close(FILE); }