|
32 | 32 | } |
33 | 33 | echo " + src/: $added PHP files\n"; |
34 | 34 |
|
35 | | -// ── 2. Add vendor/ (PHP files only, no tests/docs) ───────── |
36 | | -$vendorDir = $root . '/vendor'; |
37 | | -$excludeDirs = ['Tests', 'tests', 'test', 'doc', 'docs', 'examples', '.github']; |
38 | | - |
39 | | -$vendorIt = new RecursiveIteratorIterator( |
40 | | - new RecursiveDirectoryIterator($vendorDir, FilesystemIterator::SKIP_DOTS), |
41 | | - RecursiveIteratorIterator::LEAVES_ONLY |
42 | | -); |
43 | | - |
44 | | -$vendorAdded = 0; |
45 | | -foreach ($vendorIt as $file) { |
46 | | - if (!$file->isFile()) continue; |
47 | | - $path = $file->getPathname(); |
48 | | - |
49 | | - // Skip test/doc directories |
50 | | - $skip = false; |
51 | | - foreach ($excludeDirs as $ex) { |
52 | | - if (str_contains($path, DIRECTORY_SEPARATOR . $ex . DIRECTORY_SEPARATOR)) { |
53 | | - $skip = true; |
54 | | - break; |
55 | | - } |
| 35 | +// ── 2. Minimal PSR-4 autoloader (no Composer vendor/ needed) ─ |
| 36 | +// The project has zero PHP production dependencies. |
| 37 | +// We generate a lean autoloader that maps KaririCode\Devkit → src/. |
| 38 | +$autoloader = <<<'PHP' |
| 39 | +<?php |
| 40 | +spl_autoload_register(static function (string $class): void { |
| 41 | + $prefix = 'KaririCode\\Devkit\\'; |
| 42 | + if (!str_starts_with($class, $prefix)) { |
| 43 | + return; |
56 | 44 | } |
57 | | - if ($skip) continue; |
58 | | - |
59 | | - // Only PHP and JSON files |
60 | | - $ext = $file->getExtension(); |
61 | | - if (!in_array($ext, ['php', 'json'], true)) continue; |
| 45 | + $relative = substr($class, strlen($prefix)); |
| 46 | + $file = 'phar://kcode.phar/src/' . str_replace('\\', '/', $relative) . '.php'; |
| 47 | + if (is_file($file)) { |
| 48 | + require $file; |
| 49 | + } |
| 50 | +}); |
| 51 | +PHP; |
| 52 | +$phar['vendor/autoload.php'] = $autoloader; |
| 53 | +echo " + vendor/autoload.php: inline PSR-4 autoloader\n"; |
62 | 54 |
|
63 | | - $relative = 'vendor/' . substr($path, strlen($vendorDir) + 1); |
64 | | - $phar[$relative] = file_get_contents($path); |
65 | | - $vendorAdded++; |
66 | | -} |
67 | | -echo " + vendor/: $vendorAdded files\n"; |
68 | 55 |
|
69 | 56 | // ── 3. Add LICENSE ────────────────────────────────────────── |
70 | 57 | $phar['LICENSE'] = file_get_contents($root . '/LICENSE'); |
|
0 commit comments