DEV Community

Cover image for Copy paste source files to destination with singular and plural replace text in file contents and file paths
ILshat Khamitov
ILshat Khamitov

Posted on

Copy paste source files to destination with singular and plural replace text in file contents and file paths

I often have to copy a large number of files and folders with the base code and replace various lines inside the files, as well as in the names of files and folders, and this takes a lot of time 😒.

To solve this problem, I wrote a utility that can do it for me 😎.

Links

https://www.npmjs.com/package/rucken - npm package

https://github.com/rucken/rucken/blob/develop/libs/rucken/src/lib/copy-paste/copy-paste.service.ts - source code

https://www.npmjs.com/package/case-anything - main library used

Example of usage

1) Create folder cat-dog

mkdir cat-dog
Enter fullscreen mode Exit fullscreen mode

2) Create txt file cat-dog/cat_dog.txt

echo "catDog
CatDog
cat-dog
cat_dog
CAT_DOG
Cat-Dog
Cat_Dog
CAT-DOG
cat Dog
Cat Dog
cat dog
CAT DOG
catDogs
CatDogs
cat-dogs
cat_dogs
CAT_DOGS
Cat-Dogs
Cat_Dogs
CAT-DOGS
cat Dogs
Cat Dogs
cat dogs
CAT DOGS" > cat-dog/cat_dog.txt
Enter fullscreen mode Exit fullscreen mode

3) Run the utility

npx rucken copy-paste --find=cat-dog --replace=human-ufo --path=./cat-dog
Enter fullscreen mode Exit fullscreen mode

4) Check new file

echo ./human-ufo/human_ufo.txt
Enter fullscreen mode Exit fullscreen mode

Result

humanUfo
HumanUfo
human-ufo
human_ufo
HUMAN_UFO
Human-Ufo
Human_Ufo
HUMAN-UFO
human Ufo
Human Ufo
human ufo
HUMAN UFO
humanUfos
HumanUfos
human-ufos
human_ufos
HUMAN_UFOS
Human-Ufos
Human_Ufos
HUMAN-UFOS
human Ufos
Human Ufos
human ufos
HUMAN UFOS

Enter fullscreen mode Exit fullscreen mode

If you can’t run it through npx, then you need to install the utility globally

Install

npm i -g rucken
Enter fullscreen mode Exit fullscreen mode

Usage

rucken copy-paste --find=cat-dog --replace=human-ufo --path=./cat-dog
Enter fullscreen mode Exit fullscreen mode

I hope this utility will help developers save time πŸ˜‰

Top comments (0)