Skip to content

Commit

Permalink
Merge pull request #39 from dekuan/dev
Browse files Browse the repository at this point in the history
version 1.0.17 was released
  • Loading branch information
dekuan authored Nov 4, 2016
2 parents 5771cf1 + c89d8c5 commit 2b46e1c
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 4 deletions.
Binary file modified ladep.phar
Binary file not shown.
6 changes: 6 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,11 @@
"sha1" : "df71adabaf487112fab8640acfdeea8ca7da29fe",
"url" : "https://github.com/dekuan/ladep/raw/1.0.16/ladep.phar",
"version" : "1.0.16"
},
{
"name" : "ladep.phar",
"sha1" : "8a1452e4fc9a7630360744f41f295db975859a0c",
"url" : "https://github.com/dekuan/ladep/raw/1.0.17/ladep.phar",
"version" : "1.0.17"
}
]
1 change: 1 addition & 0 deletions src/ladep/lang/usa.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
"error_create_env_file" => "Error in creating new env file.",
"error_chmod_file" => "Error in executing command chmod.",
"error_save_status" => "Error in saving status.",
"error_rebuild_classes_map" => "Error in rebuilding classes map.",
];
157 changes: 153 additions & 4 deletions src/ladep/models/CBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace dekuan\ladep\models;


use Symfony\Component\Process;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input;
Expand All @@ -10,6 +11,7 @@
use Symfony\Component\Console\Output\OutputInterface;

use dekuan\vdata;
use dekuan\delib\CLib;
use dekuan\ladep\libs;
use dekuan\ladep\models\classes;

Expand Down Expand Up @@ -149,6 +151,7 @@ public function Run( $arrParameter, callable $pfnCbFunc )
$pfnCbFunc( "info", "" );
}


//
// create .env for new release
//
Expand Down Expand Up @@ -414,6 +417,33 @@ public function Run( $arrParameter, callable $pfnCbFunc )
}


//
// Rebuild classes map
//
// execute:
// php artisan clear-compiled
// php artisan optimize
//
if ( $bContinue )
{
$bContinue = false;
$pfnCbFunc( 'info', sprintf( "Rebuild classes map" ) );
if ( $this->_RebuildClassesMap( $sDirNew, $pfnCbFunc ) )
{
$pfnCbFunc( "info", "Rebuild classes map successfully." );
$bContinue = true;
}
else
{
$sFormat = libs\Lang::Get( "error_rebuild_classes_map" );
$sErrorDesc = sprintf( $sFormat, $sRepoUrl );
$pfnCbFunc( "error", $sErrorDesc );
}
$pfnCbFunc( "info", "" );
$pfnCbFunc( "info", "" );
$pfnCbFunc( "info", "" );
}


// $bContinue = true;
// $sSrcDir = libs\Lib::GetLocalReleaseDir( $sProjectName ) . "/1.0.3-bak/";
Expand Down Expand Up @@ -466,6 +496,7 @@ public function Run( $arrParameter, callable $pfnCbFunc )
// $pfnCbFunc( "info", "" );
// }


//
// save status
//
Expand All @@ -475,7 +506,7 @@ public function Run( $arrParameter, callable $pfnCbFunc )
$pfnCbFunc( 'info', sprintf( "Saving building status" ) );
if ( $this->_SaveStatus( $sDirNew, 1, $pfnCbFunc ) )
{
$pfnCbFunc( "info", "Building status was saved successfully." );
$pfnCbFunc( "info", "Built status was saved successfully." );
$bContinue = true;
}
else
Expand Down Expand Up @@ -668,7 +699,7 @@ private function _ComposerInstall( $sReleaseDir, callable $pfnCbFunc )
$bRet = false;
$cComposer = new classes\CComposer();

$bCleanUp = $cComposer->CleanUpComposer($sReleaseDir, $pfnCbFunc );
$bCleanUp = $cComposer->CleanUpComposer( $sReleaseDir, $pfnCbFunc );
if ( $bCleanUp )
{
// ...
Expand Down Expand Up @@ -810,6 +841,126 @@ private function _ComposerUpdate( $sReleaseDir, callable $pfnCbFunc )
return $bRet;
}

