Created
March 27, 2017 11:01
-
-
Save oskosk/92bf5ede266a97602f4ae2e8d078159e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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