Skip to content

Instantly share code, notes, and snippets.

@dansteren
Created July 31, 2022 00:12
Show Gist options
  • Save dansteren/7a69f6df99fdfab1fe32110d6ec29928 to your computer and use it in GitHub Desktop.
Save dansteren/7a69f6df99fdfab1fe32110d6ec29928 to your computer and use it in GitHub Desktop.
Utility functions for making life easier working in the azle repo
# Changes to the root directory (modify as needed)
# TODO: Consider using cdpath instead: http://romain.bardou.fr/blog/CDPATH.html
alias cdr='cd ~/repos/demergent-labs/azle'
# Comments out the last line in all index.js files in the dfx_generated directory
ma() {
COUNT=0
cd dfx_generated || exit
for directory in */; do
STORED_LAST_LINE=$(tail --lines=1 "$directory"/index.js)
FIRST_TWO_CHARS=${STORED_LAST_LINE:0:2}
if [ "$FIRST_TWO_CHARS" = "//" ]; then
continue
fi
sed -i '$ d' "$directory"/index.js
echo "// $STORED_LAST_LINE" >> "$directory"/index.js
((COUNT=COUNT+1))
done
cd ..
[[ $COUNT = 1 ]] && PLURAL="" || PLURAL="s"
echo "Modified ${COUNT} agent${PLURAL}"
}
# Deploys a g-zipped wasm file to a canister
deploy() {
dfx canister create "$1"
dfx build "$1"
dfx canister uninstall-code "$1"
if [ -z "$2" ]; then
dfx canister install "$1" --wasm "target/wasm32-unknown-unknown/release/$1.wasm.gz"
else
dfx canister install "$1" --argument "$2" --wasm "target/wasm32-unknown-unknown/release/$1.wasm.gz"
fi
}
# Runs prettier from the root directory
purdy() {
PRESENT_DIR=$(pwd)
cdr #Alias from above
echo "Running prettier from $(pwd)"
npx prettier --write .
cd "$PRESENT_DIR" || exit
}
# Runs dfx generate and cleans up afterwards
gen() {
dfx generate
purdy
ma
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment