Is there a common way of counting source lines of code (SLOC) in a CoffeeScript project?
I'm hoping for something that will traverse all of the directories in my project during the count. I found a few projects online but they seemed kind of overkill for the task. I would love a simple utility or even just some command-line-fu.
If you're on UNIX, I would go with the wc tool. I usually use wc -l *.coffee */*.coffee etc. because it is easy to remember. However, a recursive version would be
wc -l `find <proj-dir> -type f | grep \.coffee$`
which runs the find command, which recursively lists files of type f, or normal files, fed into the grep, which filters down to just Coffeescript files, and the output of that is used as the command line arguments to wc (-l signals a line count).
Edit: Now we don't want to count blank or comment lines (we're only catching single-line comments here). We lose the per-file counts, but here goes:
cat `find <proj-dir> -type f | grep \.coffee$` | sed '/^\s*#/d;/^\s*$/d' | wc -l
We find the Coffeescript files, and then cat them. Then, sed strips out lines that consist of only whitespace or have whitespace followed by a #. Finally, our friend wc counts the remaining lines.
This will do what you want: https://github.com/blackducksw/ohcount
It correctly excludes comments and blank lines and also supports many other languages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With