diff --git a/make/scripts/flatten.sh b/make/scripts/flatten.sh new file mode 100755 index 0000000000..aa2a630fbe --- /dev/null +++ b/make/scripts/flatten.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# This script flattens Solidity contracts and saves them in ./flattened +# The existing content of ./flattened is removed +# This tool takes both globs and filenames as the list of arguments and flattens everything +# Usage: ./script/sh/flatten.sh contracts/**.sol contracts/client/TestClient.sol <...> + +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# Check if arguments were supplied +if [ $# -eq 0 ]; then + echo -e "${RED}Error: provide globs/filenames of the contracts to flatten!${NC}" + exit 1 +fi + +# First, we remove the existing flattened files +rm -rf ./flattened + +# Track the amount of flattened files for the final report +count=0 +# Then, we iterate over the supplied arguments +# If any argument was a glob, this will iterate over the files it specifies +for var in "$@"; do + # Strip contract name "Abc.sol" from the path + fn=$(basename "$var") + # Flatten the file and save it in ./flattened + # Make sure that flattened contracts base names are unique! + forge flatten "$var" -o "./flattened/$fn" + ((++count)) +done + +echo -e "${GREEN}Files flattened: $count${NC}" diff --git a/packages/contracts-communication/flatten.sh b/packages/contracts-communication/flatten.sh deleted file mode 100755 index aa2a630fbe..0000000000 --- a/packages/contracts-communication/flatten.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -# This script flattens Solidity contracts and saves them in ./flattened -# The existing content of ./flattened is removed -# This tool takes both globs and filenames as the list of arguments and flattens everything -# Usage: ./script/sh/flatten.sh contracts/**.sol contracts/client/TestClient.sol <...> - -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' # No Color - -# Check if arguments were supplied -if [ $# -eq 0 ]; then - echo -e "${RED}Error: provide globs/filenames of the contracts to flatten!${NC}" - exit 1 -fi - -# First, we remove the existing flattened files -rm -rf ./flattened - -# Track the amount of flattened files for the final report -count=0 -# Then, we iterate over the supplied arguments -# If any argument was a glob, this will iterate over the files it specifies -for var in "$@"; do - # Strip contract name "Abc.sol" from the path - fn=$(basename "$var") - # Flatten the file and save it in ./flattened - # Make sure that flattened contracts base names are unique! - forge flatten "$var" -o "./flattened/$fn" - ((++count)) -done - -echo -e "${GREEN}Files flattened: $count${NC}" diff --git a/packages/contracts-communication/flatten.sh b/packages/contracts-communication/flatten.sh new file mode 120000 index 0000000000..bf88c4e2e5 --- /dev/null +++ b/packages/contracts-communication/flatten.sh @@ -0,0 +1 @@ +../../make/scripts/flatten.sh \ No newline at end of file diff --git a/packages/contracts-core/script/sh/flatten.sh b/packages/contracts-core/script/sh/flatten.sh deleted file mode 100755 index aa2a630fbe..0000000000 --- a/packages/contracts-core/script/sh/flatten.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -# This script flattens Solidity contracts and saves them in ./flattened -# The existing content of ./flattened is removed -# This tool takes both globs and filenames as the list of arguments and flattens everything -# Usage: ./script/sh/flatten.sh contracts/**.sol contracts/client/TestClient.sol <...> - -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' # No Color - -# Check if arguments were supplied -if [ $# -eq 0 ]; then - echo -e "${RED}Error: provide globs/filenames of the contracts to flatten!${NC}" - exit 1 -fi - -# First, we remove the existing flattened files -rm -rf ./flattened - -# Track the amount of flattened files for the final report -count=0 -# Then, we iterate over the supplied arguments -# If any argument was a glob, this will iterate over the files it specifies -for var in "$@"; do - # Strip contract name "Abc.sol" from the path - fn=$(basename "$var") - # Flatten the file and save it in ./flattened - # Make sure that flattened contracts base names are unique! - forge flatten "$var" -o "./flattened/$fn" - ((++count)) -done - -echo -e "${GREEN}Files flattened: $count${NC}" diff --git a/packages/contracts-core/script/sh/flatten.sh b/packages/contracts-core/script/sh/flatten.sh new file mode 120000 index 0000000000..dbde4b4983 --- /dev/null +++ b/packages/contracts-core/script/sh/flatten.sh @@ -0,0 +1 @@ +../../../../make/scripts/flatten.sh \ No newline at end of file diff --git a/packages/contracts-rfq/flatten.sh b/packages/contracts-rfq/flatten.sh deleted file mode 100755 index aa2a630fbe..0000000000 --- a/packages/contracts-rfq/flatten.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -# This script flattens Solidity contracts and saves them in ./flattened -# The existing content of ./flattened is removed -# This tool takes both globs and filenames as the list of arguments and flattens everything -# Usage: ./script/sh/flatten.sh contracts/**.sol contracts/client/TestClient.sol <...> - -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' # No Color - -# Check if arguments were supplied -if [ $# -eq 0 ]; then - echo -e "${RED}Error: provide globs/filenames of the contracts to flatten!${NC}" - exit 1 -fi - -# First, we remove the existing flattened files -rm -rf ./flattened - -# Track the amount of flattened files for the final report -count=0 -# Then, we iterate over the supplied arguments -# If any argument was a glob, this will iterate over the files it specifies -for var in "$@"; do - # Strip contract name "Abc.sol" from the path - fn=$(basename "$var") - # Flatten the file and save it in ./flattened - # Make sure that flattened contracts base names are unique! - forge flatten "$var" -o "./flattened/$fn" - ((++count)) -done - -echo -e "${GREEN}Files flattened: $count${NC}" diff --git a/packages/contracts-rfq/flatten.sh b/packages/contracts-rfq/flatten.sh new file mode 120000 index 0000000000..bf88c4e2e5 --- /dev/null +++ b/packages/contracts-rfq/flatten.sh @@ -0,0 +1 @@ +../../make/scripts/flatten.sh \ No newline at end of file