Skip to content
Snippets Groups Projects
Select Git revision
  • b30935d1860a9c834a564ecffde5d3a5fcb9c567
  • main default protected
  • v0.10
  • 0.10.6
  • 0.10.5
  • 0.10.4
  • 0.10.3
  • 0.10.2
  • 0.10.1
  • 0.10.0
  • 0.9.1
  • 0.9.0
12 results

wpinit

Blame
    • Bartek Jaskulski's avatar
      b30935d1
      feat: reintroduce command to compile plugin info · b30935d1
      Bartek Jaskulski authored
      
      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>
      Verified
      b30935d1
      History
      feat: reintroduce command to compile plugin info
      Bartek Jaskulski authored
      
      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>
    wpinit 1.54 KiB
    #!/usr/bin/env php
    <?php
    
    use WPDesk\Init\Util\PhpFileDumper;
    use WPDesk\Init\Plugin\DefaultHeaderParser;
    
    $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;
    
    function displayHelp() {
        echo "Usage: " . basename(__FILE__) . " <plugin_file> <cache_dir>\n";
        echo "Initialize a WordPress plugin by parsing the input file and generating output.\n";
        echo "\n";
        echo "Arguments:\n";
        echo "  <plugin_file> Path to the input file to parse\n";
        echo "  <cache_dir>   Path to the output file to generate\n";
    }
    
    if (in_array('--help', $argv) || in_array('-h', $argv)) {
        displayHelp();
        exit(0);
    }
    
    if ($argc < 3 || in_array('--help', $argv) || in_array('-h', $argv)) {
        echo "\033[31mError: Missing required arguments.\033[0m\n";
    	displayHelp();
        exit(1);
    }
    
    $inputFile = $argv[1];
    $outputDir = rtrim($argv[2], '/\\') . '/';
    
    // Check if input file exists
    if (!file_exists($inputFile)) {
        echo "\033[31mError: Input file '$inputFile' does not exist.\033[0m\n";
        exit(1);
    }
    
    try {
        $parser = new DefaultHeaderParser();
        $data = $parser->parse($inputFile);
    
        $dumper = new PhpFileDumper();
        $dumper->dump($data, $outputDir . 'plugin.php');
    
        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);
    }