Skip to content

Commit

Permalink
Lots of improvements to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammyjo20 committed Aug 30, 2020
1 parent 25c648e commit 91f4788
Show file tree
Hide file tree
Showing 23 changed files with 278 additions and 314 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"php": ">7.3",
"illuminate/support": "^5.0|^6.0|^7.0",
"illuminate/contracts": "^5.0|^6.0|^7.0",
"symfony/process": "^4.0",
"symfony/process": "^4.0|^5.0",
"illuminate/filesystem": "^5.0|^6.0|^7.0",
"symfony/finder": "^4.0",
"symfony/finder": "^4.0|^5.0",
"illuminate/console": "^5.0|^6.0|^7.0",
"ext-json": "*",
"ext-zip": "*"
Expand Down
286 changes: 131 additions & 155 deletions composer.lock

Large diffs are not rendered by default.

94 changes: 65 additions & 29 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,93 @@

return [

'mode' => 'local', // Local or CDN? CDN, will replace every item in the mix-manifest.json with the cdn-ified directory.

'cdn_url' => null,

'compiler' => [

'package_manager' => 'npm', // Supports npm, yarn.

'script' => 'dev', // *package_manager* run *script*

],

'upload' => [

// Which disk shall we use?
'disk' => 'cdn',

// Which directory on the disk should we put files?
'upload_assets_to' => Str::slug('lasso-' . env('APP_NAME','laravel')),

// Which path to look at
'public_path' => public_path(),

// Files that shouldn't be included in the bundle.
/*
* Configure which command Lasso should run in its deployment
* phase. This will most likely be "npm run production" but
* you may choose what you would like to execute.
*/
'script' => 'npm run production',

/*
* If there any directories/files you would like to Lasso to
* exclude when uploading to the Filesystem, specify them below.
*/
'excluded_files' => [],

// Directories that shouldn't be included in the bundle
'excluded_directories' => [],

'push_to_git' => true, // git add "lasso" && git commit -m"Lasso Assets 🐎" --author="Lasso" && git push

],

'storage' => [

/*
* Specify the filesystem Lasso should use to use to store
* and retrieve its files.
*/
'disk' => 'assets',

/*
* Specify the directory Lasso should store all of its
* files within. By default we will use "lasso-APP_NAME".
*/
'upload_to' => sprintf('lasso-%s', Str::slug(env('APP_NAME','laravel'))),

/*
* Lasso will also create a separate directory containing
* the environment the files will be stored in. Specify this
* here.
*/
'environment' => env('APP_ENV', 'production'),

/*
* After running "php artisan lasso:push", by default Lasso will
* create a "lasso-bundle.json" file and automatically commit it to
* Git. To disable this functionality, change the setting below or
* use "php artisan lasso:push --no-git".
*/
'push_to_git' => true,

/*
* When using Lasso with Git, you will be able to roll-back your
* commits, and Lasso will pull down an old bundle of assets. Choose
* how many you would like to keep.
*/
'bundles_to_keep' => 5,

],

/*
* Lasso will can also trigger Webhooks after its commands have been
* successfully executed. You may specify URLs that Lasso will POST
* to, for each of the commands.
*/
'webhooks' => [
// Trigger webhooks for events that happen inside of Lasso

'publish' => [
/*
* Specify which webhooks should be triggered after a successful
* "php artisan lasso:push" command execution.
*/
'push' => [
//
],

'retrieve' => [
/*
* Specify which webhooks should be triggered after a successful
* "php artisan lasso:pull" command execution.
*/
'pull' => [
//
],
]

],

/*
* Where are your assets stored? Most of the time, they will
* be stored within the /public directory in Laravel - but if
* you have changed this - please specify it below.
*/
'public_path' => public_path(),

];
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use Sammyjo20\Lasso\Helpers\ConfigValidator;
use Sammyjo20\Lasso\Services\Fetcher;

class FetchCommand extends Command
class PullCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'lasso:fetch';
protected $signature = 'lasso:pull';

/**
* The console command description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Sammyjo20\Lasso\Helpers\ConfigValidator;
use Sammyjo20\Lasso\Services\Bundler;

class PublishCommand extends Command
class PushCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'lasso:publish {--no-git}';
protected $signature = 'lasso:push {--no-git}';

/**
* The console command description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace Sammyjo20\Lasso\Exceptions;

class FetchCommandException extends \Exception
class BaseException extends \Exception
{
/**
* @var string
*/
public static $event = 'An exception was thrown.';

/**
* @param string $reason
* @return static
*/
public static function because(string $reason)
{
return new static(sprintf(
'Failed to fetch the latest Lasso deployment. Reason: %s', $reason
'%s Reason: %s', static::$event, $reason
));
}
}
17 changes: 0 additions & 17 deletions src/Exceptions/CommitFailedException.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Sammyjo20\Lasso\Exceptions;

