-
-
Save zoffixznet/6902c3fb1ccab4d73624d90b3b165734 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constant width = 80; | |
my Int $total-lines = 0; | |
my Int $total-words = 0; | |
my $excludes = set <cache css data node_modules vendor views>; | |
sub say-so($name, $lines, $words) { say sprintf('%-60.s | %5.d | %6.d', $name, $lines, $words) } | |
sub count-stuff(Str $dir) { | |
my int $subtotal-lines = 0; | |
my int $subtotal-words = 0; | |
sub doit($dir) { | |
my @dirs = $dir; | |
while @dirs { | |
for dir @dirs.shift -> $file { | |
if ($file.IO.f && $file.IO.extension eq 'js') { | |
given $file.IO.open.slurp { | |
my @lines := .lines.cache; | |
my @words := .words.cache; | |
$subtotal-lines += @lines; | |
$subtotal-words += @words; | |
say-so($file, @lines, @words); | |
} | |
} | |
elsif ($file.IO.d && $file.IO.basename ∉ $excludes ) { | |
@dirs.push: $file; | |
} | |
} | |
} | |
} | |
doit($dir); | |
say '-' x width; | |
say-so('Subtotal', $subtotal-lines, $subtotal-words); | |
say ''; | |
$total-lines += $subtotal-lines; | |
$total-words += $subtotal-words; | |
} | |
my $start = now; | |
count-stuff('/tmp/foo/js'); | |
count-stuff('/tmp/foo/js2'); | |
say '=' x width; | |
say-so('Total', $total-lines, $total-words); | |
my $stop = now; | |
say ''; | |
say "start: $start, stop: $stop, diff: {$stop-$start}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment