From 3bf3be46580abe644d5384714baf5c12ca57760c Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Thu, 28 Nov 2024 19:40:42 +0900 Subject: [PATCH] fix flag with env var (#288) --- examples/tictactoe/README.md | 7 ++++--- examples/tictactoe/package.json | 7 +++---- examples/tictactoe/src/constants/tictactoe.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/tictactoe/README.md b/examples/tictactoe/README.md index 61b62c11..e6bb6179 100644 --- a/examples/tictactoe/README.md +++ b/examples/tictactoe/README.md @@ -32,17 +32,18 @@ The forge script will log the deployed deterministic contract address. ... Script ran successfully.. == Logs == - Deployed at: 0x14eFE545C60FB3b65B9eeb23E22b8013908e48Bc - + Deployed at: 0x14eFE545C60FB3b65B9eeb23E22b8013908e48Bc ... ``` ### 2. Run The Frontend -Ensure the contract address matches the constant within `examples/tictactoe/src/constants/tictactoe.ts` +Supply the address as an environment variable when running the frontend. ```bash cd examples/tictactoe + +export VITE_TICTACTOE_ADDRESS=0x14eFE545C60FB3b65B9eeb23E22b8013908e48Bc pnpn i && pnpm run dev ``` diff --git a/examples/tictactoe/package.json b/examples/tictactoe/package.json index 33a57c83..2d379cd0 100644 --- a/examples/tictactoe/package.json +++ b/examples/tictactoe/package.json @@ -4,10 +4,9 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "test -n \"$npm_config_address\" && TICTACTOE_ADDRESS=$npm_config_address vite || (echo 'Error: --address parameter is required' && exit 1)", - "build": "test -n \"$npm_config_address\" && TICTACTOE_ADDRESS=$npm_config_address tsc -b && vite build || (echo 'Error: --address parameter is required' && exit 1)", - "lint": "eslint .", - "preview": "vite preview" + "dev": "if [ -z \"$VITE_TICTACTOE_ADDRESS\" ]; then echo 'Error: VITE_TICTACTOE_ADDRESS env is required' && exit 1; else vite; fi", + "build": "if [ -z \"$VITE_TICTACTOE_ADDRESS\" ]; then echo 'Error: VITE_TICTACTOE_ADDRESS env is required' && exit 1; else tsc -b && vite build; fi", + "lint": "eslint ." }, "dependencies": { "@eth-optimism/viem": "^0.0.7", diff --git a/examples/tictactoe/src/constants/tictactoe.ts b/examples/tictactoe/src/constants/tictactoe.ts index adf572b3..266311e5 100644 --- a/examples/tictactoe/src/constants/tictactoe.ts +++ b/examples/tictactoe/src/constants/tictactoe.ts @@ -1,4 +1,4 @@ -export const address = import.meta.env.TICTACTOE_ADDRESS +export const address = import.meta.env.VITE_TICTACTOE_ADDRESS export const abi = [ {