forked from banago/PHPloy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
44 lines (34 loc) · 1017 Bytes
/
build
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
#!/usr/bin/env php
<?php
$filename = 'phploy.phar';
$output_dir = __DIR__ . '/bin/';
$output_file = $output_dir . $filename;
// Remove existing file, recursively create directories if needed
@unlink($output_file);
@mkdir($output_dir, 0755, true);
// If vendors directory doesn't exist, try to install with composer
if (! is_dir(__DIR__ . '/vendor')) {
@shell_exec('composer --working-dir="' . __DIR__ . '" install');
}
// Start phar
$phar = new Phar(
$output_file,
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
$filename
);
$phar->startBuffering();
// Adding folders
$phar->buildFromDirectory(
dirname(__FILE__),
'/(src|vendor)\/.*$/'
);
// Adding main file
$phar->addFile('phploy.php');
// Create a stub and add the shebang
$default = $phar->createDefaultStub('phploy.php');
$stub = "#!/usr/bin/env php \n" . $default;
$phar->setStub($stub);
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
// Set file permissions
chmod($output_file, 0755);