Browse Source

feat: option --prod pour copier le phar dans public_html

pull/27/head
Matthieu Marcillaud 3 weeks ago
parent
commit
dc3cd66c84
  1. 2
      .gitignore
  2. 25
      compile
  3. 34
      compiler/Build.php

2
.gitignore vendored

@ -4,6 +4,8 @@
/loader/version.php
/loader/vendor/
/build/
/public_html/spip_loader.php
/public_html/version
/vendor/
/composer.lock
/.php_cs.cache

25
compile

@ -1,12 +1,33 @@
#!/usr/bin/env php
<?php
use League\CLImate\CLImate;
use Spip\Loader\Compiler\Build;
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'vendor/autoload.php';
$config = [
'debug' => false,
'prod' => false,
];
unset($argv[0]);
foreach ($argv as $option) {
try {
match($option) {
'--prod' => $config['prod'] = true,
'--debug' => $config['debug'] = true,
default => throw new \RuntimeException(sprintf('Compile: unknown \'%s\'', $option))
};
} catch (\Exception $e) {
(new CLImate())->error($e->getMessage());
exit(1);
}
}
$build = new Build(
sourceDirectory: __DIR__ . '/loader',
buildDirectory: __DIR__ . '/build',
@ -17,4 +38,8 @@ $build->prepare();
$build->run();
$build->showResults();
if ($config['prod']) {
$build->showCopyTo(__DIR__ . '/public_html');
}
exit(0);

34
compiler/Build.php

@ -64,6 +64,40 @@ class Build {
$climate->out('');
}
public function showCopyTo(string $prodDirectory) {
$climate = new CLImate;
if ($this->copyTo($prodDirectory)) {
$climate->info('> Fichiers copiés en prod');
} else {
$climate->error('! Échec de la recopie en prod');
}
$climate->out();
}
public function copyTo(string $prodDirectory) {
if (!is_dir($prodDirectory)) {
throw new \Exception(sprintf('Directory %s needs to exists', $prodDirectory));
}
$files = [$this->pharFilename, 'version'];
foreach ($files as $file) {
if (!file_exists($this->buildDirectory . '/' . $file)) {
throw new \Exception(sprintf('File %s is not compiled ?', $this->buildDirectory . '/' . $file));
}
}
foreach ($files as $file) {
if (file_exists($prodDirectory . '/' . $file)) {
unlink($prodDirectory . '/' . $file);
}
copy($this->buildDirectory . '/' . $file, $prodDirectory . '/' . $file);
}
foreach ($files as $file) {
if (!file_exists($prodDirectory . '/' . $file)) {
return false;
}
}
return true;
}
public function getStats(): array {
return $this->stats;
}

Loading…
Cancel
Save