This repository has been archived by the owner on Jul 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.php
112 lines (98 loc) · 3.27 KB
/
build.php
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
if (ini_get('phar.readonly')) {
$cmd = escapeshellarg(PHP_BINARY);
$cmd .= ' -d phar.readonly=0';
foreach ($argv as $i) {
$cmd .= ' '.escapeshellarg($i);
}
passthru($cmd,$rv);
exit($rv);
}
define('CMD',array_shift($argv));
error_reporting(E_ALL);
/*
* Build script
*/
$plug = "plugin";
$plug = preg_replace('/\/*$/',"",$plug).'/';
if (!is_dir($plug)) die("$plug: directory doesn't exist!\n");
if (!is_file($pluginYml = $plug."plugin.yml"))
die("missing plugin manifest\n");
if (!is_dir($srcDir = $plug."src/")) die("Source folder not found\n");
$p = new Phar('pmimporter.phar',
FilesystemIterator::CURRENT_AS_FILEINFO
| FilesystemIterator::KEY_AS_FILENAME,
'pmimporter.phar');
// issue the Phar::startBuffering() method call to buffer changes made to the
// archive until you issue the Phar::stopBuffering() command
$p->startBuffering();
// set the Phar file stub
// the file stub is merely a small segment of code that gets run initially
// when the Phar file is loaded, and it always ends with a __HALT_COMPILER()
$p->setStub('<?php Phar::mapPhar(); include "phar://pmimporter.phar/main.php"; __HALT_COMPILER(); ?>');
if ($plug) $p->setSignatureAlgorithm(Phar::SHA1);
foreach (['main.php'] as $f) {
echo ("- $f\n");
$p[$f] = file_get_contents($f);
}
$scripts= ["version","plugin","man"];
$help = "Available sub-commands:\n";
foreach (glob('scripts/*.php') as $fp) {
$f = preg_replace('/^scripts\//','',$fp);
$f = preg_replace('/\.php$/','',$f);
$f = preg_replace('/^pm/','',$f);
$scripts[] = $f;
echo "$fp as $f\n";
$p["scripts/$f.php"] = file_get_contents($fp);
}
sort($scripts);
$p['scripts/help.php'] = "Available sub-commands:\n\t".
implode("\n\t",$scripts)."\n";
$p['scripts/version.php'] = "<?php require_once(CLASSLIB_DIR.'version.txt');";
$p['scripts/man.php'] = file_get_contents('README.md');
$dirs=['classlib'];
while(count($dirs)) {
$d = array_shift($dirs);
$dh = opendir($d) or die("$d: unable to open directory\n");
while (false !== ($f = readdir($dh))) {
if ($f == '.' || $f == '..') continue;
$fpath = "$d/$f";
if (is_dir($fpath)) {
if (!is_link($fpath)) array_push($dirs,$fpath);
continue;
}
if (!is_file($fpath)) continue;
if (preg_match('/\.php$/',$f) || preg_match('/\.txt$/',$f)) {
echo("- $fpath\n");
$p[$fpath] = file_get_contents($fpath);
}
}
closedir($dh);
}
$pmversion = preg_replace('/\s*pmimporter\s*/','',file_get_contents("version.txt"));
$yml = file_get_contents("plugin/plugin.yml");
$yml = str_replace("<PMIMPORTER>",$pmversion,$yml);
$p["plugin.yml"] = $yml;
if (preg_match('/\n\s*version: ([^\s]+)\s*\n/',$yml,$mv)) {
echo "Plugin Version: $mv[1]\n";
$p['scripts/plugin.php'] = "ImportMap v$mv[1]\n";
} else {
$p['scripts/plugin.php'] = "generic ImportMap\n";
}
if ($plug) {
echo("Adding sources...\n");
$cnt = 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($plug)) as $s){
if (!is_file($s)) continue;
$cnt++;
$d = substr($s,strlen($plug));
if ($d == "plugin.yml") continue;
echo(" [$cnt] $d\n");
$p->addFile(realpath($s),$d);
}
}
// COMMENTED THIS OUT AS COMPRESSING WAS GENERATING CORRUPTED ARCHIVES!
//$p->compressFiles(Phar::GZ);
//Stop buffering write requests to the Phar archive, and save changes to disk
$p->stopBuffering();
//echo "my.phar archive has been saved";