Skip to content
Snippets Groups Projects

feat: remove compilation command

Closed Bartek Jaskulski requested to merge v0.10 into main
2 files
+ 58
0
Compare changes
  • Side-by-side
  • Inline

Files

  • Actually, it's better to compile plugin info at build time, because
    later, when client updates the plugin it may be hard to determine
    whether cached file with plugin info should be
    invalidated. Hypothetically, if client has plugin in version 1.0.0, and
    updates to 1.0.1, there's nothing that could tell us, the plugin info
    file is old. The only option would be to read the file and parse headers
    every time, what would defy the cached file purpose. It's just easier
    this way, especially when considering container compilation, which also
    have to be version aware, to make sure only the recent version is used
    for compilation.
    
    Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
+ 66
7
@@ -2,16 +2,75 @@
<?php
use WPDesk\Init\Util\PhpFileDumper;
use WPDesk\Init\Plugin\DefaultHeaderParser;
include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';
$autoloadPath = $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';
if (!file_exists($autoloadPath)) {
echo "\033[31mError: Autoloader not found. Please run composer install.\033[0m\n";
exit(1);
}
require_once $autoloadPath;
$filename = $argv[1] ?? null;
function display_help() {
echo "Usage: " . basename(__FILE__) . " <cache_dir>\n";
echo "Initialize a WordPress plugin by parsing the input file and generating output.\n";
echo "\n";
echo "Arguments:\n";
echo " <cache_dir> Path to the output file to generate\n";
}
$parser = new \WPDesk\Init\Plugin\DefaultHeaderParser();
function get_possible_plugin_files(): array {
$plugins_dir = opendir(getcwd());
$plugin_files = [];
while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
if ( str_starts_with( $file, '.' ) || str_ends_with( $file, '.php' ) === false || is_dir( $file ) ) {
continue;
}
$data = $parser->parse( $filename );
$plugin_files[] = $file;
}
closedir( $plugins_dir );
return $plugin_files;
}
if (in_array('--help', $argv) || in_array('-h', $argv)) {
display_help();
exit(0);
}
if ($argc < 2 || in_array('--help', $argv) || in_array('-h', $argv)) {
echo "\033[31mError: Missing required arguments.\033[0m\n";
display_help();
exit(1);
}
$outputDir = rtrim($argv[1], '/\\') . '/';
$parser = new DefaultHeaderParser();
$plugin_header = [];
foreach (get_possible_plugin_files() as $file) {
$plugin_header = $parser->parse($file);
if (! empty($plugin_header)) {
break;
}
}
if (empty($plugin_header)) {
echo "\033[31mError: No plugin data found. File has to be accessible from project's root folder and include required WordPress plugin headers.\033[0m\n";
exit(1);
}
try {
$dumper = new PhpFileDumper();
$dumper->dump( $parser->parse( $filename ), $argv[2] );
$dumper->dump($plugin_header, $outputDir . 'plugin.php');
//echo "Compile static plugin resources.";
echo "\033[32mSuccess: Plugin data generated.\033[0m\n";
exit(0);
} catch (Exception $e) {
echo "\033[31mError: " . $e->getMessage() . "\n" . $e->getTraceAsString() . "\033[0m\n";
exit(1);
}
Loading