-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
all: test | ||
|
||
.PHONY: deps | ||
deps: | ||
@echo "running dep ensure..." && \ | ||
dep ensure -v && \ | ||
$(MAKE) gxundo | ||
|
||
.PHONY: gxundo | ||
gxundo: | ||
@bash scripts/gxundo.sh vendor/ | ||
|
||
.PHONY: test | ||
test: | ||
@go test -v *.go |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
#nc="\\033[0m" | ||
red="\\033[31m" | ||
green="\\033[32m" | ||
yellow="\\033[33m" | ||
#blue="\\033[34m" | ||
#purple="\\033[35m" | ||
cyan="\\033[36m" | ||
white="\\033[37m" | ||
bold="$(tput bold)" | ||
normal="$(tput sgr0)" | ||
|
||
# function to install `jq` | ||
install_jq() { | ||
if [[ "$OSTYPE" == "linux-gnu" ]]; then | ||
if [ -n "$(command -v apt-get 2> /dev/null)" ]; then | ||
sudo apt-get -y install jq | ||
|
||
elif [ -n "$(command -v which dnf 2> /dev/null)" ]; then | ||
sudo dnf -y install jq | ||
|
||
elif [ -n "$(command -v yum 2> /dev/null)"]; then | ||
sudo yum -y install jq | ||
|
||
elif [ -n "$(command -v portage 2> /dev/null)"]; then | ||
sudo portage -y install jq | ||
|
||
elif [ -n "$(command -v pacman 2> /dev/null)"]; then | ||
sudo pacman -y install jq | ||
|
||
else | ||
echo "Cannot install jq; No supported package manager installed on system (apt-get dnf, yum, portage, pacman)" >&2 | ||
exit 1 | ||
fi | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
brew install jq | ||
fi | ||
} | ||
|
||
# check if `gorep` is installed, otherwise install it. | ||
command -v gorep >/dev/null | ||
exit_code=$? | ||
if [ "$exit_code" -ne 0 ]; then | ||
printf "$yellow%s$normal\\n" "gorep is not installed. Installing..." | ||
go get github.com/novalagung/gorep && printf "$green%s$normal\\n" "gorep installed" | ||
fi | ||
|
||
# check if `jq` is installed, otherwise install it. | ||
command -v jq >/dev/null | ||
exit_code=$? | ||
if [ "$exit_code" -ne 0 ]; then | ||
printf "$yellow%s$normal\\n" "jq is not installed. Installing..." | ||
install_jq && printf "$green%s$normal\\n" "jq installed" | ||
fi | ||
|
||
# the path to search passed an the only argument | ||
dirpath="$1" | ||
|
||
if [[ "$dirpath" == "" ]]; then | ||
printf "$red$bold%s$normal\\n" "Error: path is required" | ||
exit 1 | ||
fi | ||
|
||
printf "$yellow%s$normal\\n" "finding imports recursively under $dirpath" | ||
|
||
filter="sed -r 's|/[^/]+$||'" | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
filter="sed -E 's|/[^/]+$||'" | ||
fi | ||
|
||
# read all Go imports that contain "gx/ipfs/" | ||
for dir in $(find "$dirpath" -maxdepth 100 -type f -name '*.go' | eval "$filter" | sort -u) | ||
do | ||
for line in $(go list -json "./$dir" | jq '.Imports' | grep 'gx/ipfs/' | sed -e 's/gx\///g' | sed -e 's/"//g' | sed -e 's/,//g' | sed -e 's/ //g') | ||
do | ||
# fetch the gx package.json and read the github url | ||
root="$(echo "$line" | tr "/" "\\n" | awk 'FNR <= 3 {print}' | tr '\n' '/' | sed -e s'/.$//g')" | ||
pkg="$(echo "$line" | tr "/" "\\n" | awk 'FNR > 3 {print}' | tr '\n' '/' | sed -e s'/.$//g')" | ||
jsonurl="https://gateway.ipfs.io/$root/package.json" | ||
printf "$white%s$normal\\n" "fetching $jsonurl" | ||
new="$(curl -s "$jsonurl" | jq '.gx.dvcsimport' | sed -e 's/"//g')" | ||
if [ "$pkg" != "" ]; then | ||
new="$new/$pkg" | ||
fi | ||
old="gx/$line" | ||
|
||
printf "$cyan%s => %s$normal\\n" "$old" "$new" | ||
|
||
# replace the imports | ||
gorep -path="$dir" \ | ||
-from="$old" \ | ||
-to="$new" | ||
|
||
done | ||
done | ||
|
||
printf "$green%s$normal\\n" "complete" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.