Instead of making a complex re-usable structure, sometimes cloning an existing feature is more wise decision. Lets see how we can we that.
Existing feature
Say, the CcrApproval feature has a file structure something like this-
/ccrApproval
CcrApprovalContract.kt
CcrApprovalScreen.kt
CcrApprovalViewModel.kt
/model
CcrApproval.kt
CcrApprovalResponse.kt
Now, a new feature RxApproval is to be implemented. We can do the following step to create new feature from existing one.
Steps
Copy entire /ccrApproval folder and paste it (rename the package as rxApproval)
Change all file names prefix from CcrApproval~ to RxApproval~
Replace all occurrence of CcrApproval to RxApproval
Replace all occurrence of ccrApproval to rxApproval
File name change
find . -name '*CcrApproval*.kt' -exec sh -c '
for file do
mv -- "$file" "${file/CcrApproval/RxApproval}"
done
' sh {} +
Note:
- This command will find all files (-type f) in the current directory and its subdirectories. For each of these files, it will execute the sed command to replace 'CcrApproval' with 'RxApproval' in their contents.
Content Change
CcrApproval > RxApproval
find . -type f -exec sed -i '' 's/CcrApproval/RxApproval/g' {} \;
Note:
- the g at the end of the s/CcrApproval/RxApproval/g command tells sed to replace all occurrences of 'CcrApproval' in each file, not just the first occurrence in each line. If you only want to replace the first occurrence in each line, you can remove the g.
ccrApproval > rxApproval
find . -type f -exec sed -i '' 's/ccrApproval/rxApproval/g' {} \;
New feature
After performing all 4 steps, now we have our brand new cloned feature
/RxApprovalContract.kt
RxApprovalScreen.kt
RxApprovalViewModel.kt
/model
RxApproval.kt
RxApprovalResponse.kt
Conclusion
Pay attention to your package declaration. Don't use IDE's feature to rename the package. It may corrupt your existing feature & references.