]> BookStack Code Mirror - system-cli/blobdiff - compile.php
Bumped version
[system-cli] / compile.php
index 725fc9141747ad3807916ca3c1a188d26bbb058b..22b824880a398bf74e52ab5c1726faddd235e585 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
 
 /**
  * This file builds a phar archive to contain our CLI code.
@@ -18,6 +18,10 @@ try {
         unlink($pharFile . '.gz');
     }
 
+    if (is_dir(__DIR__ . '/vendor/phpunit')) {
+        throw new Exception("You should only compile when dev dependencies are NOT installed");
+    }
+
     // create phar
     $phar = new Phar($pharFile);
 
@@ -28,9 +32,10 @@ try {
     $defaultStub = $phar->createDefaultStub('run.php');
 
     // Add the rest of the apps files
+    $escapedDir = preg_quote(__DIR__, '/');
     $phar->addFile(__DIR__ . '/run.php', 'run.php');
-    $phar->buildFromDirectory(__DIR__, '/src(.*)/');
-    $phar->buildFromDirectory(__DIR__, '/vendor(.*)\.php$/');
+    $phar->buildFromDirectory(__DIR__, "/{$escapedDir}\\/src(.*)\.php$/");
+    $phar->buildFromDirectory(__DIR__, "/{$escapedDir}\\/vendor(.*)\.php$/");
 
     // Customize the stub to add the shebang
     $stub = "#!/usr/bin/env php \n" . $defaultStub;
@@ -44,9 +49,12 @@ try {
     $phar->compressFiles(Phar::GZ);
 
     # Make the file executable
-    chmod(__DIR__ . "/{$pharFile}", 0770);
+    chmod(__DIR__ . "/{$pharFile}", 0775);
+    if (filesize(__DIR__ . "/{$pharFile}") > 500000) {
+        throw new Exception("Phar size unusually large. Check extra files are not included by mistake.");
+    }
 
     echo "$pharFile successfully created" . PHP_EOL;
 } catch (Exception $e) {
-    echo $e->getMessage();
+    echo "ERROR: " . $e->getMessage() . "\n";
 }