Skip to content

Instantly share code, notes, and snippets.

@robCrawford
Last active October 16, 2020 12:56
Show Gist options
  • Save robCrawford/e4edf50b6b4905c8b4b9b4c5b0c5de98 to your computer and use it in GitHub Desktop.
Save robCrawford/e4edf50b6b4905c8b4b9b4c5b0c5de98 to your computer and use it in GitHub Desktop.
Copies a directory from the current package into node_modules of a parent package
cp-dep() {
# Copy directory named $1 in current package to node_modules of package named $2
# e.g. `cp-dep lib my-parent-app`
cd $(git rev-parse --show-toplevel)
package=$(node -p -e "require('./package.json').name")
dependency="$(cd .. && pwd)/$2/node_modules/$package"
to="$dependency/$1"
if [ -d $1 ] && [ -d $dependency ]; then
rm -rf $to && cp -r $1 $to
echo "Copied '$1' to '$to'"
else
echo "Not found!"
fi
cd - > /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment