Skip to content

Commit

Permalink
fix for dir remake commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpeterson committed Jun 30, 2014
1 parent 2b93b45 commit 6e85c77
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Artistan/Workbench/Commands/DevelopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DevelopCommand extends Command {
public function __construct()
{
parent::__construct();
$this->benchhelper = new BenchHelper();
$this->benchhelper = new BenchHelper($this);
}

/**
Expand Down
14 changes: 6 additions & 8 deletions src/Artistan/Workbench/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class InstallCommand extends Command {
public function __construct()
{
parent::__construct();
$this->benchhelper = new BenchHelper();
$this->benchhelper = new BenchHelper($this);
}

/**
Expand All @@ -56,12 +56,11 @@ public function fire()
}
}
foreach($packages as $name=>$package){
echo "PACKAGE: $name\n";
$this->info( "PACKAGE: $name" );
if(isset($package['git'])){
$this->benchhelper->mkdir($name);
$action = $this->benchhelper->getGit($name,$package);
if($this->option('remote')){
echo "remotes\n";
$this->info( "remotes" );
$this->benchhelper->fetchRemotes($name,$package['remotes']);
}
if($this->option('merge')){
Expand All @@ -78,10 +77,10 @@ public function fire()
}
if($this->option('publishConfigs') || $action=='install'){
// this should not be done all the time, first time only (install)
$this->call('config:publish', array('argument' => $name, '--path' => 'workbench/'.$name.'/src/config'));
$this->call('config:publish', array('package' => $name, '--path' => 'workbench/'.$name.'/src/config'));
}
}
echo "============================\n\n\n";
$this->info( "============================" );
}
if(!$this->option('skipBower')){
$this->benchhelper->bower();
Expand All @@ -91,7 +90,6 @@ public function fire()
// remove any packages from vendors directory that you are workbenching
$this->benchhelper->composerVendorCleanup(array_keys($packages));
}
//$this->call('command:name', array('argument' => 'foo', '--option' => 'bar'));
}

/**
Expand All @@ -115,7 +113,7 @@ protected function getOptions()
{
return array(
array('destroy','d', InputOption::VALUE_NONE, 'Destroy current packages.'),
array('upstream','u', InputOption::VALUE_NONE, 'Fetch upstream.'),
array('remote','r', InputOption::VALUE_NONE, 'Fetch upstream.'),
array('merge','m', InputOption::VALUE_OPTIONAL, 'Merge upstream into this branch.'),
array('skipComposer','c', InputOption::VALUE_NONE, 'skip composer install/update'),
array('skipBower','b', InputOption::VALUE_NONE, 'skip bower install/update'),
Expand Down
2 changes: 1 addition & 1 deletion src/Artistan/Workbench/Commands/LaunchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LaunchCommand extends Command {
public function __construct()
{
parent::__construct();
$this->benchhelper = new BenchHelper();
$this->benchhelper = new BenchHelper($this);
}

/**
Expand Down
51 changes: 33 additions & 18 deletions src/Artistan/Workbench/Helpers/BenchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@
namespace Artistan\Workbench\Helpers;

class BenchHelper {


/**
* The console command object.
*
* @var InstallCommand
*/
protected $cmd = false;

public function __construct(&$command){
$this->cmd = $command;
}
/**
* destroys all workbench packages
*/
public function destroy($packages) {
echo "removing all configured packages\n";
$this->cmd->info( "removing all configured packages" );
foreach($packages as $name){
// check if exists, also do not remove artistan/workbench cause I am working on it!!!
if(is_dir(base_path().'/workbench/'.$name) && $name!='artistan/workbench'){
$this->exec('rm -rf '.base_path().'/workbench/'.$name);
while( is_dir( base_path().'/workbench/'.$name) && $name!='artistan/workbench' ){
$path = explode('/',$name);
$this->exec( 'rm -rf '.base_path().'/workbench/'.$path[0] );
clearstatcache ( true, base_path().'/workbench/'.$name );
}
}
}
Expand All @@ -26,12 +40,13 @@ public function chStorage(){
* @throws Exception
*/
public function mkdir($name) {
echo "make dir $name\n";
$this->cmd->info( "make dir $name" );
if(!empty($name)){
//$this->call('command:name', array('argument' => 'foo', '--option' => 'bar'));
if(is_dir(base_path().'/workbench/'.$name)){
$this->cmd->error( "dir $name exists" );exit;
return true;
} else {
$this->cmd->error( "dir $name make" );
return mkdir(base_path().'/workbench/'.$name,0777,true);
}
} else {
Expand All @@ -45,7 +60,7 @@ public function mkdir($name) {
* @throws Exception
*/
public function composer($name='',$action='') {
echo "composer $name\n";
$this->cmd->info( "composer $name" );
if(!empty($name) && !empty($action)){
if(is_dir(base_path().'/workbench/'.$name)){
chdir(base_path().'/workbench/'.$name);
Expand All @@ -67,7 +82,7 @@ public function composer($name='',$action='') {
* @param $packages
*/
public function composerVendorCleanup($packages) {
echo "composerVendorCleanup\n";
$this->cmd->info( "composerVendorCleanup" );
foreach($packages as $name){
if(is_dir(base_path().'/vendor/'.$name)){
$this->exec('rm -rf '.base_path().'/vendor/'.$name);
Expand All @@ -80,7 +95,7 @@ public function composerVendorCleanup($packages) {
* @throws Exception
*/
public function bower($name='') {
echo "bower $name\n";
$this->cmd->info( "bower $name" );
if(!empty($name)){
if(is_dir(base_path().'/workbench/'.$name)){
chdir(base_path().'/workbench/'.$name);
Expand All @@ -106,9 +121,9 @@ public function bower($name='') {
* @throws Exception
*/
public function getGit($name,array $package) {
echo "get git $name\n";
$this->cmd->info( "get git $name" );
if(!empty($package['git'])){
//$this->call('command:name', array('argument' => 'foo', '--option' => 'bar'));
$this->mkdir($name);
chdir(base_path().'/workbench/'.$name);
if(is_dir('.git')){
// just git pull
Expand All @@ -131,8 +146,8 @@ public function getGit($name,array $package) {
public function mergeRemote($merge){
if($merge){
$this->exec('git merge '.$merge);
} else {
echo "No remote merge requested\n";
} else {
$this->error( "No remote merge requested" );
}
}

Expand All @@ -142,9 +157,8 @@ public function fetchRemotes($name,array $remotes){
}
}
public function getRemote($name,$remoteName,$location){
echo "get git $name :: $remoteName\n";
$this->cmd->info( "get git $name :: $remoteName" );
if(!empty($location)){
//$this->call('command:name', array('argument' => 'foo', '--option' => 'bar'));
chdir(base_path().'/workbench/'.$name);
if(is_dir('.git')){
if(!$this->verifyRemote($name,$remoteName)){
Expand All @@ -161,7 +175,7 @@ public function getRemote($name,$remoteName,$location){
}
}

public function verifyUpstream($name,$remoteName){
public function verifyRemote($name,$remoteName){
chdir(base_path().'/workbench/'.$name);

$str = shell_exec('git remote -v');
Expand All @@ -170,10 +184,11 @@ public function verifyUpstream($name,$remoteName){

// http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php
/**
* @param string $cmd
* @param $cmd
* @param bool $echo
*/
public function exec($cmd,$echo=true){
echo "Command: $cmd\n";
$this->cmd->info( "Command: $cmd" );
if($echo){
$descriptor_spec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
Expand All @@ -194,7 +209,7 @@ public function exec($cmd,$echo=true){
}

public function error($message,$exit=false){
echo $message."\n";
$this->cmd->info( "$message" );
if($exit){
exit;
}
Expand Down

0 comments on commit 6e85c77

Please sign in to comment.