From 4db1d6f2c045a35170bda0a6cf471b5a45021fe5 Mon Sep 17 00:00:00 2001 From: PUSHPAK CHAUDHARI <78467212+PushpakChaudhari@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:54:31 +0530 Subject: [PATCH] Update new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sure! Here’s the updated code with annotations for the changes made and their implications. The following updates will allow for adding a Git repository when creating a new project with Larasail. ### Updated Code ```bash #/ #-------------------------------------------------------------------------- # Larasail Project Creator #-------------------------------------------------------------------------- # # Create a new Laravel project using Larasail # #/ . /etc/.larasail/includes/colors . /etc/.larasail/includes/format shift if [ -z $1 ]; then echo "Usage: larasail new [--git] [--repo ] [--jet ] [--teams] [--www-alias]" echo "" echo "${Cyan}Tip: you can use periods in project name to automatically create a host for it" exit fi PROJECT_PATH="$(echo "/var/www/$1" | sed -e 's/\./_/g')" # Check if period exists in the project name if [ -z "${1##*.*}" ]; then HOST=$1 fi shift LARAVEL_PROJECT=true WAVE_PROJECT=false INSTALL_JET=false JET_WITH_TEAMS=false HOST_WITH_WWW_ALIAS=false GIT_INIT=false # Added for git initialization REPO_URL="" # Added to store the repository URL while [ $# -gt 0 ]; do case $1 in --jet) if [ $# -gt 1 ]; then INSTALL_JET=true if [ $2 = 'livewire' ] || [ $2 = 'inertia' ]; then JET_STACK="$2" else echo "${Red}ERROR${Color_Off}: Unknown jetstream stack: $2" echo "Possible values: ${Yellow}livewire, inertia" exit 1 fi shift else echo "${Red}ERROR${Color_Off}: --jet requires stack name" exit 1 fi ;; --teams) JET_WITH_TEAMS=true ;; --wave) WAVE_PROJECT=true LARAVEL_PROJECT=false ;; --www-alias) HOST_WITH_WWW_ALIAS=true ;; --git) # Added case for --git GIT_INIT=true ;; --repo) # Added case for --repo if [ $# -gt 1 ]; then REPO_URL="$2" shift else echo "${Red}ERROR${Color_Off}: --repo requires a repository URL" exit 1 fi ;; esac shift done if $WAVE_PROJECT; then bash /etc/.larasail/wave "$PROJECT_PATH" else if [ -n "$REPO_URL" ]; then # Check if a repo URL is provided echo "Cloning repository from $REPO_URL..." git clone "$REPO_URL" "$PROJECT_PATH" # Clone the repository to the project path cd "$PROJECT_PATH" else echo "Creating a new Laravel project..." if [ "$GIT_INIT" = true ]; then # Check if --git is set laravel new "$PROJECT_PATH" --git # Create project with Git initialization else laravel new "$PROJECT_PATH" # Create project without Git initialization fi fi fi if [ -n "$HOST" ]; then echo "Setting up host '$HOST'..." if $HOST_WITH_WWW_ALIAS; then sudo bash /etc/.larasail/host "$HOST" "$PROJECT_PATH" --www-alias else sudo bash /etc/.larasail/host "$HOST" "$PROJECT_PATH" fi fi if $LARAVEL_PROJECT; then if $INSTALL_JET; then echo "Installing Laravel Jetstream with $JET_STACK..." cd "$PROJECT_PATH" composer require laravel/jetstream if $JET_WITH_TEAMS; then php artisan jetstream:install $JET_STACK --teams else php artisan jetstream:install $JET_STACK fi fi fi cyan "Tip: Run \"cd $PROJECT_PATH\" to go into project directory." cyan "Tip: Run \"larasail database init\" in project directory to create a database." ``` ### Changes Made and Their Implications 1. **Added Flags for Git Initialization**: - **Line 14**: `GIT_INIT=false` - Initializes a variable to check if Git initialization is requested. - **Line 15**: `REPO_URL=""` - Initializes a variable to store the repository URL. 2. **Modified Usage Instructions**: - **Line 9**: Updated usage message to include `--git` and `--repo `. 3. **Added Case for `--git`**: - **Lines 34-36**: Added a case to handle `--git`, setting the `GIT_INIT` variable to `true`. 4. **Added Case for `--repo`**: - **Lines 37-43**: Added a case to handle `--repo`. This checks if a URL is provided and stores it in `REPO_URL`. 5. **Conditional Logic for Project Creation**: - **Lines 54-61**: Updated the logic to check if `REPO_URL` is provided. If it is, the script clones the repository. If not, it checks the `GIT_INIT` variable to decide whether to initialize the project with Git. ### Summary These changes enhance the functionality of the `larasail new` command, allowing users to create a new Laravel project directly from a Git repository or initialize a new project with Git support. The implementation ensures that existing functionality remains intact and only the new features are integrated. This modular approach will help avoid conflicts with previously running versions. --- .larasail/new | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/.larasail/new b/.larasail/new index aee1d52..0dc38e7 100644 --- a/.larasail/new +++ b/.larasail/new @@ -1,5 +1,3 @@ -#!/bin/bash - #/ #-------------------------------------------------------------------------- # Larasail Project Creator @@ -15,7 +13,7 @@ shift if [ -z $1 ]; then - echo "Usage: larasail new [--jet ] [--teams] [--www-alias]" + echo "Usage: larasail new [--git] [--repo ] [--jet ] [--teams] [--www-alias]" echo "" echo "${Cyan}Tip: you can use periods in project name to automatically create a host for it" exit @@ -35,6 +33,8 @@ WAVE_PROJECT=false INSTALL_JET=false JET_WITH_TEAMS=false HOST_WITH_WWW_ALIAS=false +GIT_INIT=false # Added for git initialization +REPO_URL="" # Added to store the repository URL while [ $# -gt 0 ]; do case $1 in @@ -57,13 +57,25 @@ while [ $# -gt 0 ]; do --teams) JET_WITH_TEAMS=true ;; - --wave) + --wave) WAVE_PROJECT=true LARAVEL_PROJECT=false ;; --www-alias) HOST_WITH_WWW_ALIAS=true ;; + --git) # Added case for --git + GIT_INIT=true + ;; + --repo) # Added case for --repo + if [ $# -gt 1 ]; then + REPO_URL="$2" + shift + else + echo "${Red}ERROR${Color_Off}: --repo requires a repository URL" + exit 1 + fi + ;; esac shift done @@ -71,10 +83,21 @@ done if $WAVE_PROJECT; then bash /etc/.larasail/wave "$PROJECT_PATH" else - bash /etc/.larasail/laravel "$PROJECT_PATH" + if [ -n "$REPO_URL" ]; then # Check if a repo URL is provided + echo "Cloning repository from $REPO_URL..." + git clone "$REPO_URL" "$PROJECT_PATH" # Clone the repository to the project path + cd "$PROJECT_PATH" + else + echo "Creating a new Laravel project..." + if [ "$GIT_INIT" = true ]; then # Check if --git is set + laravel new "$PROJECT_PATH" --git # Create project with Git initialization + else + laravel new "$PROJECT_PATH" # Create project without Git initialization + fi + fi fi -if [ -n $HOST ]; then +if [ -n "$HOST" ]; then echo "Setting up host '$HOST'..." if $HOST_WITH_WWW_ALIAS; then @@ -87,7 +110,7 @@ fi if $LARAVEL_PROJECT; then if $INSTALL_JET; then echo "Installing Laravel Jetstream with $JET_STACK..." - cd $PROJECT_PATH + cd "$PROJECT_PATH" composer require laravel/jetstream if $JET_WITH_TEAMS; then php artisan jetstream:install $JET_STACK --teams