-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.php
More file actions
executable file
·86 lines (67 loc) · 2.19 KB
/
build.php
File metadata and controls
executable file
·86 lines (67 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env php
<?php
/**
* Build script for creating oce-import-codes.phar
*
* @package OpenCoreEMR\CLI\ImportCodes
* @author Michael A. Smith <michael@opencoreemr.com>
* @copyright Copyright (c) 2025 OpenCoreEMR Inc
* @license GPL-3.0-or-later
*/
declare(strict_types=1);
// Check if we're running from CLI
if (php_sapi_name() !== 'cli') {
echo "This script must be run from the command line.\n";
exit(1);
}
// Check if phar.readonly is disabled
if (ini_get('phar.readonly')) {
echo "Error: phar.readonly is enabled. Run with: php -d phar.readonly=0 build.php\n";
exit(1);
}
$buildDir = __DIR__ . '/build';
$pharFile = $buildDir . '/oce-import-codes.phar';
// Determine version: BUILD_VERSION env var > git describe > fallback
$version = getenv('BUILD_VERSION') ?: null;
if (!$version) {
$version = trim((string) shell_exec('git describe --tags 2>/dev/null')) ?: 'dev';
}
echo "Building oce-import-codes.phar (version: $version)...\n";
// Create build directory
if (!is_dir($buildDir)) {
mkdir($buildDir, 0755, true);
}
// Remove existing phar
if (file_exists($pharFile)) {
unlink($pharFile);
}
try {
$phar = new Phar($pharFile);
// Set metadata
$phar->setMetadata([
'name' => 'oce-import-codes',
'version' => $version,
'created' => date('Y-m-d H:i:s')
]);
// Start buffering
$phar->startBuffering();
// Add source files
echo "Adding source files...\n";
$phar->buildFromDirectory(__DIR__, '/^(?!.*\/(?:build|tests|\.git)).*$/');
// Set stub with proper shebang
$stub = "#!/usr/bin/env php\n" . $phar->createDefaultStub('bin/oce-import-codes');
$phar->setStub($stub);
// Stop buffering and write
$phar->stopBuffering();
// Compress
echo "Compressing...\n";
$phar->compressFiles(Phar::GZ);
// Make executable
chmod($pharFile, 0755);
echo "✅ PHAR built successfully: $pharFile\n";
echo " Size: " . number_format(filesize($pharFile)) . " bytes\n";
echo " Usage: ./build/oce-import-codes.phar RXNORM /path/to/rxnorm.zip --openemr-path=/var/www/openemr\n";
} catch (Throwable $e) {
echo "❌ Error building PHAR: " . $e->getMessage() . "\n";
exit(1);
}