Skip to content

Instantly share code, notes, and snippets.

@yunghoy
Last active August 17, 2016 08:13
Show Gist options
  • Save yunghoy/19a43467a977cd946b08cf92d5cd0bb1 to your computer and use it in GitHub Desktop.
Save yunghoy/19a43467a977cd946b08cf92d5cd0bb1 to your computer and use it in GitHub Desktop.
#!/bin/bash
SOURCEDIR=utils
TARGETDIR=util
pushd be > /dev/null
SERVICES="$(ls -d *-island)"
popd > /dev/null
for SERVICE in ${SERVICES}; do
pushd be/${SERVICE}/src > /dev/null
if [ -d SOURCEDIR ]; then
echo "--------------------------------------------------"
echo "Modifying the island: ${SERVICE}"
# type your command
rsync -avm --include='*.ts' -f 'hide,! */' ${SOURCEDIR}/ ${TARGETDIR}
rm -rf ${SOURCEDIR}
grep -rl "\/${SOURCEDIR}" | grep -E "\.ts$|\.js$" | grep -vE "node_modules|typings|externals" | xargs sed -i -r "s/^(import.*)(\/${SOURCEDIR})(.*)/\1\/${TARGETDIR}\3/g"
grep -rl "${SOURCEDIR}\/" | grep -E "\.ts$|\.js$" | grep -vE "node_modules|typings|externals" | xargs sed -i -r "s/^(import.*)(${SOURCEDIR}\/)(.*)/\1${TARGETDIR}\/\3/g"
grep -rl "\/${SOURCEDIR}\/" | grep -E "\.ts$|\.js$" | grep -vE "node_modules|typings|externals" | xargs sed -i -r "s/^(import.*)(\/${SOURCEDIR}\/)(.*)/\1\/${TARGETDIR}\/\3/g"
# end of your command
fi
popd > /dev/null
done
@yunghoy
Copy link
Author

yunghoy commented Aug 17, 2016

!/bin/bash

SOURCEDIR=$1
TARGETDIR=$2

echo "--------------------------------------------------"
echo "Modifying the island: ${SERVICE}"

  # type your command
  rsync -avm --include='*.ts' -f 'hide,! */' ./${SOURCEDIR}/ ./${TARGETDIR}
  rm -rf ${SOURCEDIR}

  grep -rl "\/${SOURCEDIR}" | grep -E "\.ts$|\.js$" | grep -vE "node_modules|typings|externals" | xargs sed -i -r "s/^(import.*)(\/${SOURCEDIR})(.*)/\1\/${TARGETDIR}\3/g"
  grep -rl "${SOURCEDIR}\/" | grep -E "\.ts$|\.js$" | grep -vE "node_modules|typings|externals" | xargs sed -i -r "s/^(import.*)(${SOURCEDIR}\/)(.*)/\1${TARGETDIR}\/\3/g"
  grep -rl "\/${SOURCEDIR}\/" | grep -E "\.ts$|\.js$" | grep -vE "node_modules|typings|externals" | xargs sed -i -r "s/^(import.*)(\/${SOURCEDIR}\/)(.*)/\1\/${TARGETDIR}\/\3/g"
  # end of your command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment