Skip to content

Commit fa716ee

Browse files
authored
feat: add script to publish npm packages (#99)
1 parent 506e655 commit fa716ee

File tree

7 files changed

+93
-21
lines changed

7 files changed

+93
-21
lines changed

.github/workflows/publish-npm.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,36 @@ jobs:
2626
node-version: "22.14.0"
2727
registry-url: "https://registry.npmjs.org"
2828

29-
- name: Build
30-
run: anchor build
29+
- name: Build Prod
30+
run: |
31+
anchor run build-gateway
32+
mkdir -p prod/lib
33+
mkdir -p prod/idl
34+
cp target/deploy/gateway.so prod/lib/
35+
cp target/idl/gateway.json prod/idl/gateway.json
36+
37+
- name: Build Dev
38+
run: |
39+
anchor run build-gateway-dev
40+
mkdir -p dev/lib
41+
mkdir -p dev/idl
42+
cp target/deploy/gateway.so dev/lib/
43+
cp target/idl/gateway.json dev/idl/gateway.json
3144
32-
- name: Prepare IDL Files
33-
run: mv target/idl ./
45+
- name: Create index.js
46+
run: |
47+
cat > index.js << EOF
48+
module.exports = {
49+
prod: {
50+
programId: "ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis",
51+
idl: require("./mainnet/idl/gateway.json")
52+
},
53+
dev: {
54+
programId: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d",
55+
idl: require("./testnet/idl/gateway.json")
56+
}
57+
};
58+
EOF
3459
3560
- name: Determine NPM Tag
3661
id: determine-npm-tag

Anchor.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ wallet = "~/.config/solana/id.json"
2727

2828
[scripts]
2929
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
30-
build-gateway-dev = "cargo build-sbf --features dev --manifest-path programs/gateway/Cargo.toml"
31-
build-gateway = "cargo build-sbf --manifest-path programs/gateway/Cargo.toml"
30+
build-gateway-dev = "anchor build --program-name gateway -- --features dev"
31+
build-gateway = "anchor build --program-name gateway"
3232
build-upgrade-dev = "cargo build-sbf --features dev --manifest-path programs/examples/gateway_upgrade/Cargo.toml"
33+
build-examples = "anchor build --program-name connected && anchor build --program-name connected_spl"

Makefile

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
# directories for Go code generation
22
IDL_DIR := ./target/idl
33
GENERATED_DIR := ./generated
4+
# Default version if not specified
5+
VERSION ?= 0.1.0
46

5-
# generate Go code from IDL files
7+
# generate Go bindings from IDL files
68
.PHONY: generate
79
generate:
8-
rm -rf $(GENERATED_DIR)/*.go
9-
@for file in $(wildcard $(IDL_DIR)/*.json); do \
10-
base_name=$$(basename $$file .json); \
11-
input_file="../$$file"; \
12-
output_file="$(GENERATED_DIR)/$$base_name.go"; \
13-
echo "Generating $$output_file from $$file"; \
14-
(cd go-idl && go run ./generator "$$input_file" "$$output_file"); \
15-
(cd go-idl && go fmt $$output_file); \
16-
done
10+
@chmod +x ./scripts/generate_go_bindings.sh
11+
@./scripts/generate_go_bindings.sh $(IDL_DIR) $(GENERATED_DIR)
1712

13+
# build program with dev features for testnet
14+
.PHONY: dev
15+
dev:
16+
@echo "Building gateway for development environments"
17+
@anchor build --program-name gateway -- --features dev
18+
19+
# build program for mainnet (without features)
20+
.PHONY: prod
21+
prod:
22+
@echo "Building gateway for production environments"
23+
@anchor build --program-name gateway
24+
25+
# generate Go code for development networks (with dev features)
26+
.PHONY: generate-dev
27+
generate-dev: dev generate
28+
29+
# generate Go code for mainnet
30+
.PHONY: generate-prod
31+
generate-prod: prod generate

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ To run the tests
5858
$ anchor test
5959
```
6060

61-
To generate Go code for program's IDL
61+
To generate Go bindings for program's IDL
62+
Development environments : Localnet
6263
```bash
63-
$ make generate
64+
$ make generate-dev
65+
```
66+
67+
Production environments : Mainnet,Testnet
68+
```bash
69+
$ make generate-prod
6470
```
6571

6672
# Authentication and Authorization

go-idl/generated/gateway.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"private": false,
44
"license": "MIT",
55
"version": "0.0.0-set-on-publish",
6-
"description": "Package contains IDL files for the Solana Gateway program, enabling cross-chain functionality with ZetaChain",
6+
"description": "Package contains IDL and shared object files for the Solana Gateway program, enabling cross-chain functionality with ZetaChain",
77
"files": [
8-
"idl"
8+
"mainnet",
9+
"testnet",
10+
"index.js"
911
],
1012
"scripts": {
1113
"fmt:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",

scripts/generate_go_bindings.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# generate_idl.sh
3+
4+
# Get parameters
5+
IDL_DIR=$1
6+
GENERATED_DIR=$2
7+
8+
# Remove existing generated files
9+
rm -rf ${GENERATED_DIR}/*.go
10+
11+
# Process each IDL file
12+
for file in $(find ${IDL_DIR} -name "*.json"); do
13+
base_name=$(basename $file .json)
14+
input_file="../$file"
15+
output_file="${GENERATED_DIR}/${base_name}.go"
16+
17+
echo "Generating ${output_file} from ${file}"
18+
19+
# Run the generator
20+
(cd go-idl && go run ./generator "${input_file}" "${output_file}")
21+
22+
# Format the generated file
23+
(cd go-idl && go fmt "${output_file}")
24+
done

0 commit comments

Comments
 (0)