Add Copyright to Code File
Recently, while working on an open-source project, I was informed just before going live that copyright attribution needed to be added to every program file. Due to time constraints, I gave up on finding an automated solution and opted for manual editing. Resolving the issue took a few minutes of manual effort.
To efficiently solve similar problems in the future, an efficient/automated method is needed. Manual editing is cumbersome and prone to errors, especially when dealing with hundreds of program files.
During the holidays, I researched the feasibility of performing this operation within the IDE and discovered a solution.
The following method uses JB company’s IDEs, such as WebStorm and IntelliJ IDEA.
Add Copyright to Multi Files
If you want to add a copyright to existing files in a project uniformly, you can follow the steps below:
Configure
Copyright
, Editor-Copyright-Copyright ProfilesConfigure
Scope
for Copyright, Editor-CopyrightIf the requirement is simple and all program files have the same Copyright, configure it as shown below:
Apply the copyright configuration to all files
- In the resource directory, select the root folder, right-click, and choose
Update Copyright...
, and the IDE will automatically add the copyright notice to all code files. - The IDE will automatically exclude files not under VCS, such as
node_modules
, and non-program files, such as JSON, will also be excluded automatically.
- In the resource directory, select the root folder, right-click, and choose
After the above operations, you will find that all program files have successfully added the copyright notice, so easy.
Copyright Update
Sometimes, the copyright information needs to be updated.
- If you only want to update modified files, you can check
Update Copyright
when submitting, and this method will automatically update the copyright information of the modified files. - If you’re going to update all files, simply select the folder in the resource directory, right-click
Update Copyright
, and you are done.
Share copyright setting
WebStorm and other IDEs do not support sharing copyright settings across projects. If needed, you have to copy the settings between projects manually.
Someone has already raised a related issue, and you can follow it if you are interested:
At the end
After understanding this method, there will be no need for manual batch editing of copyright information in the future.