|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -echo "Downloading latest soljson.js from https://binaries.soliditylang.org/wasm/list.json" |
| 3 | +echo "Downloading specified soljson.js version based on defaultVersion in package.json" |
| 4 | + |
4 | 5 | set -e |
5 | | -# check if curl is installed |
6 | | -if ! command -v curl &> /dev/null |
7 | | -then |
| 6 | + |
| 7 | +# Check if curl and jq are installed |
| 8 | +if ! command -v curl &> /dev/null; then |
8 | 9 | echo "curl could not be found" |
9 | | - exit |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +if ! command -v jq &> /dev/null; then |
| 14 | + echo "jq could not be found" |
| 15 | + exit 1 |
10 | 16 | fi |
11 | 17 |
|
| 18 | +# Read the defaultVersion from package.json |
| 19 | +defaultVersion=$(jq -r '.defaultVersion' package.json) |
| 20 | +echo "Specified version from package.json: $defaultVersion" |
12 | 21 |
|
13 | | -# download https://binaries.soliditylang.org/wasm/list.json as json |
| 22 | +# Download the list.json file containing available versions |
14 | 23 | curl -s https://binaries.soliditylang.org/wasm/list.json > list.json |
15 | | -# get the latest version without jq |
16 | | -latest=$(grep 'latestRelease' list.json | cut -d '"' -f 4) |
17 | | -echo "latest version: $latest" |
18 | | -# get url |
19 | | -url=$(grep "\"$latest\":" list.json | cut -d '"' -f 4) |
20 | | -echo "url: $url" |
21 | | -path="https://binaries.soliditylang.org/bin/$url" |
22 | | -echo "path: $path" |
23 | | -# download the file to ./apps/remix-ide/src/assets/js/soljson.js |
24 | | -curl -s $path > ./apps/remix-ide/src/assets/js/soljson.js |
25 | | -# if directory ./apps/remix-ide/src/assets/js/soljson does not exist, create it |
| 24 | + |
| 25 | +# Use jq to extract the path for the specified version from the builds array |
| 26 | +path=$(jq -r --arg version "$defaultVersion" '.builds[] | select(.path==$version) | .path' list.json) |
| 27 | +if [ -z "$path" ]; then |
| 28 | + echo "The specified version $defaultVersion could not be found in the list" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +echo "Path for the specified version: $path" |
| 33 | +fullPath="https://binaries.soliditylang.org/bin/$path" |
| 34 | +echo "Download fullPath: $fullPath" |
| 35 | + |
| 36 | +# Ensure the target directory exists |
26 | 37 | if [ ! -d "./apps/remix-ide/src/assets/js/soljson" ]; then |
27 | | - mkdir ./apps/remix-ide/src/assets/js/soljson |
| 38 | + mkdir -p ./apps/remix-ide/src/assets/js/soljson |
28 | 39 | fi |
29 | | -cp ./apps/remix-ide/src/assets/js/soljson.js ./apps/remix-ide/src/assets/js/soljson/$url |
| 40 | + |
| 41 | +# Download the file to ./apps/remix-ide/src/assets/js/soljson.js |
| 42 | +echo "Downloading soljson.js from "$fullPath" to ./apps/remix-ide/src/assets/js/soljson.js" |
| 43 | +curl -s "$fullPath" > ./apps/remix-ide/src/assets/js/soljson.js |
| 44 | + |
| 45 | +# Copy the downloaded soljson.js to the specific version directory |
| 46 | +cp ./apps/remix-ide/src/assets/js/soljson.js "./apps/remix-ide/src/assets/js/soljson/$path" |
30 | 47 | cp list.json ./apps/remix-ide/src/assets/list.json |
31 | 48 |
|
32 | | -# remove list.json |
| 49 | +# Clean up by removing the list.json |
33 | 50 | rm list.json |
34 | | - |
|
0 commit comments