Skip to content

Instantly share code, notes, and snippets.

@oskosk
Created March 27, 2017 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskosk/92bf5ede266a97602f4ae2e8d078159e to your computer and use it in GitHub Desktop.
Save oskosk/92bf5ede266a97602f4ae2e8d078159e to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "$1" ]
then
echo "Please provide a filename/dirname from calypso as first parameter"
exit
fi
if [ -z "$2" ]
then
echo "Please provide a destination directory"
exit
fi
if [ ! -e "$2" ]
then
echo "Please provide a valid and existing destination directory"
exit
fi
component=$1
destination=$2
tmpdir=`mktemp -d`
echo "Cloning the 'master' branch from Calypso's repository into temporary dir $tmpdir"
echo
git clone -q -b master --depth 1 https://github.com/Automattic/wp-calypso $tmpdir
sourcecomponent=$tmpdir/$component
if [ ! -e $sourcecomponent ]
then
echo $tmpdir/$component
echo "Requested component does not exist in repository"
exit
fi
finalcomponent=`basename $component`
final=$destination/$finalcomponent
hasimports() {
grepit $1 >/dev/null
}
grepit() {
grep 'import\|require' -r $1 | grep -o -e "'.*'" |sort|uniq
}
cp -a $sourcecomponent $destination && hasimports $final &&
echo "Component declares these imports/requires:" &&
echo " Probably you'll need to npm install them for the component to work." &&
echo &&
grepit $final
echo "Component succesfully cannibalized in $final"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment