This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Arrilot\BitrixSystemCheck\Checks\Greensight; | ||
|
||
use Arrilot\BitrixSystemCheck\Checks\Check; | ||
|
||
class FrontendBuildIsProduction extends Check | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $manifestPath; | ||
|
||
public function __construct($manifestPath) | ||
{ | ||
$this->manifestPath = $manifestPath; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function name() | ||
{ | ||
return "Проверка, что frontend build собран в production режиме..."; | ||
} | ||
|
||
public function run() | ||
{ | ||
$manifestPath = $this->manifestPath; | ||
$manifestData = file_get_contents($manifestPath); | ||
if ($manifestData === false) { | ||
$this->logError('Не удалось прочитать файл ' . $manifestPath); | ||
return false; | ||
} | ||
|
||
$manifest = json_decode($manifestData, true); | ||
if ($manifest === null && json_last_error() !== JSON_ERROR_NONE) { | ||
$this->logError('Не удалось декодировать файл ' . $manifestPath . ': ' . json_last_error()); | ||
return false; | ||
} | ||
|
||
if (empty($manifest['mode'])) { | ||
$this->logError('В манифесте ' . $manifestPath . ' отсутсвует ключ mode, похоже собрана dev сборка'); | ||
return false; | ||
} | ||
|
||
if (!in_array($manifest['mode'], ['prod', 'production'])) { | ||
$this->logError('mode !== prod || production'); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |