I have two repos for a web site: one for the backend, one for the frontend. I want to copy files from the frontend to the backend directory, so that everything can be served from one place.
When I run the build
command on the frontend, a folder named dist/
is created. I want to copy all these files to a folder with the relative path ../backend/public
. This public
folder may already contain some other files.
My current script uses hard-coded names for index.html
and and assets/
directory, but more files may be added over time, so I would like a generic solution that will copy everything that has not changed in dist/
to ../backend/public
.
#!/bin/bash
cd ../backend/public
rm -rf index.html assets
cp ../../frontend/dist/index.html ./
cp -r ../../frontend/dist/assets ./assets
Your script could be condensed to:
There is no reason to
cd
in the script, nor to delete existing files if you're copying things with the same name, you only need to delete directories since otherwise, if they exist, any files with a different name will be kept. If you only ever copy files with the same name, that isn't needed either.To make it more generic, you could pass the list of files/dirs you want to copy:
Which you would then run from the
frontend
directory like this: