Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch release v1.0.1 - Use correct time zone and minor refactors for readability #152

Merged
merged 16 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
.phpunit.result.cache
/storage/framework/
.php_cs.cache
8 changes: 8 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset>
<file>app</file>
<file>config</file>
<file>tests</file>

<rule ref="Tighten"/>
</ruleset>
10 changes: 5 additions & 5 deletions app/Actions/CompileAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ class CompileAssets
use AbortsCommands;

protected $shell;
protected $silentDevScript;
protected $npm;
jonsugar marked this conversation as resolved.
Show resolved Hide resolved
protected $consoleWriter;

public function __construct(Shell $shell, SilentDevScript $silentDevScript, ConsoleWriter $consoleWriter)
public function __construct(Shell $shell, SilenceNpm $silenceNpm, ConsoleWriter $consoleWriter)
{
$this->shell = $shell;
$this->silentDevScript = $silentDevScript;
$this->npm = $silenceNpm;
$this->consoleWriter = $consoleWriter;
}

public function __invoke()
{
$this->consoleWriter->logStep('Compiling project assets');

$this->silentDevScript->add();
$this->npm->silence();
$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->npm->unsilence();

$this->consoleWriter->success('Project assets compiled successfully.');
}
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/ConfigureFrontendFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __invoke()
$this->ensureJetstreamInstalled();

