Hello guys, I usually start a project using composer to have the appstarter, and add libraries like phpmailler. I want to have my CI4 always updated so I come with this little script using composer that I think that could be very useful:
composer.json
Code:
{
"name": "codeigniter4/appstarter",
"description": "CodeIgniter4 starter app",
"license": "MIT",
"type": "project",
"homepage": "https://codeigniter.com",
"support":
{
"forum": "https://forum.codeigniter.com/",
"source": "https://github.com/codeigniter4/CodeIgniter4",
"slack": "https://codeigniterchat.slack.com"
},
"require":
{
"php": "^8.1",
"codeigniter4/framework": "^4.0",
"codeigniter4/translations": "*",
"dompdf/dompdf": "^3.0",
"phpmailer/phpmailer": "^6.9",
"twbs/bootstrap": "^5.3"
},
"require-dev":
{
"fakerphp/faker": "^1.9",
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^10.5.16"
},
"autoload":
{
"psr-4":
{
"App\\": "app/",
"Config\\": "app/Config"
},
"exclude-from-classmap":
[
"**/Database/Migrations/**"
]
},
"autoload-dev":
{
"psr-4":
{
"Tests\\Support\\": "tests/_support"
}
},
"config":
{
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"scripts":
{
"test": "phpunit",
"post-install-cmd":
[
"@updatebootstrap",
"@updateci"
],
"post-update-cmd":
[
"@updatebootstrap",
"@updateci"
],
"updatebootstrap":
[
"php updatebootstrap.php"
],
"updateci":
[
"php updateci.php"
]
}
}
updatebootstrap.php
PHP Code:
<?php
//Inicio copiar CSS do bootstrap
$arr_orig = ['vendor','twbs','bootstrap','dist','css'];
$origem = join( DIRECTORY_SEPARATOR, $arr_orig ) . DIRECTORY_SEPARATOR . "*.*";
$arr_dest = ['public','css','bootstrap'];
$destino = join( DIRECTORY_SEPARATOR, $arr_dest );
//echo($origem);
if( DIRECTORY_SEPARATOR == '/')
{
exec("cp -r " . $origem . " " . $destino);
}
else
{
exec("copy " . $origem . " " . $destino);
}
//Fim copiar CSS do bootstrap
//Inicio copiar JS do bootstrap
$arr_orig = ['vendor','twbs','bootstrap','dist','js'];
$origem = join( DIRECTORY_SEPARATOR, $arr_orig ) . DIRECTORY_SEPARATOR . "*.*";
$arr_dest = ['public','js','bootstrap'];
$destino = join( DIRECTORY_SEPARATOR, $arr_dest );
//echo($origem);
if( DIRECTORY_SEPARATOR == '/' )
{
exec("cp -r " . $origem . " " . $destino);
}
else
{
exec("copy " . $origem . " " . $destino);
}
//Fim copiar JS do bootstrap
?>
updateci.php
PHP Code:
<?php
//criar pasta para backup
if( ! is_dir('bknc') )
{
exec( "mkdir bknc" );
}
else{
echo("ja existe a bknc" . PHP_EOL);
}
//copiar ficheiros do ci
if( DIRECTORY_SEPARATOR == '/' )
{
exec('cp app/Config/App.php bknc/App.php');
exec('cp app/Controllers/BaseController.php bknc/BaseController.php');
exec('cp app/Config/Constants.php bknc/Constants.php');
exec('cp app/Config/Database.php bknc/Database.php');
exec('cp app/Config/Filters.php bknc/Filters.php');
exec('cp app/Config/Logger.php bknc/Logger.php');
exec('cp app/Config/Routes.php bknc/Routes.php');
exec('cp app/Config/Session.php bknc/Session.php');
exec('cp composer.json bknc/composer.json');
exec('cp -TR vendor/codeigniter4/framework/ . ');
exec('cp -TR vendor/codeigniter4/translations/Language ./app/Language/');
exec('chmod -R 775 writable/debugbar');
//inicio repor ficheiros de bknc
exec('cp bknc/App.php app/Config/App.php ');
exec('cp bknc/BaseController.php app/Controllers/BaseController.php ');
exec('cp bknc/Constants.php app/Config/Constants.php ');
exec('cp bknc/Database.php app/Config/Database.php ');
exec('cp bknc/Filters.php app/Config/Filters.php ');
exec('cp bknc/Logger.php app/Config/Logger.php ');
exec('cp bknc/Routes.php app/Config/Routes.php ');
exec('cp bknc/Session.php app/Config/Session.php ');
exec('cp bknc/composer.json composer.json ');
//fim repor ficheiros de bknc
exec('rm -rf bknc/*.*');
}
else
{
exec('copy app\\Config\\App.php bknc\\App.php /Y');
exec('copy app\\Controllers\\BaseController.php bknc\\BaseController.php /Y');
exec('copy app\\Config\\Constants.php bknc\\Constants.php /Y');
exec('copy app\\Config\\Database.php bknc\\Database.php /Y');
exec('copy app\\Config\\Filters.php bknc\\Filters.php /Y');
exec('copy app\\Config\\Logger.php bknc\\Logger.php /Y');
exec('copy app\\Config\\Routes.php bknc\\Routes.php /Y');
exec('copy app\\Config\\Session.php bknc\\Session.php /Y');
exec('copy composer.json bknc\\composer.json /Y');
exec('xcopy vendor\\codeigniter4\\framework\\ . /S /Y');
exec('xcopy vendor\\codeigniter4\\translations\\Language\\. .\\app\\Language\\ /S /Y');
//repor ficheiros
exec('copy bknc\\App.php app\\Config\\App.php /Y');
exec('copy bknc\\BaseController.php app\\Controllers\\BaseController.php /Y');
exec('copy bknc\\Constants.php app\\Config\\Constants.php /Y');
exec('copy bknc\\Database.php app\\Config\\Database.php /Y');
exec('copy bknc\\Filters.php app\\Config\\Filters.php /Y');
exec('copy bknc\\Logger.php app\\Config\\Logger.php /Y');
exec('copy bknc\\Routes.php app\\Config\\Routes.php /Y');
exec('copy bknc\\Session.php app\\Config\\Session.php /Y');
exec('copy bknc\\composer.json composer.json /Y');
}
?>
I hope that this could be helpful for yours projects
Cheers!