Last active
September 23, 2016 16:49
-
-
Save jeffersonmartin/77c1087714b22a816c049c6654cc07f4 to your computer and use it in GitHub Desktop.
When developing applications, you spend 95% of your time working with models, views, and controllers. However, these respective directories are buried deep in the Laravel application directory structure. This script creates a project folder with symlink folders for Laravel controllers, models, and views for a specific Github repository. This all…
This file contains hidden or 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 | |
# | |
# Laravel MVC Project Symlink Script | |
# @author Jefferson Martin <github.com/jeffersonmartin> | |
# | |
# When developing applications, you spend 95% of your time working with models, | |
# views, and controllers. However, these respective directories are buried deep | |
# in the Laravel application directory structure. Although we could create a | |
# different directory structure, it requires a lot of changes to Service Providers | |
# and configuration files that can be difficult for other developers to get their | |
# head around when they expect the default Laravel directory structure. | |
# | |
# This script creates a project folder with symlink folders for controllers, | |
# models, and views for a specific Github repository. This allows you to open | |
# your project folder in your text editor and only see the controllers, models, | |
# views, and routes, but none of the extra directories that you rarely touch. | |
# | |
# Example Usage: | |
# ./laravel-project-symlink.sh account-name repository-name | |
# | |
# Define account-name and repository-name from CLI arguments | |
ACCOUNT_NAME=$1 | |
REPOSITORY_NAME=$2 | |
# Environment: What base directory do you want to use for symlinked project files? | |
ENV_PROJECT_DIR='/Users/jefferson/Projects' | |
# Environment: What directory structure do you use for cloned git repositories? | |
ENV_GIT_DIR="/Users/jefferson/Sites/${ACCOUNT_NAME}/${REPOSITORY_NAME}" | |
# Laravel: What directory are your controllers located in? | |
LARAVEL_CONTROLLERS_DIR='app/Http/Controllers' | |
# Laravel: Where is your routes file located? You can change this to a directory if needed. | |
LARAVEL_ROUTES_FILE='app/Http/routes.php' | |
# Laravel: What directory are your models located in? | |
LARAVEL_MODELS_DIR='app/*.php' | |
# Laravel: What directory are your views located in? | |
LARAVEL_VIEWS_DIR='resources/views' | |
# | |
# Create Directory Structure & Symlinks | |
# | |
echo '' | |
echo 'Laravel MVC Project Symlink Script' | |
echo "Account: ${ACCOUNT_NAME}" | |
echo "Repository: ${REPOSITORY_NAME}" | |
echo '' | |
echo 'Creating directory structure for symlinked projects' | |
echo ${ENV_PROJECT_DIR} | |
mkdir ${ENV_PROJECT_DIR} | |
echo '' | |
echo 'Create directory structure for Git account and repository' | |
echo ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME} | |
mkdir -p ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME} | |
echo '' | |
echo 'Create symlink for Laravel controllers' | |
echo ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/controllers | |
ln -s ${ENV_GIT_DIR}/${LARAVEL_CONTROLLERS_DIR} ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/controllers | |
echo '' | |
echo 'Create symlink for Laravel models' | |
echo ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/models | |
mkdir ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/models | |
ln -s ${ENV_GIT_DIR}/${LARAVEL_MODELS_DIR} ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/models | |
echo '' | |
echo 'Create symlink for Laravel views' | |
echo ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/views | |
ln -s ${ENV_GIT_DIR}/${LARAVEL_VIEWS_DIR} ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/views | |
echo '' | |
echo 'Create symlink for Laravel routes' | |
ln -s ${ENV_GIT_DIR}/${LARAVEL_ROUTES_FILE} ${ENV_PROJECT_DIR}/${ACCOUNT_NAME}/${REPOSITORY_NAME}/ | |
echo '' | |
echo 'Script complete' | |
echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a screenshot of the simpler directory structure.