-
-
Save kennethrapp/701c275ff0a2349fc51f to your computer and use it in GitHub Desktop.
composer.sh - quick and dirty shell for starting a composer project
This file contains 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 | |
# default psr-0 app directory | |
psr_0='App' | |
# default filenames and composer.json content | |
c_phar='composer.phar' | |
c_lock='composer.lock' | |
c_json='composer.json' | |
# default composer.json with no dependencies | |
cjd='{\n | |
\t"autoload":{\n | |
\t\t"psr-0":{\n | |
\t\t\t"'$psr_0'": "src/"\n | |
\t\t}\n | |
\t}\n | |
}' | |
# default routing .htaccess file | |
hta=' | |
<IfModule mod_rewrite.c>\n | |
Options -MultiViews\n | |
RewriteEngine On\n | |
RewriteCond %{REQUEST_FILENAME} !-d\n | |
RewriteCond %{REQUEST_FILENAME} !-f\n | |
RewriteRule ^ index.php [L]\n | |
</IfModule>' | |
#default index.php | |
index_php='<\?php\n | |
require_once("../vendor/autoload.php");\n' | |
# if composer doesn't exist, install it, recurse | |
if [ ! -f "$c_phar" ]; then | |
curl -s https://getcomposer.org/installer | php | |
composer.sh | |
else | |
echo "composer.phar exists." | |
#composer exists, but there is no composer.json - create a default | |
if [ ! -f "$c_json" ]; then | |
echo "creating composer.json..." | |
echo -e $cjd >> $c_json | |
else | |
echo "composer.json found." | |
fi; | |
#create the project directory if it doesn't exist | |
mkdir -p "src/$psr_0" | |
#update composer (unnecessary if we also just downloaded it though) | |
php composer.phar self-update | |
# if composer.lock exists, update, otherwise, install dependencies | |
if [ -f "$c_lock" ]; then | |
php "$c_phar" update | |
else | |
php "$c_phar" install | |
fi | |
mkdir -p "public"; | |
if [ ! -f "public/index.php" ]; then | |
echo -e $index_php >> "public/index.php"; | |
echo -e $hta >> "public/.htaccess"; | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment