Counting your lines of ActionScript

Have you ever been curious about how many lines of AS a project had? To be honest, I couldn't care less but hey, there're clients out there with pretty good reasons for it.

So, Google a little bit, first result takes me to CLOC.

In theory you should be able to restrict CLOC to a language only but most likely due to my incompetence with regular expressions I couldn't get it to work the way I liked it. So doing a little bit of command line trickery, I had to create a text file containing the path of the AS files I wanted to parse and then feed that to CLOC. This is how it looks:

[code lang="bash"]find dir -type f -iname *.as > asfiles.txt[/code]

Then send that to CLOC:

[code lang="bash"]perl cloc --list-file=asfiles.txt --quiet --report=module_report.txt --no3 --strip-comments=nc --original-dir[/code]

That would be the simpler option. But because my project is made of modules (it's a multicore PureMVC app) and the client wanted both stats per-module and global, I had to push it a little bit further. Basically create a stats file per module and then merge them together. Piece of cake:

[code lang="bash"]perl cloc --no3 --sum-reports --report_file=overall moduleReport1 moduleReport2 moduleReportN[/code]

Where "overall" is the name of the final output file (actually, 2 files are created, one per file, other per language) and "moduleReportX" files are the partial report created before for each module.

Another good thing about CLOC is that it runs in both OSX and Ubuntu at least pretty much out of the box because both come with Perl installed. However, had a little problem in Ubuntu but contacted Al Danial (the author) and he fixed it right away. If you are running Perl 5.10, go to the line 1038 of CLOC and replace "%" by "@".

Good to go!

Back to index