Skip to content

Commit

Permalink
Merge pull request #17 from albinvar/dev
Browse files Browse the repository at this point in the history
Enhance creation of projects using helpers
  • Loading branch information
albinvar authored Jul 17, 2021
2 parents 24f9eb3 + 3e8fd23 commit d343c83
Show file tree
Hide file tree
Showing 22 changed files with 675 additions and 608 deletions.
9 changes: 4 additions & 5 deletions app/Commands/About.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace App\Commands;

use Illuminate\Console\Scheduling\Schedule;
use Laminas\Text\Figlet\Figlet;
use App\Helpers\Webzone;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;

class About extends Command
Expand All @@ -24,17 +23,17 @@ class About extends Command
* @var string
*/
protected $description = 'About Webzone';

public function __construct()
{
parent::__construct();
$this->webzone = new Webzone();
}

/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$this->about();
}
Expand Down
11 changes: 5 additions & 6 deletions app/Commands/ComposerGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace App\Commands;

use App\Helpers\Webzone;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use App\Helpers\Webzone;

class ComposerGlobal extends Command
{
Expand All @@ -30,19 +30,18 @@ class ComposerGlobal extends Command
* @var string
*/
protected $description = 'Init composer globally';

public function __construct()
{
parent::__construct();

$this->webzone = new Webzone();
}



/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$this->callSilently('settings:init');
$this->composer = config('pma.composer');
Expand Down
109 changes: 39 additions & 70 deletions app/Commands/Create/CakePHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace App\Commands\Create;

use App\Helpers\ComposerPackageInstaller;
use App\Helpers\Webzone;
use Illuminate\Console\Scheduling\Schedule;
use Laminas\Text\Figlet\Figlet;
use LaravelZero\Framework\Commands\Command;

class CakePHP extends Command
Expand All @@ -14,44 +15,25 @@ class CakePHP extends Command

protected $path;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'create:cakephp
{name?}
{name=blog}
{--path=}';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Create cakephp projects';

/**
* Execute the console command.
*/
public function handle(): mixed
public function handle(): void
{
$this->callSilently('settings:init');
$this->dir = $this->getData()['project_dir'];
$this->line(exec('clear'));
$this->logo();
$this->init();
}

public function getData()
{
$json_object = file_get_contents(config('settings.PATH') . '/settings.json');
return json_decode($json_object, true);
}
$this->installer = new ComposerPackageInstaller('CakePhP', 'cakephp');
$this->webzone = new Webzone();

public function logo(): void
{
$figlet = new Figlet();
$this->comment($figlet->setFont(config('logo.font'))->render('CakePHP'));
$this->webzone->clear();
$this->webzone->logo('CAKE PHP', 'comment');
$this->init();
}

/**
Expand All @@ -64,52 +46,39 @@ public function schedule(Schedule $schedule): void

private function init(): void
{
//name of project
if (! empty($this->argument('name'))) {
$this->name = $this->argument('name');
} else {
//planing to generate random names from a new package.
$this->name = 'cakephp-blog';
}

//set path
if (! empty($this->option('path'))) {
$this->path = $this->option('path');
} elseif (! empty($this->dir) && is_dir($this->dir)) {
$this->path = $this->dir;
} else {
$this->path = '/sdcard';
}

//check if directory exists
if (! $this->checkDir()) {
exit;
$path = $this->option('path');

$this->task('Setting up Installer', function () use ($path): void {
$this->installer->setProperties($this->argument('name'), $path);
$this->installer->setComposerPackage('cakephp/cakephp');
});

$this->task('Checking if project exists', function () {
if ($this->installer->checkIfProjectExists()) {
$this->status = false;
$this->newline(2);
$this->error('Project with same name already exists');
$this->newline();
return false;
}
$this->status = true;
return true;
});

if ($this->status) {
$this->install();
}
$this->line(exec('tput sgr0'));
$this->info('Creating CakePHP app');
$this->newline();
$this->create();
$this->newline();
$this->comment("CakePHP App created successfully on {$this->path}/{$this->name}");
}

private function checkDir()
private function install(): void
{
if (file_exists($this->path . '/' . $this->name)) {
$this->error('A duplicate file/directory found in the path. Please choose a better name.');
return false;
}
return true;
}

private function create(): void
{
$cmd = "cd {$this->path} && composer create-project --prefer-dist cakephp/app:~4.0 \"{$this->name}\"";
$this->exec($cmd);
}

private function exec($command): void
{
$this->line(exec($command));
$this->newline();
$this->info('Creating CakePHP Application...');
$this->newline();
$this->installer->install();
$this->newline();
$this->info(" 🎉 CakePHP app created successfully at {$this->installer->mainPath}/{$this->installer->name}. 🥳");
$this->newline();
$this->comment(' 🤙 Create Something Awesome 😉');
}
}
111 changes: 40 additions & 71 deletions app/Commands/Create/Codeigniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace App\Commands\Create;

use App\Helpers\ComposerPackageInstaller;
use App\Helpers\Webzone;
use Illuminate\Console\Scheduling\Schedule;
use Laminas\Text\Figlet\Figlet;
use LaravelZero\Framework\Commands\Command;

class Codeigniter extends Command
Expand All @@ -14,44 +15,25 @@ class Codeigniter extends Command

protected $path;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'create:codeigniter
{name?}
{name=blog}
{--path=}';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Create Codeigniter projects';
protected $description = 'Create CodeIgniter projects';

/**
* Execute the console command.
*/
public function handle(): mixed
public function handle(): void
{
$this->callSilently('settings:init');
$this->dir = $this->getData()['project_dir'];
$this->line(exec('clear'));
$this->logo();
$this->init();
}

public function getData()
{
$json_object = file_get_contents(config('settings.PATH') . '/settings.json');
return json_decode($json_object, true);
}
$this->installer = new ComposerPackageInstaller('CodeIgniter', 'codeigniter');
$this->webzone = new Webzone();

public function logo(): void
{
$figlet = new Figlet();
$this->comment($figlet->setFont(config('logo.font'))->render('Codeigniter'));
$this->webzone->clear();
$this->webzone->logo('CodeIgniter', 'comment');
$this->init();
}

/**
Expand All @@ -64,52 +46,39 @@ public function schedule(Schedule $schedule): void

private function init(): void
{
//name of project
if (! empty($this->argument('name'))) {
$this->name = $this->argument('name');
} else {
//planing to generate random names from a new package.
$this->name = 'codeigniter_project';
}

//set path
if (! empty($this->option('path'))) {
$this->path = $this->option('path');
} elseif (! empty($this->dir) && is_dir($this->dir)) {
$this->path = $this->dir;
} else {
$this->path = '/sdcard';
}

//check if directory exists
if (! $this->checkDir()) {
exit;
$path = $this->option('path');

$this->task('Setting up Installer', function () use ($path): void {
$this->installer->setProperties($this->argument('name'), $path);
$this->installer->setComposerPackage('codeigniter4/appstarter');
});

$this->task('Checking if project exists', function () {
if ($this->installer->checkIfProjectExists()) {
$this->status = false;
$this->newline(2);
$this->error('Project with same name already exists');
$this->newline();
return false;
}
$this->status = true;
return true;
});

if ($this->status) {
$this->install();
}
$this->line(exec('tput sgr0'));
$this->info('Creating Codeigniter app');
$this->newline();
$this->create();
$this->newline();
$this->comment("Codeigniter App created successfully on {$this->path}/{$this->name}");
}

private function checkDir()
private function install(): void
{
if (file_exists($this->path . '/' . $this->name)) {
$this->error('A duplicate file/directory found in the path. Please choose a better name.');
return false;
}
return true;
}

private function create(): void
{
$cmd = "cd {$this->path} && composer create-project codeigniter4/appstarter \"{$this->name}\"";
$this->exec($cmd);
}

private function exec($command): void
{
$this->line(exec($command));
$this->newline();
$this->info('Creating CodeIgniter Application...');
$this->newline();
$this->installer->install();
$this->newline();
$this->info(" CodeIgniter app created successfully at {$this->installer->mainPath}/{$this->installer->name}. ");
$this->newline();
$this->comment(' Create Something Awesome ');
}
}
Loading

0 comments on commit d343c83

Please sign in to comment.