From 86cd66252206821adee2b458e0caa42873943619 Mon Sep 17 00:00:00 2001 From: Venba Date: Thu, 6 Jun 2024 10:18:39 +0530 Subject: [PATCH] CHANGE_ --- .env.development | 4 +++- .env.production | 4 +++- .env.test | 3 +++ build_web_dev.sh | 34 ++++++++++++++++++++++++++++++++++ build_web_production.sh | 34 ++++++++++++++++++++++++++++++++++ build_web_test.sh | 34 ++++++++++++++++++++++++++++++++++ lib/main.dart | 1 + lib/models/environment.dart | 23 +++++++++++++++++++---- 8 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 .env.test create mode 100755 build_web_dev.sh create mode 100755 build_web_production.sh create mode 100755 build_web_test.sh diff --git a/.env.development b/.env.development index f37f410..8902263 100644 --- a/.env.development +++ b/.env.development @@ -1 +1,3 @@ -API_URL=https://venbait.in/nhance/dev/employeeRest/ \ No newline at end of file +API_URL=https://venbait.in/nhance/dev/employeeRest/ +BASE_HREF=/nhance/app/dev/ +ENV=development \ No newline at end of file diff --git a/.env.production b/.env.production index f37f410..10a94c8 100644 --- a/.env.production +++ b/.env.production @@ -1 +1,3 @@ -API_URL=https://venbait.in/nhance/dev/employeeRest/ \ No newline at end of file +API_URL=https://venbait.in/nhance/uat/employeeRest/ +BASE_HREF=/nhance/app/uat/ +ENV=production \ No newline at end of file diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..99da8dc --- /dev/null +++ b/.env.test @@ -0,0 +1,3 @@ +API_URL=https://venbait.in/nhance/test/employeeRest/ +BASE_HREF=/nhance/app/test/ +ENV=test \ No newline at end of file diff --git a/build_web_dev.sh b/build_web_dev.sh new file mode 100755 index 0000000..f7d52b3 --- /dev/null +++ b/build_web_dev.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Define the path to the .env.development file +ENV_FILE_PATH=".env.development" + +# Check if the .env.development file exists +if [ ! -f $ENV_FILE_PATH ]; then + echo "$ENV_FILE_PATH does not exist" + exit 1 +fi + +# Copy the .env.development file to .env +cp $ENV_FILE_PATH .env + +# Check if the BASE_HREF variable exists in the .env file +if ! grep -q BASE_HREF .env; then + echo "BASE_HREF not found in .env file" + exit 1 +fi + +# Extract the BASE_HREF value +BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2) + +# Check if the BASE_HREF value is empty +if [ -z "$BASE_HREF" ]; then + echo "BASE_HREF value is empty" + exit 1 +fi + +# Build the web app for development with base href +flutter build web --release --base-href "$BASE_HREF" + +# Optionally, remove the .env file after the build +# rm .env diff --git a/build_web_production.sh b/build_web_production.sh new file mode 100755 index 0000000..7463034 --- /dev/null +++ b/build_web_production.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Define the path to the .env file for production +ENV_FILE_PATH=".env.production" + +# Check if the .env file exists +if [ ! -f $ENV_FILE_PATH ]; then + echo "$ENV_FILE_PATH does not exist" + exit 1 +fi + +# Copy the .env file for production to .env +cp $ENV_FILE_PATH .env + +# Check if the BASE_HREF variable exists in the .env file +if ! grep -q BASE_HREF .env; then + echo "BASE_HREF not found in .env file" + exit 1 +fi + +# Extract the BASE_HREF value +BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2) + +# Check if the BASE_HREF value is empty +if [ -z "$BASE_HREF" ]; then + echo "BASE_HREF value is empty" + exit 1 +fi + +# Build the web app for production environment with base href +flutter build web --release --base-href "$BASE_HREF" + +# Optionally, remove the .env file after the build +# rm .env diff --git a/build_web_test.sh b/build_web_test.sh new file mode 100755 index 0000000..cee690d --- /dev/null +++ b/build_web_test.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Define the path to the .env file for testing +ENV_FILE_PATH=".env.test" + +# Check if the .env file exists +if [ ! -f $ENV_FILE_PATH ]; then + echo "$ENV_FILE_PATH does not exist" + exit 1 +fi + +# Copy the .env file for testing to .env +cp $ENV_FILE_PATH .env + +# Check if the BASE_HREF variable exists in the .env file +if ! grep -q BASE_HREF .env; then + echo "BASE_HREF not found in .env file" + exit 1 +fi + +# Extract the BASE_HREF value +BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2) + +# Check if the BASE_HREF value is empty +if [ -z "$BASE_HREF" ]; then + echo "BASE_HREF value is empty" + exit 1 +fi + +# Build the web app for test environment with base href +flutter build web --release --base-href "$BASE_HREF" + +# Optionally, remove the .env file after the build +# rm .env diff --git a/lib/main.dart b/lib/main.dart index 6a94274..e7d69cf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,6 +16,7 @@ import 'package:nhancepolicy/hrPolicyDetails.dart'; import 'package:nhancepolicy/oldPolicy.dart'; Future main() async { + // await dotenv.load(fileName: Environment.fileName); await dotenv.load(fileName: Environment.fileName); runApp(MaterialApp( diff --git a/lib/models/environment.dart b/lib/models/environment.dart index b17298b..096ca2a 100644 --- a/lib/models/environment.dart +++ b/lib/models/environment.dart @@ -3,14 +3,29 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class Environment { static String get fileName { - if (kReleaseMode) { - return '.env.production'; - } + const bool isProduction = + bool.fromEnvironment('dart.vm.product', defaultValue: false); + const bool isTest = + bool.fromEnvironment('dart.vm.environment', defaultValue: false); - return '.env.development'; + if (isProduction) { + return '.env.production'; + } else if (isTest) { + return '.env.test'; + } else { + return '.env.development'; + } } static String get apiUrl { return dotenv.env['API_URL'] ?? 'API_URL not found!'; } + + static String get baseHref { + return dotenv.env['BASE_HREF'] ?? 'BASE_HREF not found!'; + } + + static String get env { + return dotenv.env['ENV'] ?? 'ENV not found!'; + } }