Skip to content

Commit

Permalink
Merge pull request #88 from tightenco/pr/83
Browse files Browse the repository at this point in the history
Re-attempt to merge Jon's work in for Lambo stuff
  • Loading branch information
mattstauffer authored Mar 20, 2020
2 parents 2ea9fa9 + e626685 commit 0204d42
Show file tree
Hide file tree
Showing 69 changed files with 2,323 additions and 322 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
.phpunit.result.cache
/storage/framework/
42 changes: 42 additions & 0 deletions app/Actions/CompileAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Actions;

use App\Shell\Shell;

class CompileAssets
{
use LamboAction;

protected $shell;
protected $silentDevScript;

public function __construct(Shell $shell, SilentDevScript $silentDevScript)
{
$this->shell = $shell;
$this->silentDevScript = $silentDevScript;
}

public function __invoke()
{
if (! config('lambo.store.mix')) {
return;
}

$this->silentDevScript->add();

$this->logStep('Compiling project assets');

$process = $this->shell->execInProject("npm run dev{$this->extraOptions()}");

$this->abortIf(! $process->isSuccessful(), 'Compilation of project assets did not complete successfully', $process);

$this->silentDevScript->remove();

$this->info('Project assets compiled successfully.');
}
public function extraOptions()
{
return config('lambo.store.with_output') ? '' : ' --silent';
}
}
37 changes: 37 additions & 0 deletions app/Actions/ConfigureFrontendFramework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Actions;

use App\Shell\Shell;

class ConfigureFrontendFramework
{
use LamboAction;

private $shell;

private $laravelUi;

public function __construct(Shell $shell, LaravelUi $laravelUi)
{
$this->shell = $shell;
$this->laravelUi = $laravelUi;
}

public function __invoke()
{
if (! config('lambo.store.frontend')) {
return;
}

$this->laravelUi->install();

$this->logStep('Configuring frontend scaffolding');

$process = $this->shell->execInProject('php artisan ui ' . config('lambo.store.frontend'));

$this->abortIf(! $process->isSuccessful(), "Installation of UI scaffolding did not complete successfully.", $process);

$this->info('UI scaffolding has been set to ' . config('lambo.store.frontend'));
}
}
46 changes: 45 additions & 1 deletion app/Actions/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,54 @@

namespace App\Actions;

use App\Shell\Shell;
use Illuminate\Support\Str;
use Symfony\Component\Process\ExecutableFinder;

class CreateDatabase
{
use LamboAction;

protected $finder;
protected $shell;

public function __construct(Shell $shell, ExecutableFinder $finder)
{
$this->finder = $finder;
$this->shell = $shell;
}

public function __invoke()
{
// @todo
if (! config('lambo.store.create_database')) {
return;
}

if (! $this->mysqlExists()) {
return "MySQL does not seem to be installed. Skipping new database creation.";
}

$this->logStep('Creating database');

$process = $this->shell->execInProject($this->command());

$this->abortIf(! $process->isSuccessful(), "The new database was not created.", $process);

return 'Created a new database ' . config('lambo.store.database_name');
}

protected function mysqlExists()
{
return $this->finder->find('mysql') !== null;
}

protected function command()
{
return sprintf(
'mysql --user=%s --password=%s -e "CREATE DATABASE IF NOT EXISTS %s";',
config('lambo.store.database_username'),
config('lambo.store.database_password'),
config('lambo.store.database_name')
);
}
}
19 changes: 9 additions & 10 deletions app/Actions/CustomizeDotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

namespace App\Actions;

use Facades\App\Utilities;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;

class CustomizeDotEnv
{
use LamboAction;

public function __invoke()
{
$this->logStep('Customizing .env and .env.example');

$filePath = config('lambo.store.project_path') . '/.env.example';

$output = $this->customize(File::get($filePath));

File::put($filePath, $output);
File::put(str_replace('.env.example', '.env', $filePath), $output);

$this->info('.env files configured.');
}

public function customize($contents)
Expand All @@ -41,17 +46,11 @@ public function value($key, $fallback)
$replacements = [
'APP_NAME' => config('lambo.store.project_name'),
'APP_URL' => config('lambo.store.project_url'),
'DB_DATABASE' => $this->databaseName(),
'DB_USERNAME' => 'root',
'DB_PASSWORD' => null,
'DB_DATABASE' => config('lambo.store.database_name'),
'DB_USERNAME' => config('lambo.store.database_username'),
'DB_PASSWORD' => config('lambo.store.database_password'),
];

return Arr::get($replacements, $key, $fallback);
}

public function databaseName()
{
// @todo allow for flag for custom database name.. TEST IT!
return Utilities::prepNameForDatabase(config('lambo.store.project_name'));
}
}
18 changes: 8 additions & 10 deletions app/Actions/DisplayHelpScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,35 @@
namespace App\Actions;

use App\Options;
use Illuminate\Support\Arr;

