diff --git a/yarn-project/noir-contracts/scripts/types.sh b/yarn-project/noir-contracts/scripts/types.sh index 2747a38ef9b3..c25603dda38a 100755 --- a/yarn-project/noir-contracts/scripts/types.sh +++ b/yarn-project/noir-contracts/scripts/types.sh @@ -1,4 +1,3 @@ - #!/bin/bash # Example: @@ -8,7 +7,7 @@ # Enable strict mode: # Exit on error (set -e), treat unset variables as an error (set -u), -set -eu; +set -eu artifacts_dir="src/artifacts" types_dir="src/types" @@ -17,42 +16,40 @@ types_dir="src/types" mkdir -p $types_dir mkdir -p $artifacts_dir - ROOT=$(pwd) write_import() { - CONTRACT_NAME=$1 - NAME=$(echo $CONTRACT_NAME | perl -pe 's/(^|_)(\w)/\U$2/g') + CONTRACT_NAME=$1 + NAME=$(echo $CONTRACT_NAME | perl -pe 's/(^|_)(\w)/\U$2/g') - echo "import ${NAME}Json from './${CONTRACT_NAME}_contract.json' assert { type: 'json' };" >> "$artifacts_dir/index.ts"; + echo "import ${NAME}Json from './${CONTRACT_NAME}_contract.json' assert { type: 'json' };" >>"$artifacts_dir/index.ts" } write_export() { - CONTRACT_NAME=$1 - NAME=$(echo $CONTRACT_NAME | perl -pe 's/(^|_)(\w)/\U$2/g') + CONTRACT_NAME=$1 + NAME=$(echo $CONTRACT_NAME | perl -pe 's/(^|_)(\w)/\U$2/g') - # artifacts - echo "export const ${NAME}ContractArtifact = ${NAME}Json as ContractArtifact;" >> "$artifacts_dir/index.ts"; - echo "Written typescript for $NAME" + # artifacts + echo "export const ${NAME}ContractArtifact = ${NAME}Json as ContractArtifact;" >>"$artifacts_dir/index.ts" + echo "Written typescript for $NAME" - # types - echo "export * from './${CONTRACT_NAME}.js';" >> "$types_dir/index.ts"; + # types + echo "export * from './${CONTRACT_NAME}.js';" >>"$types_dir/index.ts" } - process() { CONTRACT=$1 cd $ROOT - NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_source.ts $CONTRACT_NAME + NODE_OPTIONS="--no-warnings --loader ts-node/esm" yarn ts-node --esm src/scripts/copy_source.ts $CONTRACT_NAME echo "Creating types for $CONTRACT" - NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_output.ts $CONTRACT_NAME + NODE_OPTIONS="--no-warnings --loader ts-node/esm" yarn ts-node --esm src/scripts/copy_output.ts $CONTRACT_NAME } -format(){ +format() { echo "Formatting contract folders" - yarn run -T prettier -w ../aztec.js/src/artifacts/*.json ./$types_dir/*.ts + yarn run -T prettier -w ../aztec.js/src/artifacts/*.json ./$types_dir/*.ts echo -e "Done\n" } @@ -69,14 +66,14 @@ wait rm -f $artifacts_dir/index.ts || true # Generate artifacts package index.ts -echo "// Auto generated module\n" > "$artifacts_dir/index.ts"; -echo "import { ContractArtifact } from '@aztec/foundation/abi';" >> "$artifacts_dir/index.ts"; +echo "// Auto generated module\n" >"$artifacts_dir/index.ts" +echo "import { ContractArtifact } from '@aztec/foundation/abi';" >>"$artifacts_dir/index.ts" # Generate types package index.ts -echo "// Auto generated module\n" > "$types_dir/index.ts"; +echo "// Auto generated module\n" >"$types_dir/index.ts" for CONTRACT_NAME in "$@"; do - write_import $CONTRACT_NAME - write_export $CONTRACT_NAME + write_import $CONTRACT_NAME + write_export $CONTRACT_NAME done # only run the rest when the full flag is set