Created
November 4, 2024 12:53
-
-
Save suresh-kumara-gist/e73b2f26afe4df55328e79b97390c63b to your computer and use it in GitHub Desktop.
create the Flutter project and set graddle version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
#!/bin/bash | |
# Function to prompt for user input | |
prompt() { | |
read -p "$1" response | |
echo "$response" | |
} | |
# Get the directory to create the Flutter project | |
DIRECTORY=$(prompt "Enter the directory to create the Flutter project: ") | |
# Check if the directory exists, create it if it doesn't | |
if [ ! -d "$DIRECTORY" ]; then | |
echo "Directory does not exist. Creating directory: $DIRECTORY" | |
mkdir -p "$DIRECTORY" | |
if [ $? -ne 0 ]; then | |
echo "Failed to create directory. Exiting." | |
exit 1 | |
fi | |
fi | |
# Change to the specified directory | |
cd "$DIRECTORY" || exit | |
# Get the project name | |
PROJECT_NAME=$(prompt "Enter the Flutter project name: ") | |
# Check if project name is provided | |
if [ -z "$PROJECT_NAME" ]; then | |
echo "Project name cannot be empty. Exiting." | |
exit 1 | |
fi | |
# Create the Flutter project | |
flutter create "$PROJECT_NAME" | |
if [ $? -ne 0 ]; then | |
echo "Failed to create Flutter project." | |
exit 1 | |
fi | |
# Ask for platforms to retain | |
PLATFORMS=$(prompt "Enter platforms to retain (android, ios, linux, web, macos, windows) separated by spaces: ") | |
# Define all possible platforms | |
ALL_PLATFORMS=("android" "ios" "linux" "web" "macos" "windows") | |
# Remove platforms not in the retain list | |
for PLATFORM in "${ALL_PLATFORMS[@]}"; do | |
if [[ ! " $PLATFORMS " =~ " $PLATFORM " ]]; then | |
if [ -d "$PROJECT_NAME/$PLATFORM" ]; then | |
rm -rf "$PROJECT_NAME/$PLATFORM" | |
echo "Removed $PLATFORM platform." | |
fi | |
fi | |
done | |
# Ask for Gradle version, default to 8.4 if empty | |
GRADLE_VERSION=$(prompt "Enter Gradle version (default is 8.4): ") | |
GRADLE_VERSION=${GRADLE_VERSION:-8.4} | |
# Change to the Android directory and set Gradle version | |
cd "$PROJECT_NAME/android" || exit | |
./gradlew wrapper --gradle-version="$GRADLE_VERSION" | |
if [ $? -ne 0 ]; then | |
echo "Failed to set Gradle version." | |
exit 1 | |
fi | |
cd - || exit | |
# Ask for any packages to be installed | |
PACKAGES=$(prompt "Enter any packages to install (space-separated, or leave empty): ") | |
# If packages are provided, run flutter pub add | |
if [ -n "$PACKAGES" ]; then | |
# Change to the project directory | |
cd "$PROJECT_NAME" || exit | |
# Run flutter pub add with the provided packages | |
echo "Adding packages: $PACKAGES" | |
flutter pub add $PACKAGES | |
if [ $? -ne 0 ]; then | |
echo "Failed to add packages." | |
exit 1 | |
fi | |
fi | |
# Initialize Git repository and make the first commit | |
cd "$PROJECT_NAME" || exit | |
git init | |
git branch -m master | |
git add . | |
git commit -m "first commit" | |
cd "$PROJECT_NAME" | |
echo "Flutter project '$PROJECT_NAME' created successfully!" | |
``` |
Author
suresh-kumara-gist
commented
Nov 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment