Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
  • v0.10
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.10.3
  • 0.10.4
  • 0.10.5
  • 0.10.6
  • 0.9.0
  • 0.9.1
11 results

Target

Select target project
  • wpdesk/wp-init
1 result
Select Git revision
  • main
  • v0.10
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.10.3
  • 0.10.4
  • 0.10.5
  • 0.10.6
  • 0.9.0
  • 0.9.1
11 results
Show changes
Commits on Source (3)
# wp-init changelog
## [0.10.1] - 2024-10-08
### Changed
- `wpinit` CLI command automatically seeks for potential plugin file, instead of relying on passing it as argument.
## [0.10.0] - 2024-10-07
### Added
- Dependency injection container compilation on first request.
......
......@@ -11,41 +11,62 @@ if (!file_exists($autoloadPath)) {
}
require_once $autoloadPath;
function displayHelp() {
echo "Usage: " . basename(__FILE__) . " <plugin_file> <cache_dir>\n";
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 " <plugin_file> Path to the input file to parse\n";
echo " <cache_dir> Path to the output file to generate\n";
}
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;
}
$plugin_files[] = $file;
}
closedir( $plugins_dir );
return $plugin_files;
}
if (in_array('--help', $argv) || in_array('-h', $argv)) {
displayHelp();
display_help();
exit(0);
}
if ($argc < 3 || in_array('--help', $argv) || in_array('-h', $argv)) {
if ($argc < 2 || in_array('--help', $argv) || in_array('-h', $argv)) {
echo "\033[31mError: Missing required arguments.\033[0m\n";
displayHelp();
display_help();
exit(1);
}
$inputFile = $argv[1];
$outputDir = rtrim($argv[2], '/\\') . '/';
$outputDir = rtrim($argv[1], '/\\') . '/';
// Check if input file exists
if (!file_exists($inputFile)) {
echo "\033[31mError: Input file '$inputFile' does not exist.\033[0m\n";
$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 {
$parser = new DefaultHeaderParser();
$data = $parser->parse($inputFile);
$dumper = new PhpFileDumper();
$dumper->dump($data, $outputDir . 'plugin.php');
$dumper->dump($plugin_header, $outputDir . 'plugin.php');
echo "\033[32mSuccess: Plugin data generated.\033[0m\n";
exit(0);
......