chore: Better handling errors during installation

This commit is contained in:
Phan An 2019-09-10 20:30:38 +02:00
parent 9f21e5a879
commit d55a823036
5 changed files with 50 additions and 17 deletions

View file

@ -6,6 +6,7 @@ APP_NAME=Koel
# pgsql (PostgreSQL)
# sqlsrv (Microsoft SQL Server)
# sqlite-persistent (Local sqlite file)
# IMPORTANT: This value must present for artisan koel:init command to work.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306

View file

@ -2,6 +2,7 @@
namespace App\Console\Commands;
use App\Exceptions\InstallationFailedException;
use App\Models\Setting;
use App\Models\User;
use App\Repositories\SettingRepository;
@ -53,13 +54,21 @@ class InitCommand extends Command
$this->info('Running in no-interaction mode');
}
$this->maybeGenerateAppKey();
$this->maybeGenerateJwtSecret();
$this->maybeSetUpDatabase();
$this->migrateDatabase();
$this->maybeSeedDatabase();
$this->maybeSetMediaPath();
$this->compileFrontEndAssets();
try {
$this->maybeGenerateAppKey();
$this->maybeGenerateJwtSecret();
$this->maybeSetUpDatabase();
$this->migrateDatabase();
$this->maybeSeedDatabase();
$this->maybeSetMediaPath();
$this->compileFrontEndAssets();
} catch (Exception $e) {
$this->error("Oops! Koel installation or upgrade didn't finish successfully.");
$this->error('Please try again, or visit '.config('koel.misc.docs_url').' for manual installation.');
$this->error('😥 Sorry for this. You deserve better.');
return;
}
$this->comment(PHP_EOL.'🎆 Success! Koel can now be run from localhost with `php artisan serve`.');
@ -67,10 +76,13 @@ class InitCommand extends Command
$this->comment('You can also scan for media with `php artisan koel:sync`.');
}
$this->comment('Again, for more configuration guidance, refer to');
$this->info('📙 '.config('koel.misc.docs_url'));
$this->comment('or open the .env file in the root installation folder.');
$this->comment('Thanks for using Koel. You rock!');
$this->comment('Again, visit 📙 '.config('koel.misc.docs_url').' for the official documentation.');
$this->comment(
"Feeling generous and want to support Koel's development? Check out "
.config('koel.misc.sponsor_github_url')
.' 🤗'
);
$this->comment('Thanks for using Koel. You rock! 🤘');
}
/**
@ -237,16 +249,25 @@ class InitCommand extends Command
{
$this->info('Now to front-end stuff');
// We need to run two yarn commands:
// We need to run several yarn commands:
// - The first to install node_modules in the resources/assets submodule
// - The second for the root folder, to build Koel's front-end assets with Mix.
// - The second and third for the root folder, to build Koel's front-end assets with Mix.
chdir('./resources/assets');
$this->info('├── Installing Node modules in resources/assets directory');
system('yarn --colors');
$runOkOrThrow = static function (string $command): void {
passthru($command, $status);
throw_if((bool) $status, InstallationFailedException::class);
};
$runOkOrThrow('yarn install --colors');
chdir('../..');
$this->info('└── Compiling assets');
system('yarn --colors');
system('yarn production --colors');
$runOkOrThrow('yarn install --colors');
$runOkOrThrow('yarn production --colors');
}
/** @return array<string> */

View file

@ -0,0 +1,9 @@
<?php
namespace App\Exceptions;
use RuntimeException;
class InstallationFailedException extends RuntimeException
{
}

View file

@ -129,6 +129,8 @@ return [
'misc' => [
'home_url' => 'https://koel.phanan.net/',
'docs_url' => 'https://koel.phanan.net/docs',
'sponsor_github_url' => 'https://github.com/users/phanan/sponsorship',
'sponsor_open_collective_url' => 'https://opencollective.com/koel',
],
];

@ -1 +1 @@
Subproject commit d4bb207c3307dc69301db821586bd2383c29898a
Subproject commit d197c9a443ce4adf4ae661b4abfad8e96555b138