$process = $this->shell->execInProject(sprintf(
"php artisan jetstream:install %s%s%s",
'php artisan jetstream:install %s%s%s',
$configuredFrontend,
config('lambo.store.teams') ? ' --teams' : '',
config('lambo.store.with_output') ? '' : ' --quiet'
Expand All @@ -60,7 +60,7 @@ public function ensureJetstreamInstalled()

$process = $this->shell->execInProject('composer require laravel/jetstream' . (config('lambo.store.with_output') ? '' : ' --quiet'));

$this->abortIf(! $process->isSuccessful(), "Installation of laravel/jetstream did not complete successfully.", $process);
$this->abortIf(! $process->isSuccessful(), 'Installation of laravel/jetstream did not complete successfully.', $process);

$this->consoleWriter->success('laravel/jetstream installed.');
}
Expand Down
10 changes: 5 additions & 5 deletions app/Actions/DisplayHelpScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class DisplayHelpScreen
public function __invoke()
{
app('console-writer')->newLine();
app('console-writer')->text("<comment>Usage:</comment>");
app('console-writer')->text('<comment>Usage:</comment>');
app('console-writer')->text(" lambo new myApplication [arguments]\n");
app('console-writer')->text("<comment>Commands (lambo COMMANDNAME):</comment>");
app('console-writer')->text('<comment>Commands (lambo COMMANDNAME):</comment>');

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

app('console-writer')->newLine();
app('console-writer')->text("<comment>Options (lambo new myApplication OPTIONS):</comment>");
app('console-writer')->text('<comment>Options (lambo new myApplication OPTIONS):</comment>');

foreach ((new Options)->all() as $option) {
foreach ((new Options())->all() as $option) {
app('console-writer')->text($this->createCliStringForOption($option));
}
}
Expand All @@ -54,6 +54,6 @@ public function createCliStringForOption($option)

public function makeSpaces($count)
{
return str_repeat(" ", $this->indent - $count);
return str_repeat(' ', $this->indent - $count);
}
}
8 changes: 4 additions & 4 deletions app/Actions/DisplayLamboWelcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class DisplayLamboWelcome
{
protected $lamboLogo = "
protected $lamboLogo = '
__ __ :version:
/ / ____ _____ ___ / /_ ____
/ / / __ `/ __ `__ \/ __ \/ __ \
/ /___/ /_/ / / / / / / /_/ / /_/ /
/_____/\__,_/_/ /_/ /_/_.___/\____/";
/_____/\__,_/_/ /_/ /_/_.___/\____/';

protected $welcomeText = "
<info>Lambo:</info> Super-powered <comment>'laravel new'</comment> for Laravel and Valet.";
Expand All @@ -23,12 +23,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-writer')->text("<info>$line </info>");
app('console-writer')->text("<info>{$line} </info>");
}

foreach (explode("\n", $this->welcomeText) as $line) {
// Extra space on the end fixes an issue with console when it ends with backslash
app('console-writer')->text($line . " ");
app('console-writer')->text("{$line} ");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Shell;
use Illuminate\Support\Facades\File;

class SavedConfig
class EditConfigFile
jonsugar marked this conversation as resolved.
Show resolved Hide resolved
{
use AbortsCommands;

Expand All @@ -16,10 +16,10 @@ public function __construct(Shell $shell)
$this->shell = $shell;
}

public function createOrEditConfigFile(string $fileName)
public function __invoke(string $fileName)
{
$configDir = config('home_dir') . '/.lambo';
$configFilePath = $configDir . "/" . $fileName;
$configFilePath = $configDir . '/' . $fileName;

if (! File::isDirectory($configDir)) {
app('console-writer')->note("Configuration directory '{$configDir}' does not exist, creating it now...");
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/OpenInBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke()
return;
}

$this->shell->execInProject("valet open");
$this->shell->execInProject('valet open');
}

public function browser()
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/OpenInEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function __invoke()

$this->consoleWriter->logStep('Opening In Editor');

$process = $this->shell->withTTY()->execInProject(sprintf("%s .", config('lambo.store.editor')));
$this->abortIf(! $process->isSuccessful(), sprintf("Failed to open editor %s", config('lambo.store.editor')), $process);
$process = $this->shell->withTTY()->execInProject(sprintf('%s .', config('lambo.store.editor')));
$this->abortIf(! $process->isSuccessful(), sprintf('Failed to open editor %s', config('lambo.store.editor')), $process);

$this->consoleWriter->success('Opening your project in ' . config('lambo.store.editor'));
}
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/RunAfterScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke()

$this->consoleWriter->logStep('Running after script');

$process = $this->shell->execInProject("sh " . $afterScriptPath);
$process = $this->shell->execInProject('sh ' . $afterScriptPath);
$this->abortIf(! $process->isSuccessful(), 'After file did not complete successfully', $process);

$this->consoleWriter->success('After script has completed.');
Expand Down
11 changes: 6 additions & 5 deletions app/Actions/RunLaravelInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@ public function __construct(Shell $shell, ConsoleWriter $consoleWriter)

public function __invoke()
{
$this->consoleWriter->logStep("Running the Laravel installer");
$this->consoleWriter->logStep('Running the Laravel installer');

$process = $this->shell->execInRoot('laravel new ' . config('lambo.store.project_name') . $this->extraOptions());
$this->abortIf(! $process->isSuccessful(), "The laravel installer did not complete successfully.", $process);
$this->abortIf(! $process->isSuccessful(), 'The laravel installer did not complete successfully.', $process);

$this->consoleWriter->success($this->getFeedback());
}

public function extraOptions()
{
return sprintf('%s%s',
return sprintf(
'%s%s',
config('lambo.store.dev') ? ' --dev' : '',
config('lambo.store.with_output') ? '' : ' --quiet'
);
}

public function getFeedback(): string
{
return sprintf("A new application '%s' has been created from the %s branch.",
return sprintf(
"A new application '%s' has been created from the %s branch.",
config('lambo.store.project_name'),
config('lambo.store.dev') ? 'develop' : 'release'
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;

class SilentDevScript
class SilenceNpm
{
private $packageJsonPath;
private $backupPackageJsonPath;
Expand All @@ -16,13 +16,13 @@ public function __construct()
$this->backupPackageJsonPath = config('lambo.store.project_path') . '/package-original.json';
}

public function add()
public function silence()
{
File::copy($this->packageJsonPath, $this->backupPackageJsonPath);
File::replace($this->packageJsonPath, $this->getSilentPackageJson($this->packageJsonPath));
}

public function remove()
public function unsilence()
{
File::move($this->backupPackageJsonPath, $this->packageJsonPath);
}
Expand All @@ -33,6 +33,6 @@ private function getSilentPackageJson(string $originalPackageJson)
$silentDevelopmentCommand = str_replace('--progress', '--no-progress', Arr::get($packageJson, 'scripts.development'));
Arr::set($packageJson, 'scripts.development', $silentDevelopmentCommand);

return json_encode($packageJson, JSON_UNESCAPED_SLASHES);
return json_encode($packageJson, JSON_UNESCAPED_SLASHES);
}
}
34 changes: 15 additions & 19 deletions app/Actions/UpgradeSavedConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ class UpgradeSavedConfiguration
// IMPORTANT NOTE: Every time we make *any* changes to configuration, we need
// to increment this configurationVersion so that users get upgraded config
private $configurationVersion = 1;

private $configDir;
private $configFilePath;
private $lastVersionUpdateFilePath;
private $commented = [];
private $removedConfigurationKeys = [
'NODE',
'MIX',
'AUTH',
'FRONTEND',
];

private $newConfiguration = [
'MIGRATE_DATABASE' => [
'commented' => false,
Expand All @@ -35,7 +37,7 @@ class UpgradeSavedConfiguration
'default' => '127.0.0.1',
'description' => [
'The database host. Defaults to 127.0.0.1.',
]
],
],
'DB_PORT' => [
'commented' => true,
Expand All @@ -53,20 +55,14 @@ class UpgradeSavedConfiguration
],
];

private $configDir;
private $configFilePath;
private $lastVersionUpdateFilePath;

private $commented = [];

public function __construct()
{
$this->configDir = config('home_dir') . '/.lambo';
$this->configFilePath = "{$this->configDir}/config";
$this->lastVersionUpdateFilePath = "{$this->configDir}/.last_version_update";
}

public function __invoke()
public function __invoke(): bool
{
if (! $this->shouldUpgrade()) {
return false;
Expand All @@ -83,7 +79,7 @@ public function __invoke()
return true;
}

private function shouldUpgrade()
private function shouldUpgrade(): bool
{
if (! File::isFile($this->configFilePath)) {
return false;
Expand All @@ -100,10 +96,10 @@ private function shouldUpgrade()
return false;
}

public function upgrade(string $savedConfiguration, array $unusedConfigurationKeys, array $newConfiguration = []): string
public function upgrade(string $savedConfiguration, array $removedConfigurationKeys, array $newConfiguration = []): string
{
return implode(PHP_EOL, [
$this->commentUnusedConfiguration($savedConfiguration, $unusedConfigurationKeys),
$this->commentRemovedConfiguration($savedConfiguration, $removedConfigurationKeys),
"\n# ------------------------------------------------------------------------------",
'# ' . Carbon::now()->format('j-M-Y g:i a') . ' (auto-generated by Lambo):',
'# ------------------------------------------------------------------------------',
Expand All @@ -112,7 +108,7 @@ public function upgrade(string $savedConfiguration, array $unusedConfigurationKe
]);
}

private function commentUnusedConfiguration(string $savedConfiguration, array $oldConfigurationKeys): string
private function commentRemovedConfiguration(string $savedConfiguration, array $oldConfigurationKeys): string
{
return collect(explode("\n", $savedConfiguration))->transform(function ($item) use ($oldConfigurationKeys) {
$matched = collect($oldConfigurationKeys)->reduce(function ($carry, $oldKey) use ($item) {
Expand All @@ -126,17 +122,17 @@ private function commentUnusedConfiguration(string $savedConfiguration, array $o
})->implode("\n");
}

private function summarizeComments()
private function summarizeComments(): string
{
if (count($this->commented) < 1) {
return '';
}

return implode(PHP_EOL, [
'# Lambo has commented out the following configuration items; they are no',
'# longer used, and you may safely remove them:',
'# Lambo has commented out the following configuration items as they',
'# are no-longer used. You may safely remove them:',
collect($this->commented)->reduce(function ($carry, $item) {
return "$carry# {$item}\n";
return "{$carry}# {$item}\n";
}, '')
]);
}
Expand All @@ -149,7 +145,7 @@ private function addNewConfiguration(array $newConfiguration): string

return collect(array_keys($newConfiguration))->reduce(function ($carry, $key) use ($newConfiguration) {
$description = collect($newConfiguration[$key]['description'])->reduce(function ($carry, $item) {
return "$carry# {$item}\n";
return "{$carry}# {$item}\n";
}, '');

$configurationItem = sprintf(
Expand Down
1 change: 1 addition & 0 deletions app/Actions/ValetLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ValetLink
use AbortsCommands;

protected $shell;

private $consoleWriter;

public function __construct(Shell $shell, ConsoleWriter $consoleWriter)
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/ValetSecure.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __invoke()

$this->consoleWriter->logStep('Running valet secure');

$process = $this->shell->execInProject("valet secure");
$process = $this->shell->execInProject('valet secure');
$this->abortIf(! $process->isSuccessful(), 'valet secure did not complete successfully', $process);

$this->consoleWriter->success('valet secure successful');
Expand Down
Loading