Add Copyright or License text to the Source Files Recursively

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human
Search for a command to run...

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human
No comments yet. Be the first to comment.
Traditional SSR is great, but it has a massive buffering problem. Let's look into the SSR Streaming and learn how it could be a game changer.

Learn how to build maintainable, reusable forms in React using design patterns like custom hooks, compound components, and context for scalable CRUD

Learn how JavaScript variables work, including let vs const, primitive and reference types, pass by value, and how JavaScript stores data in memory.

A beginner-friendly introduction to JavaScript covering what it is, how it works, and how to set up your JavaScript environment

Learn how the promises are handled internally using event loop. This concept is essentials to debug and work with async programming.

GreenRoots Blog - A Blog by Tapas Adhikary
186 posts
Educator | YouTuber | Building ReactPlay | Let's Connect
Recently I was assigned to the task of adding a Copyright text block to all the JavaScript Source Code files. Initially, the task was assumed to be an easy one as I thought of using any related VSCode Extensions to achieve it. However it was proved to be hectic when I found, I have to do it for 250 odd files 😲!
What next? Of course, the natural instinct was to, search on the web for a tool that does it. I just did that. I found many responses, especially a few great directions from StackOverFlow. So, I thought it would be better to put the working solution in a public GitHub repo so that, others can use it using a good documentation.
The tool add-copyright is able to meet all the requirements mentioned above with a few limitations that we will see at the end.
You can clone the repo and use it from here:
The main files of the tool are followings,
copyright.txt: An input file where you keep the text block(Copyright/License text) to apply on your Source Code.addcopyright.sh: The Script file which is responsible for adding the text block to the target Source Code.find <SOURCE_CODE_DIRECTIRY> -type d -name "<EXCLUDE_DIRECTORY>" -prune -o -name "*.js" -print0 | xargs -0 ./addcopyright.sh
Where the <SOURCE_CODE_DIRECTIRY> is the path of your source code. Where the <EXCLUDE_DIRECTORY> is the directory to exclude if it exists under for updating the Copyright information.
For example, running the tool on the JsvaScript Source Code under the folder /opt/atapas/code by excluding the folder node_modules, use this command,
find /opt/atapas/code -type d -name "node_modules" -prune -o -name "*.js" -print0 | xargs -0 ./addcopyright.sh
You can ignore multiple folders in a single command and can use them on different types of Source Code files. Please go through the Readme documentation for more details.
Here is the output of running the command,

Few Limitations included:
This tool can be made use for different language files like javascript, java, c, c++, HTML, shell-script etc. However the content of the copyright.txt should be changed according to the multi-line comment format. For example,
/*
This is a comment
*/
<!--
This is a HTML Comment
-->
I hope the tool will be useful to many of you as it was to me. Please like/share(👍) this post and give a star(⭐) to my project in GitHub. If you are willing to contribute to it in any form, you are most welcome!
There could be various other ways(maybe a better one too) to achieve the same goal. Please feel free to share in the comment section.