new deployer command

This commit is contained in:
Mark Gregory
2026-09-16 11:01:02 +01:00
parent 0756b1de79
commit 45a370ed91
20 changed files with 193 additions and 161 deletions
+2 -3
View File
@@ -2,7 +2,6 @@
return [ return [
'name' => 'M3', 'name' => 'M3',
'features' => 'features' => [
[ ],
],
]; ];
@@ -2,8 +2,8 @@
namespace Modules\M3\Database\Seeders; namespace Modules\M3\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class M3DatabaseSeeder extends Seeder class M3DatabaseSeeder extends Seeder
{ {
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
use Modules\M3\Support\ModuleInfo; use Modules\M3\Support\ModuleInfo;
if (! function_exists('m3_feature_enabled')) { if (! function_exists('m3_feature_enabled')) {
@@ -7,6 +8,6 @@ if (! function_exists('m3_feature_enabled')) {
*/ */
function m3_feature_enabled(string $key): bool function m3_feature_enabled(string $key): bool
{ {
return (bool) config(ModuleInfo::nameLower().".features.{$key}", false); return (bool) config(ModuleInfo::nameLower() . ".features.{$key}", false);
} }
} }
+13 -1
View File
@@ -10,6 +10,7 @@ class M3Controller extends Controller
{ {
/** /**
* Display a listing of the resource. * Display a listing of the resource.
*
* @return Renderable * @return Renderable
*/ */
public function index() public function index()
@@ -19,6 +20,7 @@ class M3Controller extends Controller
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
*
* @return Renderable * @return Renderable
*/ */
public function create() public function create()
@@ -28,7 +30,9 @@ class M3Controller extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*
* @param Request $request * @param Request $request
*
* @return Renderable * @return Renderable
*/ */
public function store(Request $request) public function store(Request $request)
@@ -38,7 +42,9 @@ class M3Controller extends Controller
/** /**
* Show the specified resource. * Show the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function show($id) public function show($id)
@@ -48,7 +54,9 @@ class M3Controller extends Controller
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function edit($id) public function edit($id)
@@ -58,8 +66,10 @@ class M3Controller extends Controller
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
*
* @param Request $request * @param Request $request
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
@@ -69,7 +79,9 @@ class M3Controller extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function destroy($id) public function destroy($id)
+40 -38
View File
@@ -2,31 +2,29 @@
namespace Modules\M3\Providers; namespace Modules\M3\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\Facades\File;
use Modules\M3\Support\ModuleInfo;
use Config; use Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Modules\M3\Support\ModuleInfo;
class M3ServiceProvider extends ServiceProvider class M3ServiceProvider extends ServiceProvider
{ {
/** /**
* @var string $moduleName * @var string
*/ */
protected string $moduleName = 'M3'; protected string $moduleName = 'M3';
/** /**
* @var string $moduleNameLower * @var string
*/ */
protected string $moduleNameLower = 'm3'; protected string $moduleNameLower = 'm3';
/**
/** * Get the services provided by the provider.
* Get the services provided by the provider. *
* * @return array
* @return array */
*/ public function provides(): array
public function provides():array
{ {
return []; return [];
} }
@@ -36,7 +34,7 @@ class M3ServiceProvider extends ServiceProvider
* *
* @return void * @return void
*/ */
public function boot() : void public function boot(): void
{ {
$this->registerTranslations(); $this->registerTranslations();
$this->registerConfig(); $this->registerConfig();
@@ -63,34 +61,35 @@ class M3ServiceProvider extends ServiceProvider
*/ */
protected function registerHelpers(): void protected function registerHelpers(): void
{ {
foreach (glob(__DIR__.'/../Helpers/*.php') as $filename) { foreach (glob(__DIR__ . '/../Helpers/*.php') as $filename) {
require_once $filename; require_once $filename;
} }
} }
/** /**
* Dynamically Register Commands. * Dynamically Register Commands.
* *
* @return void * @return void
*/ */
public function registerCommands(): void public function registerCommands(): void
{ {
if (!$this->app->runningInConsole()) { if (! $this->app->runningInConsole()) {
return; return;
}
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
} }
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
}
/** /**
* Register config. * Register config.
@@ -100,10 +99,11 @@ class M3ServiceProvider extends ServiceProvider
protected function registerConfig(): void protected function registerConfig(): void
{ {
$this->publishes([ $this->publishes([
module_path(ModuleInfo::name(), 'Config/config.php') => config_path( ModuleInfo::nameLower(). '.php'), module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower() . '.php'),
], 'config'); ], 'config');
$this->mergeConfigFrom( $this->mergeConfigFrom(
module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower() module_path(ModuleInfo::name(), 'Config/config.php'),
ModuleInfo::nameLower(),
); );
} }
@@ -117,9 +117,9 @@ class M3ServiceProvider extends ServiceProvider
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower()); $viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views'); $sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([ $this->publishes([
$sourcePath => $viewPath $sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower() . '-module-views']); ], ['views', ModuleInfo::nameLower() . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower()); $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
} }
/** /**
@@ -129,10 +129,10 @@ class M3ServiceProvider extends ServiceProvider
*/ */
public function registerTranslations(): void public function registerTranslations(): void
{ {
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower()); $langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
if (is_dir($langPath)) { if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower()); $this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
} else { } else {
$this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower()); $this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower());
} }
@@ -140,6 +140,7 @@ class M3ServiceProvider extends ServiceProvider
/** /**
* Regsiter View Paths * Regsiter View Paths
*
* @return array * @return array
*/ */
private function getPublishableViewPaths(): array private function getPublishableViewPaths(): array
@@ -150,6 +151,7 @@ class M3ServiceProvider extends ServiceProvider
$paths[] = $path . '/modules/' . ModuleInfo::nameLower(); $paths[] = $path . '/modules/' . ModuleInfo::nameLower();
} }
} }
return $paths; return $paths;
} }
} }
@@ -2,8 +2,8 @@
namespace Modules\M3\Providers; namespace Modules\M3\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
{ {
+1 -1
View File
@@ -11,6 +11,6 @@
| |
*/ */
Route::prefix('m3')->group(function() { Route::prefix('m3')->group(function () {
Route::get('/', 'M3Controller@index'); Route::get('/', 'M3Controller@index');
}); });
+3 -1
View File
@@ -4,10 +4,11 @@ namespace Modules\M3\Support;
class ModuleInfo class ModuleInfo
{ {
protected static string $moduleName = 'M3'; protected static string $moduleName = 'M3';
/** /**
* defines the Module Name * defines the Module Name
*
* @return string * @return string
*/ */
public static function name(): string public static function name(): string
@@ -17,6 +18,7 @@ class ModuleInfo
/** /**
* define the lowercase version * define the lowercase version
*
* @return string * @return string
*/ */
public static function nameLower(): string public static function nameLower(): string
+2 -3
View File
@@ -2,7 +2,6 @@
return [ return [
'name' => 'OTM', 'name' => 'OTM',
'features' => 'features' => [
[ ],
],
]; ];
@@ -2,8 +2,8 @@
namespace Modules\OTM\Database\Seeders; namespace Modules\OTM\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class OTMDatabaseSeeder extends Seeder class OTMDatabaseSeeder extends Seeder
{ {
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
use Modules\OTM\Support\ModuleInfo; use Modules\OTM\Support\ModuleInfo;
if (! function_exists('otm_feature_enabled')) { if (! function_exists('otm_feature_enabled')) {
@@ -7,6 +8,6 @@ if (! function_exists('otm_feature_enabled')) {
*/ */
function otm_feature_enabled(string $key): bool function otm_feature_enabled(string $key): bool
{ {
return (bool) config(ModuleInfo::nameLower().".features.{$key}", false); return (bool) config(ModuleInfo::nameLower() . ".features.{$key}", false);
} }
} }
+13 -1
View File
@@ -10,6 +10,7 @@ class OTMController extends Controller
{ {
/** /**
* Display a listing of the resource. * Display a listing of the resource.
*
* @return Renderable * @return Renderable
*/ */
public function index() public function index()
@@ -19,6 +20,7 @@ class OTMController extends Controller
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
*
* @return Renderable * @return Renderable
*/ */
public function create() public function create()
@@ -28,7 +30,9 @@ class OTMController extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*
* @param Request $request * @param Request $request
*
* @return Renderable * @return Renderable
*/ */
public function store(Request $request) public function store(Request $request)
@@ -38,7 +42,9 @@ class OTMController extends Controller
/** /**
* Show the specified resource. * Show the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function show($id) public function show($id)
@@ -48,7 +54,9 @@ class OTMController extends Controller
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function edit($id) public function edit($id)
@@ -58,8 +66,10 @@ class OTMController extends Controller
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
*
* @param Request $request * @param Request $request
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
@@ -69,7 +79,9 @@ class OTMController extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function destroy($id) public function destroy($id)
+40 -38
View File
@@ -2,31 +2,29 @@
namespace Modules\OTM\Providers; namespace Modules\OTM\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\Facades\File;
use Modules\OTM\Support\ModuleInfo;
use Config; use Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Modules\OTM\Support\ModuleInfo;
class OTMServiceProvider extends ServiceProvider class OTMServiceProvider extends ServiceProvider
{ {
/** /**
* @var string $moduleName * @var string
*/ */
protected string $moduleName = 'OTM'; protected string $moduleName = 'OTM';
/** /**
* @var string $moduleNameLower * @var string
*/ */
protected string $moduleNameLower = 'otm'; protected string $moduleNameLower = 'otm';
/**
/** * Get the services provided by the provider.
* Get the services provided by the provider. *
* * @return array
* @return array */
*/ public function provides(): array
public function provides():array
{ {
return []; return [];
} }
@@ -36,7 +34,7 @@ class OTMServiceProvider extends ServiceProvider
* *
* @return void * @return void
*/ */
public function boot() : void public function boot(): void
{ {
$this->registerTranslations(); $this->registerTranslations();
$this->registerConfig(); $this->registerConfig();
@@ -63,34 +61,35 @@ class OTMServiceProvider extends ServiceProvider
*/ */
protected function registerHelpers(): void protected function registerHelpers(): void
{ {
foreach (glob(__DIR__.'/../Helpers/*.php') as $filename) { foreach (glob(__DIR__ . '/../Helpers/*.php') as $filename) {
require_once $filename; require_once $filename;
} }
} }
/** /**
* Dynamically Register Commands. * Dynamically Register Commands.
* *
* @return void * @return void
*/ */
public function registerCommands(): void public function registerCommands(): void
{ {
if (!$this->app->runningInConsole()) { if (! $this->app->runningInConsole()) {
return; return;
}
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
} }
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
}
/** /**
* Register config. * Register config.
@@ -100,10 +99,11 @@ class OTMServiceProvider extends ServiceProvider
protected function registerConfig(): void protected function registerConfig(): void
{ {
$this->publishes([ $this->publishes([
module_path(ModuleInfo::name(), 'Config/config.php') => config_path( ModuleInfo::nameLower(). '.php'), module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower() . '.php'),
], 'config'); ], 'config');
$this->mergeConfigFrom( $this->mergeConfigFrom(
module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower() module_path(ModuleInfo::name(), 'Config/config.php'),
ModuleInfo::nameLower(),
); );
} }
@@ -117,9 +117,9 @@ class OTMServiceProvider extends ServiceProvider
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower()); $viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views'); $sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([ $this->publishes([
$sourcePath => $viewPath $sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower() . '-module-views']); ], ['views', ModuleInfo::nameLower() . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower()); $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
} }
/** /**
@@ -129,10 +129,10 @@ class OTMServiceProvider extends ServiceProvider
*/ */
public function registerTranslations(): void public function registerTranslations(): void
{ {
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower()); $langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
if (is_dir($langPath)) { if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower()); $this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
} else { } else {
$this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower()); $this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower());
} }
@@ -140,6 +140,7 @@ class OTMServiceProvider extends ServiceProvider
/** /**
* Regsiter View Paths * Regsiter View Paths
*
* @return array * @return array
*/ */
private function getPublishableViewPaths(): array private function getPublishableViewPaths(): array
@@ -150,6 +151,7 @@ class OTMServiceProvider extends ServiceProvider
$paths[] = $path . '/modules/' . ModuleInfo::nameLower(); $paths[] = $path . '/modules/' . ModuleInfo::nameLower();
} }
} }
return $paths; return $paths;
} }
} }
@@ -2,8 +2,8 @@
namespace Modules\OTM\Providers; namespace Modules\OTM\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
{ {
+1 -1
View File
@@ -11,6 +11,6 @@
| |
*/ */
Route::prefix('otm')->group(function() { Route::prefix('otm')->group(function () {
Route::get('/', 'OTMController@index'); Route::get('/', 'OTMController@index');
}); });
+3 -1
View File
@@ -4,10 +4,11 @@ namespace Modules\OTM\Support;
class ModuleInfo class ModuleInfo
{ {
protected static string $moduleName = 'OTM'; protected static string $moduleName = 'OTM';
/** /**
* defines the Module Name * defines the Module Name
*
* @return string * @return string
*/ */
public static function name(): string public static function name(): string
@@ -17,6 +18,7 @@ class ModuleInfo
/** /**
* define the lowercase version * define the lowercase version
*
* @return string * @return string
*/ */
public static function nameLower(): string public static function nameLower(): string
+51 -51
View File
@@ -40,11 +40,11 @@ class DatabaseStage extends Command
]; ];
foreach ([ foreach ([
'STAGE_SSH_HOST' => $stage['ssh_host'], 'STAGE_SSH_HOST' => $stage['ssh_host'],
'STAGE_SSH_USER' => $stage['ssh_user'], 'STAGE_SSH_USER' => $stage['ssh_user'],
'STAGE_DB_DATABASE' => $stage['database'], 'STAGE_DB_DATABASE' => $stage['database'],
'STAGE_DB_USERNAME' => $stage['username'], 'STAGE_DB_USERNAME' => $stage['username'],
] as $name => $value) { ] as $name => $value) {
if (! $value) { if (! $value) {
$this->error("Missing {$name}."); $this->error("Missing {$name}.");
@@ -69,14 +69,14 @@ class DatabaseStage extends Command
['Stage server', "{$stage['ssh_user']}@{$stage['ssh_host']}"], ['Stage server', "{$stage['ssh_user']}@{$stage['ssh_host']}"],
['Stage database', $stage['database']], ['Stage database', $stage['database']],
['Stage owner', $stage['username']], ['Stage owner', $stage['username']],
] ],
); );
if ( if (
! $this->option('force') && ! $this->option('force') &&
! $this->confirm( ! $this->confirm(
"This will DROP and completely RECREATE '{$stage['database']}'. Continue?", "This will DROP and completely RECREATE '{$stage['database']}'. Continue?",
false false,
) )
) { ) {
$this->warn('Cancelled.'); $this->warn('Cancelled.');
@@ -110,9 +110,9 @@ class DatabaseStage extends Command
'PGPASSWORD' => $local['password'], 'PGPASSWORD' => $local['password'],
])->timeout(3600)->run([ ])->timeout(3600)->run([
'pg_dump', 'pg_dump',
'--host='.$local['host'], '--host=' . $local['host'],
'--port='.$local['port'], '--port=' . $local['port'],
'--username='.$local['username'], '--username=' . $local['username'],
// Custom archive format. // Custom archive format.
'--format=custom', '--format=custom',
@@ -127,14 +127,14 @@ class DatabaseStage extends Command
'--no-acl', '--no-acl',
// Include everything in the database. // Include everything in the database.
'--file='.$localDump, '--file=' . $localDump,
$local['database'], $local['database'],
]); ]);
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"pg_dump failed:\n".$result->errorOutput() "pg_dump failed:\n" . $result->errorOutput(),
); );
} }
@@ -143,7 +143,7 @@ class DatabaseStage extends Command
} }
return true; return true;
} },
); );
$dumpSize = $this->formatBytes(filesize($localDump)); $dumpSize = $this->formatBytes(filesize($localDump));
@@ -167,12 +167,12 @@ class DatabaseStage extends Command
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Invalid PostgreSQL archive:\n".$result->errorOutput() "Invalid PostgreSQL archive:\n" . $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -194,12 +194,12 @@ class DatabaseStage extends Command
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Upload failed:\n".$result->errorOutput() "Upload failed:\n" . $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -220,7 +220,7 @@ class DatabaseStage extends Command
$terminateDatabase = str_replace( $terminateDatabase = str_replace(
"'", "'",
"''", "''",
$stage['database'] $stage['database'],
); );
$sql = <<<SQL $sql = <<<SQL
@@ -238,7 +238,7 @@ SQL;
$remoteCommand = sprintf( $remoteCommand = sprintf(
'sudo -u %s psql --set ON_ERROR_STOP=on --dbname=postgres', 'sudo -u %s psql --set ON_ERROR_STOP=on --dbname=postgres',
escapeshellarg($stage['admin_username']) escapeshellarg($stage['admin_username']),
); );
$result = Process::input($sql) $result = Process::input($sql)
@@ -253,13 +253,13 @@ SQL;
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Unable to recreate stage database:\n". "Unable to recreate stage database:\n" .
$result->errorOutput() $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -272,15 +272,15 @@ SQL;
'Restoring complete stage database', 'Restoring complete stage database',
function () use ($stage, $remoteDump) { function () use ($stage, $remoteDump) {
$restore = sprintf( $restore = sprintf(
'PGPASSWORD=%s pg_restore '. 'PGPASSWORD=%s pg_restore ' .
'--host=%s '. '--host=%s ' .
'--port=%s '. '--port=%s ' .
'--username=%s '. '--username=%s ' .
'--dbname=%s '. '--dbname=%s ' .
'--no-owner '. '--no-owner ' .
'--no-acl '. '--no-acl ' .
'--exit-on-error '. '--exit-on-error ' .
'--verbose '. '--verbose ' .
'%s', '%s',
escapeshellarg($stage['password']), escapeshellarg($stage['password']),
escapeshellarg($stage['db_host']), escapeshellarg($stage['db_host']),
@@ -300,13 +300,13 @@ SQL;
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Database restore failed:\n". "Database restore failed:\n" .
$result->errorOutput() $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -319,12 +319,12 @@ SQL;
'Verifying restored database', 'Verifying restored database',
function () use ($stage) { function () use ($stage) {
$command = sprintf( $command = sprintf(
'PGPASSWORD=%s psql '. 'PGPASSWORD=%s psql ' .
'--host=%s '. '--host=%s ' .
'--port=%s '. '--port=%s ' .
'--username=%s '. '--username=%s ' .
'--dbname=%s '. '--dbname=%s ' .
'--tuples-only '. '--tuples-only ' .
'--command=%s', '--command=%s',
escapeshellarg($stage['password']), escapeshellarg($stage['password']),
escapeshellarg($stage['db_host']), escapeshellarg($stage['db_host']),
@@ -332,7 +332,7 @@ SQL;
escapeshellarg($stage['username']), escapeshellarg($stage['username']),
escapeshellarg($stage['database']), escapeshellarg($stage['database']),
escapeshellarg( escapeshellarg(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';" "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';",
), ),
); );
@@ -346,8 +346,8 @@ SQL;
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Database verification failed:\n". "Database verification failed:\n" .
$result->errorOutput() $result->errorOutput(),
); );
} }
@@ -356,7 +356,7 @@ SQL;
$this->line(" Stage public tables: {$count}"); $this->line(" Stage public tables: {$count}");
return true; return true;
} },
); );
/* /*
@@ -381,11 +381,11 @@ SQL;
$this->newLine(); $this->newLine();
$this->components->info( $this->components->info(
'Stage PostgreSQL database cloned successfully.' 'Stage PostgreSQL database cloned successfully.',
); );
$this->line( $this->line(
"Local {$local['database']} → Stage {$stage['database']}" "Local {$local['database']} → Stage {$stage['database']}",
); );
return self::SUCCESS; return self::SUCCESS;
@@ -396,7 +396,7 @@ SQL;
$this->newLine(); $this->newLine();
$this->warn( $this->warn(
"The dump may still exist at {$localDump} and/or {$remoteDump}." "The dump may still exist at {$localDump} and/or {$remoteDump}.",
); );
return self::FAILURE; return self::FAILURE;
@@ -405,7 +405,7 @@ SQL;
private function quoteSqlIdentifier(string $identifier): string private function quoteSqlIdentifier(string $identifier): string
{ {
return '"'.str_replace('"', '""', $identifier).'"'; return '"' . str_replace('"', '""', $identifier) . '"';
} }
private function formatBytes(int $bytes): string private function formatBytes(int $bytes): string
@@ -418,8 +418,8 @@ SQL;
: 0; : 0;
return number_format( return number_format(
$bytes / (1024 ** $power), $bytes / (1024 ** $power),
$power === 0 ? 0 : 2 $power === 0 ? 0 : 2,
).' '.$units[$power]; ) . ' ' . $units[$power];
} }
} }
+14 -14
View File
@@ -41,31 +41,31 @@ host('stage')
*/ */
task('build', function (): void { task('build', function (): void {
$node = 'export NVM_DIR="$HOME/.nvm"' $node = 'export NVM_DIR="$HOME/.nvm"'
.' && [ -s "$NVM_DIR/nvm.sh" ]' . ' && [ -s "$NVM_DIR/nvm.sh" ]'
.' && . "$NVM_DIR/nvm.sh"' . ' && . "$NVM_DIR/nvm.sh"'
.' && nvm use {{node_version}}'; . ' && nvm use {{node_version}}';
run( run(
$node $node
.' && cd {{release_path}}' . ' && cd {{release_path}}'
.' && npm ci --no-audit --no-fund' . ' && npm ci --no-audit --no-fund',
); );
run( run(
$node $node
.' && cd {{release_path}}' . ' && cd {{release_path}}'
.' && for lock in Modules/*/package-lock.json; do' . ' && for lock in Modules/*/package-lock.json; do'
.' [ -f "$lock" ] || continue;' . ' [ -f "$lock" ] || continue;'
.' module_dir="$(dirname "$lock")";' . ' module_dir="$(dirname "$lock")";'
.' echo "[Modules] npm ci: $module_dir";' . ' echo "[Modules] npm ci: $module_dir";'
.' (cd "$module_dir" && npm ci --no-audit --no-fund);' . ' (cd "$module_dir" && npm ci --no-audit --no-fund);'
.' done' . ' done',
); );
run( run(
$node $node
.' && cd {{release_path}}' . ' && cd {{release_path}}'
.' && npm run build' . ' && npm run build',
); );
}); });