Handling varying exclude folders for source code backup of MERN, React Native, Android and DotNet tech stacks
Quick-Info
- React Native: android, ios, node_modules, .expo, .gradle
- Android: build, release, .gradle, .idea
- DotNET: bin, obj, node_modules
- Others (MERN Stack, Java): node_modules .next .gradle .idea .cache .expo build target
Details
Tech Stack-Specific Source Code Backup Exclusions
- Exclude folders: android, ios, node_modules, .expo, .gradle
- Exclude folders: build, release, .gradle, .idea
- Exclude folders: target, build, .idea
- Exclude folders: bin, obj, node_modules
- Exclude folders: node_modules, build, .cache, .next (if Next.js)
Project folders recommended organization
- CurrProj for actively modified projects and ReadProj for reading/reference only projects.
- When project-folder in ReadProj needs modification, it should first be moved to CurrProj.
- Within ReadProj and CurrProj, organize by Tech Stack-wise folders:
- ReactNative
- Android
- Java
- DotNET
- Others
- VSCode's files.readonlyInclude user setting can configure read-only mode for all files within a folder, such as ReadProj, in the VSCode editor.
- Applying filesystem-level read-only permissions to the entire ReadProj folder might allow viewing in VSCode, but Android Studio/IDEA would most likely encounter issues.
Miscellaneous
- For efficient and precise exclusions with robocopy on Windows, organizing by tech stack allows me to leverage the /XD switch most effectively and maintain a cleaner, more reliable backup script.
- On organizing by client or my own app name folders, I may not have a single robocopy command for the entire top-level folder as the exclude folders could be different for different tech stack folders within the top-level client or my own app name folders.
- A limitation of Robocopy's /XD (exclude directories) switch is that it operates on directory names, not on relative paths or patterns within the directory structure.
- A single, free, sophisticated, and universally "well-tested" backup program specifically designed for Windows to intelligently parse .gitignore files across various tech stacks to pick up only source code for general file system backup is not a common, readily available, out-of-the-box solution.
- Microsoft’s Windows Subsystem for Linux WSL and open-source and mature rsync utility together could provide me highly granular control over exclusions, including patterns, specific relative paths (within the context of a project), and dynamic generation from .gitignore. But that brings in complexity for my use case. Given my priorities of reliability, performance with native Windows filesystems, and minimal setup/complexity, sticking with robocopy and tech-stack-based directory structure is a better solution for my use case.
- The concern with using a custom script that recursively traverses down the directory structure and identifies the tech-stack of project-folders encountered and then uses appropriate exclude folders for robocopy command for that project-folder is that backup is a critical operation. Custom scripts could have bugs resulting in some key data not being copied onto the backup. In contrast if I am depending mainly or only on robocopy and its exclude directory feature then I am using a Microsoft tested and supported program used by many, many people over many years and so is reported to be very stable and reliable.
- Windows Powershell scripts: Copy without node_modules and .next folders/directories; List node_modules and .next folders, 9 June 2024
- Windows PowerShell script and commands to list files and folders modified in past x days excluding specified folders like .git and node_modules (helps in backup), 4 May 2024
- Using robocopy to copy folder without node_modules subfolder(s) and using WinMerge and TreeSize to check, 4 March 2024
a) Path with default value being current directory (for example, Path is current directory)
b) FFNamePatternsToMove which should hold a collection (array if that is suitable) of part of names (not full name) of files or folders in Path that have to be moved. As an example: Others, ReactNative, DotNet, Android, Common
c) TargetFolder which is the folder in Path to which all the files or folders in FFNamePatternsToMove have to be moved to. As an example: CurrProj
As an example if Path has 20250810-2201-Others-XF-maxage-1.zip file, then it will match 1st entry in example FFNamePatternsToMove given above. So 20250810-2201-Others-XF-maxage-1.zip has to be moved to TargetFolder (in our example: CurrProj)
If Path does not have any files or folders whose names contain ReactNative, nothing should be done.
So in our example, confirmation prompts should be shown for:
Creation of CurrProj in current directory
Move of 20250810-2201-Others-XF-maxage-1.zip file from current directory to CurrProj folder in current directory.
---
---
is flagged as error by vscode. You need # character before 1st and 3rd lines.
MoveFFNamePatterns.ps1
script, Get-Help -Full $PSCommandPath
is used. This command tells PowerShell to retrieve the full help content for the current script.Get-Help
is a powerful tool for discovering how to use commands, and in this case, it would output the detailed documentation you wrote at the top of your script, specifically everything inside the <# ... #>
block.
Output of Get-Help -Full
When you run Get-Help -Full
on your script, PowerShell parses the special comment block and presents it in a structured format. The output will look like this:
NAME: The name of your script (
MoveFFNamePatterns.ps1
).SYNOPSIS: A brief description of what the script does.
DESCRIPTION: A more detailed explanation of the script's purpose and functionality.
PARAMETERS: A list of the script's parameters (
Path
,FFNamePatternsToMove
,TargetFolder
,Usage
), along with their descriptions and examples.EXAMPLES: The usage examples you provided, showing how to run the script with different parameters.
This feature is why writing clear, descriptive comments in the help block is so important—it makes your script user-friendly and self-documenting.
Me: Oh! So the comments you have provided are in a format that Get-Help can understand and use to show help output for the user. Did I get that right?
Gem: Yes, you've got that exactly right. The special comment block you see at the top of the script—the one enclosed by <#
and #>
—is a specific PowerShell feature called comment-based help.
PowerShell is designed to recognize this format and extract the information to create a help topic for your script. This allows you to write the documentation for your tool directly within the script itself, making it self-contained and easy for others to use with the Get-Help
cmdlet.
Comments
Post a Comment