1. <?php
  2. /**
  3. * Boots JavaScript scripts based on CLI arguments for a legacy project.
  4. */
  5. // Get CLI arguments
  6. $argv = array_slice($argv, 1); // Remove script name
  7. // Define argument mappings
  8. $script_map = [
  9. 'script1' => 'scripts/script1.js',
  10. 'script2' => 'scripts/script2.js',
  11. 'script3' => 'scripts/script3.js',
  12. ];
  13. // Check if arguments exist and map to scripts
  14. foreach ($argv as $arg) {
  15. if (isset($script_map[$arg])) {
  16. $script_path = $script_map[$arg];
  17. // Check if the script file exists
  18. if (file_exists($script_path)) {
  19. // Output the script tag
  20. echo "<script src='" . $script_path . "'></script>\n";
  21. } else {
  22. echo "Error: Script file not found: " . $script_path . "\n";
  23. }
  24. } else {
  25. echo "Error: Unknown script argument: " . $arg . "\n";
  26. }
  27. }
  28. ?>

Add your comment