Skip to content

Commit 97a9192

Browse files
authored
Merge pull request #14 from KaririCode-Framework/develop
Develop
2 parents 07b6bac + 38369e7 commit 97a9192

1 file changed

Lines changed: 18 additions & 31 deletions

File tree

bin/build-phar.php

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,26 @@
3232
}
3333
echo " + src/: $added PHP files\n";
3434

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;
5644
}
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";
6254

63-
$relative = 'vendor/' . substr($path, strlen($vendorDir) + 1);
64-
$phar[$relative] = file_get_contents($path);
65-
$vendorAdded++;
66-
}
67-
echo " + vendor/: $vendorAdded files\n";
6855

6956
// ── 3. Add LICENSE ──────────────────────────────────────────
7057
$phar['LICENSE'] = file_get_contents($root . '/LICENSE');

0 commit comments

Comments
 (0)