Skip to content

Commit

Permalink
try adding loader option
Browse files Browse the repository at this point in the history
  • Loading branch information
spypsy committed Dec 4, 2023
1 parent 8de5f50 commit 1bcfcfa
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions yarn-project/noir-contracts/scripts/types.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#!/bin/bash

# Example:
Expand All @@ -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"
Expand All @@ -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"
}

Expand All @@ -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
Expand Down

0 comments on commit 1bcfcfa

Please sign in to comment.