class CompilerFailedException extends \Exception
class CommittingFailed extends BaseException
{
//
}
8 changes: 8 additions & 0 deletions src/Exceptions/CompilerFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sammyjo20\Lasso\Exceptions;

class CompilerFailed extends BaseException
{
//
}
12 changes: 3 additions & 9 deletions src/Exceptions/ConfigFailedValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

namespace Sammyjo20\Lasso\Exceptions;

class ConfigFailedValidation extends \Exception
class ConfigFailedValidation extends BaseException
{
/**
* @param string $reason
* @return static
* @var string
*/
public static function because(string $reason)
{
return new static(sprintf(
'Failed to process configuration. Reason: %s', $reason
));
}
public static $event = 'Failed to parse configuration.';
}
2 changes: 1 addition & 1 deletion src/Exceptions/ConsoleMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Sammyjo20\Lasso\Exceptions;

class ConsoleMethodException extends \Exception
class ConsoleMethodException extends BaseException
{
//
}
8 changes: 8 additions & 0 deletions src/Exceptions/FetchCommandFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sammyjo20\Lasso\Exceptions;

class FetchCommandFailed extends BaseException
{
//
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Sammyjo20\Lasso\Exceptions;

class BackupRestoreException extends \Exception
class RestoreFailed extends BaseException
{

//
}
13 changes: 0 additions & 13 deletions src/Helpers/CommitValidator.php

This file was deleted.

45 changes: 9 additions & 36 deletions src/Helpers/ConfigValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Sammyjo20\Lasso\Helpers;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Sammyjo20\Lasso\Exceptions\ConfigFailedValidation;

class ConfigValidator
Expand Down Expand Up @@ -34,27 +33,9 @@ private function get(string $item)
* @param $value
* @return bool
*/
private function checkMode($value): bool
private function checkCompilerScript($value): bool
{
return Str::contains($value, ['local', 'cdn']);
}

/**
* @param $value
* @return bool
*/
private function checkCdnUrl($value): bool
{
return !is_null($value) && filter_var($value, FILTER_SANITIZE_URL);
}

/**
* @param $value
* @return bool
*/
private function checkPackageManager($value): bool
{
return Str::contains($value, ['npm', 'yarn']);
return !is_null($value);
}

/**
Expand Down Expand Up @@ -99,23 +80,11 @@ private function checkBundleToKeepCount($value): bool
*/
public function validate(): void
{
if (!$this->checkMode($this->get('mode'))) {
throw ConfigFailedValidation::because('The specified mode must be either "local" or "cdn".');
}

if ($this->get('mode') === 'cdn' && !$this->checkCdnUrl($this->get('cdn_url'))) {
throw ConfigFailedValidation::because('The specified CDN url is invalid.');
}

if (!$this->checkPackageManager($this->get('compiler.package_manager'))) {
throw ConfigFailedValidation::because('The specified package manager must be either "npm" or "yarn".');
if (!$this->checkCompilerScript($this->get('compiler.script'))) {
throw ConfigFailedValidation::because('You must specify a script to run the compiler. (E.g: npm run production)');
}

if (!$this->checkIfPublicPathExists($this->get('upload.public_path'))) {
throw ConfigFailedValidation::because('The specified public directory is not a valid or accessible directory.');
}

if (!$this->checkDiskExists($this->get('upload.disk'))) {
if (!$this->checkDiskExists($this->get('storage.disk'))) {
throw ConfigFailedValidation::because('The specified upload disk is not a valid disk.');
}

Expand All @@ -126,5 +95,9 @@ public function validate(): void
if (!$this->checkBundleToKeepCount($this->get('storage.bundles_to_keep'))) {
throw ConfigFailedValidation::because('You must specify how many bundles should be kept. (Min: 1)');
}

if (!$this->checkIfPublicPathExists($this->get('public_path'))) {
throw ConfigFailedValidation::because('The specified public directory is not a valid or accessible directory.');
}
}
}
8 changes: 4 additions & 4 deletions src/LassoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Sammyjo20\Lasso;

use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Sammyjo20\Lasso\Commands\PublishCommand;
use Sammyjo20\Lasso\Commands\FetchCommand;
use Sammyjo20\Lasso\Commands\PushCommand;
use Sammyjo20\Lasso\Commands\PullCommand;
use Sammyjo20\Lasso\Container\Console;

class LassoServiceProvider extends BaseServiceProvider
Expand All @@ -19,8 +19,8 @@ public function boot()
$this->app->instance(Console::class, new Console());

$this->commands([
PublishCommand::class,
FetchCommand::class,
PushCommand::class,
PullCommand::class,
]);
}
}
Expand Down
Loading

0 comments on commit 91f4788

Please sign in to comment.