Add javascript indenter

This commit is contained in:
Xavier Guimard 2013-10-30 19:44:09 +00:00
parent 1487e055a7
commit be919274c2
2 changed files with 22 additions and 0 deletions

View File

@ -686,3 +686,6 @@ tidy: clean
find lemon*/ -type f \( -name '*.pm' -or -name '*.pl' -or -name '*.t' \) -print -exec perltidy -b {} \;
find lemon*/ -name '*.bak' -delete
tidy-js: clean
find lemon*/ -type f -name '*.js' ! -name 'jq*' -print -exec scripts/javascript-indent {} \;

19
scripts/javascript-indent Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/perl -w
use JavaScript::Beautifier qw/js_beautify/;
unless ( $ARGV[0] and -e $ARGV[0] ) {
die "Usage $0 <file.js>";
}
open F, $ARGV[0] or die($!);
my $src;
while (<F>) { $src .= $_; }
close F;
open F, ">",$ARGV[0] or die($!);
print F js_beautify( $src, {
indent_size => 1, indent_character => "\t", preserve_newlines => 1 }
);