Skip to content

Commit

Permalink
fix: env file management for parcel
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuidl committed Sep 18, 2024
1 parent d302601 commit a941696
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
6 changes: 0 additions & 6 deletions .env.dist

This file was deleted.

6 changes: 6 additions & 0 deletions veascan-web/.env.devnet.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Subgraph endpoints for veascan, Example: "85918/vea-inbox-arb-sepolia-devnet/version/latest"
export VEASCAN_INBOX_ARBSEPOLIA_TO_SEPOLIA_SUBGRAPH=11111/your-subgraph/version/your-version
export VEASCAN_OUTBOX_ARBSEPOLIA_TO_SEPOLIA_SUBGRAPH=11111/your-subgraph/version/your-version

export VEASCAN_INBOX_ARBSEPOLIA_TO_CHIADO_SUBGRAPH=11111/your-subgraph/version/your-version
export VEASCAN_OUTBOX_ARBSEPOLIA_TO_CHIADO_SUBGRAPH=11111/your-subgraph/version/your-version
4 changes: 2 additions & 2 deletions veascan-web/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
overwrite: true,
schema: [
"https://api.studio.thegraph.com/query/67213/veascan-inbox-arb-sep-devnet/version/latest",
"https://api.studio.thegraph.com/query/67213/veascan-outbox-arb-sep-devnet/version/latest",
`https://api.studio.thegraph.com/query/${process.env.VEASCAN_INBOX_ARBSEPOLIA_TO_SEPOLIA_SUBGRAPH}`,
`https://api.studio.thegraph.com/query/${process.env.VEASCAN_OUTBOX_ARBSEPOLIA_TO_SEPOLIA_SUBGRAPH}`,
],
documents: "src/hooks/queries/*.ts",
generates: {
Expand Down
18 changes: 13 additions & 5 deletions veascan-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@
"queries": "./src/hooks/queries"
},
"scripts": {
"clear": "rm -r .parcel-cache",
"clean": "rm dist/bundle.js",
"start": "parcel",
"build": "parcel build",
"clean": "rm -rf dist/bundle.js .parcel-cache",
"start": "yarn start-devnet",
"start-devnet": "scripts/runEnv.sh devnet 'yarn parcel'",
"start-testnet": "scripts/runEnv.sh testnet 'yarn parcel'",
"start-mainnet": "scripts/runEnv.sh mainnet 'yarn parcel'",
"build": "yarn build-devnet",
"build-devnet": "scripts/runEnv.sh devnet 'yarn parcel build'",
"build-testnet": "scripts/runEnv.sh testnet 'yarn parcel build'",
"build-mainnet": "scripts/runEnv.sh mainnet 'yarn parcel build'",
"check-style": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"check-types": "tsc --noEmit",
"generate": "graphql-codegen --config codegen.ts",
"generate": "yarn generate-devnet",
"generate-devnet": "scripts/runEnv.sh devnet 'yarn codegen'",
"generate-testnet": "scripts/runEnv.sh testnet 'yarn codegen'",
"generate-mainnet": "scripts/runEnv.sh mainnet 'yarn codegen'",
"codegen": "graphql-codegen --config codegen.ts"
},
"devDependencies": {
Expand Down
37 changes: 37 additions & 0 deletions veascan-web/scripts/runEnv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

deployment="$1"
shift
commands="$@"

if [[ -z "$deployment" ]]; then
echo "usage: $(basename $0) <local|devnet|testnet|mainnet>"
exit 1
fi

valid_deployments=("local" "devnet" "testnet" "mainnet")
if [[ ! " ${valid_deployments[@]} " =~ " ${deployment} " ]]; then
echo "Invalid deployment option. Please choose either: ${valid_deployments[@]}."
exit 1
fi

function sourceEnvFile() { #envFile
envFile="$1"
if [ -f "$envFile" ]; then
echo -e "${GREEN}${NC} $(basename $envFile)"
. $envFile
else
echo -e "${RED}${NC} $(basename $envFile)"
fi
}

envFile="$SCRIPT_DIR/../.env.${deployment}"
sourceEnvFile "$envFile"
sourceEnvFile "$envFile.public"

(set -e; $commands)

0 comments on commit a941696

Please sign in to comment.