Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
WBP check
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot committed Apr 25, 2019
1 parent ef4f37e commit f6f286d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Checks/Greensight/FrontendBuildIsProduction.php
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;
}
}

0 comments on commit f6f286d

Please sign in to comment.