Skip to content

Instantly share code, notes, and snippets.

@notoriousturtle
Forked from markhatchell/new-cake
Last active May 21, 2017 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notoriousturtle/ea0198288ce46580aea09f11b1bfd01b to your computer and use it in GitHub Desktop.
Save notoriousturtle/ea0198288ce46580aea09f11b1bfd01b to your computer and use it in GitHub Desktop.
CakePHP 3 & Bootstrap 3 install and setup script
#!/bin/bash
# Install CakePHP3, with Bootstrap (and assets)
#
# Install:
# curl -L "https://gist.githubusercontent.com/[raw-gist-link]/new-cake" -onew-cake; chmod +x new-cake;
#
# Usage: new-cake [project_name]
#
# Requirements: curl, php, bower
echo "Updating composer" && \
curl -sS https://getcomposer.org/installer | php
echo "Creating CakePHP project";
php composer.phar create-project cakephp/app $1;
cd $1;
chmod +x bin/cake;
git init
echo "Adding general plugins in Composer";
../composer.phar require elboletaire/twbs-cake-plugin ~3.0;
../composer.phar require twbs/bootstrap ~3.0
echo "Adding general plugins to Bootstrap";
./bin/cake plugin load Bootstrap
./bin/cake plugin load Less
./bin/cake plugin load BootstrapUI
echo "Adding plugin helpers to AppController";
php -r '$d = file_get_contents("src/Controller/AppController.php"); $d=str_replace("class AppController extends Controller\n{","class AppController extends Controller\n{\n\n public \$helpers = [\n \"BootstrapUI.Form\",\n \"BootstrapUI.Html\",\n \"BootstrapUI.Flash\",\n \"BootstrapUI.Paginator\"\n ];",$d); file_put_contents("src/Controller/AppController.php",$d);';
echo "Updating AppView";
php -r '$d = file_get_contents("src/View/AppView.php"); $d=str_replace("use Cake\\View\\View", "use BootstrapUI\\View\\UIView", $d); $d=str_replace("class AppView extends View", "class AppView extends UIView", $d); $d=str_replace("public function initialize()\n {\n }", "public function initialize()\n {\n parent::initialize();\n }", $d); file_put_contents("src/View/AppView.php", $d);';
echo "Adding sample layout";
cp -R vendor/friendsofcake/bootstrap-ui/src/Template/Layout/examples src/Template/Layout/TwitterBootstrap
echo "Installing Bootstrap assets";
bower install bootstrap
mkdir -p webroot/css/bootstrap webroot/js/bootstrap webroot/js/jquery webroot/css/fonts
cp bower_components/bootstrap/dist/css/* webroot/css/bootstrap/.
cp bower_components/bootstrap/dist/js/* webroot/js/bootstrap/.
cp bower_components/jquery/dist/* webroot/js/jquery/.
cp bower_components/bootstrap/dist/fonts/* webroot/css/fonts/.
echo /bower_components >> .gitignore
git add .gitignore \
webroot/css/bootstrap \
webroot/js/bootstrap \
webroot/js/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment