Added laravel-init

This commit is contained in:
Ali
2025-12-18 14:43:56 +08:00
parent 4492d4557c
commit 15676b08d9
4 changed files with 308 additions and 3 deletions

41
laravel-init Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
# Current user.
ME=$(whoami)
# Use PHP composer to check if the project requires Laravel framework and quit if not.
if ! composer show | grep -q "laravel/framework"; then
echo "This project does not require Laravel framework. Exiting."
return 1
fi
# Show the version of Laravel installed.
LARAVEL_VERSION=$(composer show --format=json | jq -r '.packages[]? | select(.name == "laravel/framework") | .version')
echo "Laravel version: $LARAVEL_VERSION"
# Create required empty directories and add .gitignore to each of them:
DIRECTORIES=(
"storage/framework/cache"
"storage/framework/sessions"
"storage/framework/views/twig"
"storage/app"
"storage/logs"
"storage/reports"
"bootstrap/cache"
)
for dir in "${DIRECTORIES[@]}"; do
# Create directory if it doesn't exist
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
echo "Created directory: $dir"
fi
# Add .gitignore file with !.gitignore content
if [ ! -f "$dir/.gitignore" ]; then
echo "!.gitignore" > "$dir/.gitignore"
echo "Created .gitignore in: $dir"
fi
done
echo "Laravel project directory initialized."