I've recently been building web applications with front-end frameworks like React, Reagent, and Angular 2. I was recently working on an Angualr 2 project and thought, "man, this sure seems like a ton of lines of code", but had no concrete evidence to prove it. After a quick google search I came to this stack overflow question, and the awesome answer(s) therein.
The commands in this post should be entered into any linux command shell such as the terminal app on a mac. Open it up and run this line of code to create an empty file called "derp.txt".
Then you can pass it to wc like so.
This will give you three numbers. If you just created the file with touch they should all be zeros.
The numbers are not labeled because you should be using wc so much that you have the numbers memorized and will never forget them (or just so that it's easier to pipe the output of this into other things). Just in case you've forgotten, the numbers represent newlines, words, and bytes. Interestingly, you can pass the -c flag for bytes and the -m flag for characters, but they always seem to give the same output on my machine.
In its simplest form, let's just say you want to get the total number of lines for all files in your current directory with the ".js" extension. This is simple enough, we can just use the * wildcard. This will print out the value for each of your files and a little total at the bottom.
The simple wildcard example above won't search recursively through subfolders. Indeed, this is the main question the op is asking in stack overflow example I mentioned. The top voted answer is a nice one and allows you to get the wc metrics recursively for some file type.
If I wanted to really compare Angular, React, and Reagent projects I had to be fair about it. React has only .js files for the core logic and DOM code, but Angular has .ts and .html files for the core logic and DOM code. I found this hidden gem in one of the comments of the second answer on that SO question.
I was only looking for a character count tool and found something that can give me characters, line numbers, and words! I think these three along with maybe number of files I think should give you a good measure of actually how large you project is to other similar projects. It's also interesting to compare non-similar projects to see if one may get the job done but with much less code as this may be easier to write, manage, and maintain in the long run. Anyway, that is an argument for another day. Today is the day of wc, and with it you luck may double, you see.
Your comment will be posted after it is approved.
Leave a Reply.
The posts on this site are written and maintained by Jim Lynch. About Jim...