class DisplayHelpScreen
{
use LamboAction;

protected $indent = 30;

protected $commands = [
'help-screen' => 'Display this screen',
'make-config' => 'Generate config file',
'edit-config' => 'Edit config file',
'make-after' => 'Generate "after" file',
'edit-after' => 'Edit "after" file',
];

public function __invoke()
{
$console = app('console');

$console->line("\n<comment>Usage:</comment>");
$console->line(" lambo new myApplication [arguments]\n");
$console->line("<comment>Commands (lambo COMMANDNAME):</comment>");
$this->line("\n<comment>Usage:</comment>");
$this->line(" lambo new myApplication [arguments]\n");
$this->line("<comment>Commands (lambo COMMANDNAME):</comment>");

foreach ($this->commands as $command => $description) {
$spaces = $this->makeSpaces(strlen($command));
$console->line(" <info>{$command}</info>{$spaces}{$description}");
$this->line(" <info>{$command}</info>{$spaces}{$description}");
}

$console->line("\n<comment>Options (lambo new myApplication OPTIONS):</comment>");
$this->line("\n<comment>Options (lambo new myApplication OPTIONS):</comment>");

foreach ((new Options)->all() as $option) {
$console->line($this->createCliStringForOption($option));
$this->line($this->createCliStringForOption($option));
}
}

Expand Down
6 changes: 4 additions & 2 deletions app/Actions/DisplayLamboWelcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class DisplayLamboWelcome
{
use LamboAction;

protected $lamboLogo = "
__ __ :version:
/ / ____ _____ ___ / /_ ____
Expand All @@ -23,12 +25,12 @@ public function __invoke()
{
foreach (explode("\n", $this->lamboLogo) as $line) {
// Extra space on the end fixes an issue with console when it ends with backslash
app('console')->info($line . " ");
$this->info($line . " ");
}

foreach (explode("\n", $this->welcomeText) as $line) {
// Extra space on the end fixes an issue with console when it ends with backslash
app('console')->line($line . " ");
$this->line($line . " ");
}
}
}
16 changes: 16 additions & 0 deletions app/Actions/EditAfter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Actions;

use App\InteractsWithLamboConfig;
use Illuminate\Support\Facades\File;

class EditAfter
{
use InteractsWithLamboConfig;

public function __invoke()
{
$this->createOrEditConfigFile("after", File::get(base_path('stubs/after.stub')));
}
}
16 changes: 16 additions & 0 deletions app/Actions/EditConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Actions;

use App\InteractsWithLamboConfig;
use Illuminate\Support\Facades\File;

class EditConfig
{
use InteractsWithLamboConfig;

public function __invoke()
{
$this->createOrEditConfigFile("config", File::get(base_path('stubs/config.stub')));
}
}
12 changes: 10 additions & 2 deletions app/Actions/GenerateAppKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace App\Actions;

use App\Shell;
use App\Shell\Shell;

class GenerateAppKey
{
use LamboAction;

protected $shell;

public function __construct(Shell $shell)
Expand All @@ -15,6 +17,12 @@ public function __construct(Shell $shell)

public function __invoke()
{
$this->shell->execInProject('php artisan key:generate');
$this->logStep('Running php artisan key:generate');

$process = $this->shell->execInProject('php artisan key:generate');

$this->abortIf(! $process->isSuccessful(), 'Failed to generate application key successfully', $process);

$this->info('Application key has been set.');
}
}
19 changes: 12 additions & 7 deletions app/Actions/InitializeGitRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace App\Actions;

use App\Shell;
use App\Shell\Shell;

class InitializeGitRepo
{
use LamboAction;

protected $shell;

public function __construct(Shell $shell)
Expand All @@ -15,15 +17,18 @@ public function __construct(Shell $shell)

public function __invoke()
{
$this->shell->execInProject('git init');
$this->shell->execInProject('git add .');
$this->shell->execInProject('git commit -m "' . $this->gitCommit() . '"');
$this->logStep('Initializing git repository');

app('console')->info('Git repository initialized.');
$this->execAndCheck('git init');
$this->execAndCheck('git add .');
$this->execAndCheck('git commit -m "' . config('lambo.store.commit_message') . '"');
$this->info('New git repository initialized.');
}

public function gitCommit()
public function execAndCheck($command)
{
return app('console')->option('message') ?? 'Initial commit.';
$process = $this->shell->execInProject($command);

$this->abortIf(! $process->isSuccessful(), 'Initialization of git repository did not complete successfully.', $process);
}
}
19 changes: 16 additions & 3 deletions app/Actions/InstallNpmDependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace App\Actions;

use App\Shell;
use App\Shell\Shell;

class InstallNpmDependencies
{
use LamboAction;

protected $shell;

public function __construct(Shell $shell)
Expand All @@ -15,8 +17,19 @@ public function __construct(Shell $shell)

public function __invoke()
{
app('console')->info('Installing NPM dependencies.');
if (! config('lambo.store.node')) {
return;
}

$process = $this->shell->execInProject("npm install{$this->extraOptions()}");

$this->abortIf(! $process->isSuccessful(), 'Installation of npm dependencies did not complete successfully', $process);

$this->shell->execInProject("npm install");
$this->info('Npm dependencies installed.');
}

public function extraOptions()
{
return config('lambo.store.with-output') ? '' : ' --silent';
}
}
Loading

0 comments on commit 0204d42

Please sign in to comment.