You are not logged in.
I'm a software developer in Toronto.
I like Foundation/SASS for adaptive mobile first web development. I also happen to be very fond of Laravel for rapid PHP development.
If you are like me, you may find a pain having to issue a bunch of commands every time you need to create a new project. Not to mention having to edit all the configuration files for both, Foundation and Laravel to get the directory structure "the way you like it". Overtime, I got tired of it and decided to write a script to automate this process.
The directory structure I use is the default Laravel's install, eg:
myApp |
|- app
|- public
|- vendor
and inside the public directory I set the Foundation framework. Therefore it looks like this:
myApp |
|- app
|- public-|
| |- assets -|
| |- css
| |- fonts
| |- scss |
| | |- partials
| |
| |- js
|- images
|- vendor
This is the script:
#!/bin/bash
# ====================================+
# Creates a new Laravel project using Foundation 5.0
# Copies template files and sets directory structures
# as per ITTwo development standards.
#====================================+
WEBROOT=/srv/http;
OWNER=ralvez;
DEVAREA=/home/$OWNER/HTML;
TEMPLATE_FILES=$DEVAREA/dev.foundation;
clear
echo +===================================================+
echo " LAMP Project Builder (Laravel/Foundation) "
echo +===================================================+
echo
# verify that the dev.template directory exists
if [ -d $TEMPLATE_FILES ]; then
PROJECT_NAME=$1;
if [ -z "$1" ]; then
echo "Missing project name"
exit;
fi
echo "1. Creating Laravel Project: "$PROJECT_NAME
echo
composer.phar create-project laravel/laravel $DEVAREA/$PROJECT_NAME &&
foundation new $DEVAREA/$PROJECT_NAME/_public
# Create my development environment
cd $DEVAREA/$PROJECT_NAME
mv public/.htaccess _public/.htaccess
mv public/index.php _public/index.php
mv public/robots.txt _public/robots.txt
rm -fr public && mv _public public
mkdir public/packages
# Arrange directory structure
cd public
mkdir -p images/icons images/sprites
mkdir -p assets/fonts assets/css
# Move files into my directory structure
mv js/app.js js/master.js
mv js assets/js
mv scss assets/scss
# Create partials directory
mkdir assets/scss/partials
# Create default partial files
for partial in variables base layouts mixins fonts modules;
do
touch assets/scss/partials/_$partial.scss;
done
# Move existing files into partials
mv assets/scss/app.scss assets/scss/master.scss
mv assets/scss/_*.scss assets/scss/partials
cd .. # go back to the app root directory
echo "2. Getting template files"
echo
echo " a. index, template and hidden files ..."
echo
cp $TEMPLATE_FILES/index.html $DEVAREA/$PROJECT_NAME/public
cp $TEMPLATE_FILES/.gitignore $DEVAREA/$PROJECT_NAME/.gitignore
cp $TEMPLATE_FILES/Guardfile $DEVAREA/$PROJECT_NAME/app/Guardfile
echo " b. config.rb"
echo
cp $TEMPLATE_FILES/config.rb $DEVAREA/$PROJECT_NAME/public/config.rb
echo " c. $TEMPLATE_FILES/master.scss "
echo
cp $TEMPLATE_FILES/master.scss $DEVAREA/$PROJECT_NAME/public/assets/scss/master.scss
echo " d. Initialize Git project"
echo
cd $DEVAREA/$PROJECT_NAME
if [ -f ".git" ]; then
rm -fr .git
fi;
# Initialize git for this project
git init
git add .
git commit -m 'Initial Commit'
echo " f. Prevent sending log in data into repo ..."
git update-index --assume-unchanged $DEVAREA/$PROJECT_NAME/app/config/database.php
echo "3. Setting permissions on "$DEVAREA/$PROJECT_NAME/"app/storage"
echo
chmod -R 757 $DEVAREA/$PROJECT_NAME/app/storage
echo "4. Creaging symlink to $DEVAREA/$PROJECT_NAME/public in the web server"
echo
su root -c "ln -s $DEVAREA/$PROJECT_NAME/public $WEBROOT/$PROJECT_NAME"
if [ $? -ne 0 ]; then
exit;
fi
clear
echo "+----------------------------------------------------------------+"
echo " All done!"
echo "A. Edit "/home/$OWNER/HTML/$PROJECT_NAME"/app/config/database.php"
echo " and set your database password as needed."
echo "C. Remember to run compass watch and guard"
echo "+----------------------------------------------------------------+"
else
echo "Missing directory "$HOME "/HTML/$TEMPLATE_FILES"
fi
For the setup as I have described, these are my config.rb and master.scss which I keep in my development directory in a folder I call dev.foundation
config.rb :
# Require any additional compass plugins here.
add_import_path "bower_components/foundation/scss"
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "assets/css"
sass_dir = "assets/scss"
javascripts_dir = "assets/js"
fonts_dir = "assets/fonts"
images_dir = "images"
# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
output_style = :expanded
# To enable relative paths to assets via compass helper functions. Uncomment:
relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = false
# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
master.scss:
@import "partials/settings";
@import "partials/fonts";
@import "foundation";
@import "partials/variables";
@import "partials/base";
@import "partials/layouts";
@import "partials/modules";
Now this is of course tailored to the way I like my code structured, if you like it different (I can't imagine why ) just edit the master.scss and config.rb to your coding stile and you are on you way.
The main script is, or so I think , easy to understand but I'll be happy to answer questions if anyone has them.
You may also want to add other files to your template directory (dev.foundation) like I did (you will see that in the code) and that can be easily done by editing the main script. I've left the code in place so you can use it as an example, but if you do not need it just comment the lines and you are set.
BTW, I'm not a bash-fu coder, if you see improvements to the code let me know.
I hope this will help some other developers.
Enjoy!!
R.
p.s: If someone wants a tar file with the scripts and my current development setup I'll be happy to put a link to a public server.
Offline