summaryrefslogtreecommitdiff
path: root/generator/make.sh
blob: ebd720ee1a46fa66fb722d69c68beb0ff82f20f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash -x
# Copyright 2016 Ludovic Pouzenc <ludovic@pouzenc.fr>
# Copyright 2016 Nicolas Goaziou <mail@nicolasgoaziou.fr>
# 
# This file is part of CHD Gestion.
# 
# CHD Gestion is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# CHD Gestion is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with CHD Gestion.  If not, see <http://www.gnu.org/licenses/>.
# 
this=$(readlink -f $0)
src_dir=$(dirname $this)

cd /var/www

# Sauver la précédente fournée
if [ -d chd_gestion ]
then [ -d chd_gestion.bkp ] && rm -r chd_gestion.bkp/
	mv chd_gestion chd_gestion.bkp
fi

# Installer un nouveau CakePHP ( http://book.cakephp.org/3.0/en/quickstart.html#getting-cakephp )
[ -f composer.phar ] || wget https://getcomposer.org/composer.phar

mkdir chd_gestion
cd chd_gestion || exit

ln -s ../composer.phar
# Personnaliser les dépendances (forcer CakePHP 3.1.10)
cp -a "$src_dir/composer.json" .
# Deployer un squellette d'appli (avec les dépendances)
yes | php composer.phar create-project
# Cakephp/app nous sert de base, mais a été installé comme dépendance à cause de l'utilisation du composer.json
rsync -ai --exclude **/empty ./vendor/cakephp/app/ .

# Ajouter PHPUnit ( http://book.cakephp.org/3.0/en/development/testing.html#installing-phpunit )
#php composer.phar require --dev phpunit/phpunit:5.*
# Ajouter le plugin Search ( https://github.com/FriendsOfCake/search )
#php composer.phar require friendsofcake/search "dev-master"

# Ajouter un theme pour altérer le comportement de bake (http://book.cakephp.org/3.0/en/bake/development.html#creating-a-bake-theme )
yes | bin/cake bake plugin CustomTheme

# Paramétrer le français en langue par défaut ( http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#setting-the-default-locale )
sed --in-place -e "s/ini_set('intl.default_locale', '[^']*')/ini_set('intl.default_locale', 'fr_FR')/" config/bootstrap.php

# Page d'accueil = Liste des adhérents (http://book.cakephp.org/3.0/en/development/routing.html#quick-tour )
sed --in-place -e "s#connect('/', [^)]\\+)#connect('/', ['controller' => 'Adherents', 'action' => 'index'])#" config/routes.php

cat >> config/bootstrap.php <<"EOT"
# Ajouter des pluriel irréguliers vu de la langue anglaise
# http://book.cakephp.org/3.0/en/core-libraries/inflector.html#loading-custom-inflections
Inflector::rules('uninflected', ['ipmgmt']);
Inflector::rules('uninflected', ['relais']);
Inflector::rules('irregular', ['interesse' => 'interesses']);

# Ne pas afficher les heures par défaut
use Cake\I18n\Time;
Time::setToStringFormat([IntlDateFormatter::SHORT, -1]);
EOT

# Ajout des personnalisations qui s'expriment pas facilement dans un script
rsync -ai "$src_dir/before-bake/" ./

# Génération de l'ensemble du CRUD ( http://book.cakephp.org/3.0/en/bake/usage.html )
for table in $(bin/cake bake all | sed -ne 's/^- \(.*\)$/\1/p' | grep -vE '^v_')
do
	yes | bin/cake bake all --theme=CustomTheme $table
done

# Ecarsement de certains modèles générés
rsync -aib --backup-dir=../src.orig "$src_dir/after-bake/src/" ./src/