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
wctool. I usually usewc -l *.coffee */*.coffee etc.because it is easy to remember. However, a recursive version would bewhich runs the
find command, which recursively lists files of typef, or normal files, fed into thegrep, which filters down to just Coffeescript files, and the output of that is used as the command line arguments towc(-lsignals 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:
We find the Coffeescript files, and then
catthem. Then,sedstrips out lines that consist of only whitespace or have whitespace followed by a#. Finally, our friendwccounts the remaining lines.