Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate typescript and publish on merge #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
workspaces := "./packages"
# workspaces := "./packages ./core"

set dotenv-load
# Displays available recipes by running `just -l`.
setup:
#!/usr/bin/env bash
Expand Down Expand Up @@ -90,12 +91,47 @@ tidy-update: build-update
just tidy

gen-schema:
#!/usr/bin/env bash
for dir in contracts/*/; do
dir_name=$(basename $dir)

echo "Generating schema for $dir"
cd $dir
cargo schema
mv ./schema ../../schema/$dir_name
done
#!/usr/bin/env bash
initial_dir=$PWD
for dir in contracts/*; do
dir_name=$(basename $dir)
echo "Generating schema for $dir_name..."

# Change to the contract directory
if cd $dir; then
# Check if 'cargo schema' can be run successfully
if cargo schema; then
# Move back to the initial directory
cd $initial_dir
# Create target schema directory if it doesn't exist
mkdir -p schema/$dir_name
# Move the generated schema to the target directory
if ! mv $dir/schema schema/$dir_name; then
echo "Failed to move schema directory for $dir_name."
fi
else
cd $initial_dir
fi
else
echo "Failed to change directory to $dir."
fi
Comment on lines +94 to +118
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gen-schema recipe has been enhanced to handle directory changes and schema generation more robustly. Consider the following improvements:

  • Error Handling: Ensure that the script exits with a non-zero status code when encountering errors to prevent silent failures in CI/CD pipelines.
  • Directory Navigation: Use pushd and popd instead of cd for changing directories. This approach is more reliable and readable, especially in scripts with multiple directory changes.
- if cd $dir; then
+ if pushd $dir > /dev/null; then
- cd $initial_dir
+ popd > /dev/null

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
#!/usr/bin/env bash
initial_dir=$PWD
for dir in contracts/*; do
dir_name=$(basename $dir)
echo "Generating schema for $dir_name..."
# Change to the contract directory
if cd $dir; then
# Check if 'cargo schema' can be run successfully
if cargo schema; then
# Move back to the initial directory
cd $initial_dir
# Create target schema directory if it doesn't exist
mkdir -p schema/$dir_name
# Move the generated schema to the target directory
if ! mv $dir/schema schema/$dir_name; then
echo "Failed to move schema directory for $dir_name."
fi
else
cd $initial_dir
fi
else
echo "Failed to change directory to $dir."
fi
done
#!/usr/bin/env bash
initial_dir=$PWD
for dir in contracts/*; do
dir_name=$(basename $dir)
echo "Generating schema for $dir_name..."
# Change to the contract directory
if pushd $dir > /dev/null; then
# Check if 'cargo schema' can be run successfully
if cargo schema; then
# Move back to the initial directory
popd > /dev/null
# Create target schema directory if it doesn't exist
mkdir -p schema/$dir_name
# Move the generated schema to the target directory
if ! mv $dir/schema schema/$dir_name; then
echo "Failed to move schema directory for $dir_name."
fi
else
popd > /dev/null
fi
else
echo "Failed to change directory to $dir."
fi
done

done

# Generate schema for all contracts and generate TypeScript code
gen-ts:
#!/usr/bin/env bash
just gen-schema

SCHEMA_DIR="./schema"
TS_OUT_DIR="./dist"
mkdir -p $TS_OUT_DIR
for schema_path in $(find $SCHEMA_DIR -name schema -type d | grep -v "^./schema$"); do
contract_name=$(basename $(dirname $schema_path))
echo "Generating TypeScript for $contract_name..."
cosmwasm-ts-codegen generate \
--plugin client \
--schema $schema_path \
--out $TS_OUT_DIR/$contract_name \
--name $contract_name \
--no-bundle
done
Loading