//
// php artisan clear-compiled
// php artisan optimize
//
private function _RebuildClassesMap( $sReleaseDir, callable $pfnCbFunc )
{
return (
$this->_RunArtisanCommand( $sReleaseDir, "clear-compiled", $pfnCbFunc )
&&
$this->_RunArtisanCommand( $sReleaseDir, "optimize", $pfnCbFunc )
);
}

private function _RunArtisanCommand( $sReleaseDir, $sCommandName, callable $pfnCbFunc )
{
if ( ! CLib::IsExistingString( $sReleaseDir, true ) || ! is_dir( $sReleaseDir ) )
{
return false;
}
if ( ! CLib::IsExistingString( $sCommandName, true ) )
{
return false;
}

$bRet = false;
$cComposer = new classes\CComposer();

//
// "php artisan clear-compiled"
// "php artisan optimize"
//
$bCleanUp = $cComposer->CleanUpComposer( $sReleaseDir, $pfnCbFunc );
if ( $bCleanUp )
{
// save old dir
$sOldWorkingDir = getcwd();

// ...
chdir( $sReleaseDir );
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "info", sprintf( "Changed CWD to %s", $sReleaseDir ) );
}

// ...
$sCommand = sprintf( "php artisan %s", $sCommandName );
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "info", $sCommand );
}

$cProcess = new Process\Process( $sCommand, $sReleaseDir );
$cProcess
->setWorkingDirectory( $sReleaseDir )
->setTimeout( libs\Config::Get( 'cmd_timeout' ) )
->enableOutput()
->run( function( $sType, $sBuffer ) use ( $pfnCbFunc )
{
if ( Process\Process::OUT === $sType )
{
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "info", trim( $sBuffer ) );
}
}
else if ( Process\Process::ERR == $sType )
{
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "comment", trim( $sBuffer ) );
}
}
else
{
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "comment", trim( $sBuffer ) );
}
}

return true;
})
;

if ( $cProcess->isSuccessful() )
{
$bRet = true;
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "info", sprintf( "artisan %s successfully.", $sCommandName ) );
}
}
else
{
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "error", $cProcess->getErrorOutput() );
}
}


// change dir to old
chdir( $sOldWorkingDir );
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "info", sprintf( "Changed CWD to %s", $sOldWorkingDir ) );
}
}
else
{
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "error", "Falied to clean up composer.json" );
}
}

return $bRet;
}


private function _SetupConfigApp( $sReleaseDir, classes\CProject $cProject, callable $pfnCbFunc )
{
$cSetup = new classes\CSetup();
Expand Down Expand Up @@ -877,8 +1028,6 @@ private function _SaveStatus( $sReleaseDir, $bReady, callable $pfnCbFunc )
return $cStatus->SaveStatus( $sReleaseDir, $bReady );
}



private function _CompressAndInjectFilesIntoView( $sProjectName, $sVer, $arrOptions, callable $pfnCbFunc )
{
$cCompressor = new classes\CCompressAndInject();
Expand Down
27 changes: 27 additions & 0 deletions src/ladep/models/classes/CComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ private function _CleanUpComposer( $sReleaseDir, callable $pfnCbFunc = null )
$bModified = true;
unset( $arrJson[ 'scripts' ][ 'pre-update-cmd' ] );
}

//
// remove "require-dev":
// remove "autoload-dev":
//
if ( array_key_exists( 'require-dev', $arrJson ) )
{
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "comment", "Key require-dev was found." );
}

// ...
$bModified = true;
unset( $arrJson[ 'require-dev' ] );
}
if ( array_key_exists( 'autoload-dev', $arrJson ) )
{
if ( is_callable( $pfnCbFunc ) )
{
$pfnCbFunc( "comment", "Key autoload-dev was found." );
}

// ...
$bModified = true;
unset( $arrJson[ 'autoload-dev' ] );
}
}

if ( $bModified )
Expand Down

0 comments on commit 2b46e1c

Please sign in to comment.