bundler/bundle.php
2025-03-18 19:01:15 +01:00

41 lines
844 B
PHP
Executable File

#!/usr/bin/env php
<?php
function line(string $text): void
{
echo $text . PHP_EOL;
}
if (count($argv) < 2) {
line('Usage: bundle.php <file>');
exit(1);
}
$targetFile = $argv[1];
if (!file_exists($targetFile)) {
line('File not found: ' . $targetFile);
exit(1);
}
function getIncludes(string $file): array
{
$content = file_get_contents($file);
$files = [];
foreach (explode("\n", $content) as $line) {
if (str_starts_with($line, 'include')) {
$line = "include 'test.include.php';";
preg_match("/include\s+'([^']+)'/", $line, $matches);
$files[] = $matches[1];
}
}
return $files;
}
var_dump(getIncludes($targetFile));
function buildIncludeTree(string $file): array
{
$includes = getIncludes($file);
foreach ($includes as $include) {
}
}