From 6568b87786b51e0c6f4b5e31c01e1eb4e7214cbf Mon Sep 17 00:00:00 2001 From: ngoc Date: Mon, 26 Jan 2026 10:27:19 +0700 Subject: [PATCH] feat: custom .env --- cli/commands/dev.ts | 13 ++++++++----- cli/index.ts | 7 ++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cli/commands/dev.ts b/cli/commands/dev.ts index 19f3355..095e379 100644 --- a/cli/commands/dev.ts +++ b/cli/commands/dev.ts @@ -12,10 +12,9 @@ const colors = { }; // Load .env file if it exists -function loadEnvFile() { - const envPath = '.env'; +function loadEnvFile(envPath: string = '.env') { if (existsSync(envPath)) { - console.log(`${colors.blue}📄 Loading .env file...${colors.reset}`); + console.log(`${colors.blue}📄 Loading .env file from: ${envPath}${colors.reset}`); const envContent = readFileSync(envPath, 'utf-8'); const lines = envContent.split('\n'); @@ -35,6 +34,10 @@ function loadEnvFile() { } } console.log(`${colors.green}✅ Environment variables loaded${colors.reset}`); + } else if (envPath !== '.env') { + // Only error if a custom path was specified but not found + console.error(`${colors.red}❌ .env file not found at: ${envPath}${colors.reset}`); + process.exit(1); } } @@ -63,13 +66,13 @@ function isPortInUse(port: number): boolean { } // Dev command - Start complete development environment -export async function runDevCommand(cliDir: string) { +export async function runDevCommand(cliDir: string, envPath?: string) { console.log(`${colors.blue}════════════════════════════════════════════════════════${colors.reset}`); console.log(`${colors.blue} Natural Language Agreement Oracle - Quick Setup${colors.reset}`); console.log(`${colors.blue}════════════════════════════════════════════════════════${colors.reset}\n`); // Load .env file first - loadEnvFile(); + loadEnvFile(envPath); console.log(''); // Check prerequisites diff --git a/cli/index.ts b/cli/index.ts index 56662c2..e1734e7 100755 --- a/cli/index.ts +++ b/cli/index.ts @@ -48,6 +48,7 @@ Options (vary by command): --arbitration-provider Arbitration provider (create, default: OpenAI) --arbitration-model Arbitration model (create, default: gpt-4o-mini) --arbitration-prompt Custom arbitration prompt (create, optional) + --env Path to .env file (dev, default: .env) Environment Variables: PRIVATE_KEY Private key for transactions @@ -58,6 +59,9 @@ Examples: # Start development environment nla dev + # Start development with custom .env file + nla dev --env /path/to/.env.production + # Deploy contracts nla deploy @@ -122,6 +126,7 @@ function parseCliArgs() { "arbitration-provider": { type: "string" }, "arbitration-model": { type: "string" }, "arbitration-prompt": { type: "string" }, + "env": { type: "string" }, }, strict: true, }); @@ -150,7 +155,7 @@ async function main() { // Handle dev and stop commands if (command === "dev") { - await runDevCommand(__dirname); + await runDevCommand(__dirname, args.env as string | undefined); return; }