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 2
/
mkplugin.php
executable file
·105 lines (93 loc) · 2.71 KB
/
mkplugin.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
<?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);
function usage() {
die("Usage:\n\t".CMD." [-o outdir] <src_directory> [extra files]\n");
}
$path = ".";
if (isset($argv[0]) && $argv[0] == '-o') {
array_shift($argv);
$path = array_shift($argv);
if (!isset($path)) die("Must specify output path\n");
if (!is_dir($path)) die("$path: output directory not found\n");
}
$path = preg_replace('/\/*$/',"",$path).'/';
$plug = array_shift($argv);
if (!isset($plug)) usage();
$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");
/*
* Read manifest...
*/
$fp = fopen($pluginYml,"r");
if (!$fp) die("Unable to open $pluginYml\n");
$manifest = [];
while (($ln = fgets($fp)) !== false && !(isset($manifest["name"]) && isset($manifest["version"]))) {
if (preg_match('/^\s*(name|version):\s*(.*)\s*$/',$ln,$mv)) {
$manifest[$mv[1]] = $mv[2];
}
}
fclose($fp);
if (!isset($manifest["name"]) || !isset($manifest["version"])) die("Incomplete plugin manifest\n");
$ignore = [];
if (is_file($plug."ignore.txt")) {
$ignore["ignore.txt"] = "ignore.txt";
foreach (file($plug."ignore.txt") as $ln) {
$ln = trim(preg_replace('/^#.$/',"",$ln));
if ($ln === "") continue;
$ignore[$ln] = $ln;
}
} else {
foreach([".gitignore"] as $i) {
$ignore[$i] = $i;
}
}
$pharname = $manifest["name"]."_v".$manifest["version"].".phar";
$phar = new Phar($path.$pharname);
$phar->setStub('<?php __HALT_COMPILER();');
$phar->setSignatureAlgorithm(Phar::SHA1);
$phar->startBuffering();
echo("Adding sources...\n");
$cnt = 0;
$cc1 = 0;
$cc2 = 0;
$argv[] = 'src';
$argv[] = 'resources';
$argv[] = 'plugin.yml';
$skip[] = [];
foreach ($argv as $top) {
$ftop = $plug.$top;
if (isset($skip[$ftop])) continue;
$skip[$ftop] = $top;
if (is_dir($ftop)) {
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($ftop)) as $s){
if (!is_file($s)) continue;
$cnt++;
$d = substr($s,strlen($plug));
if (isset($ignore[basename($d)]) || isset($ignore[$d])) continue;
echo(" [$cnt] $d\n");
$phar->addFile(realpath($s),$d);
}
} elseif (is_file($ftop)) {
$cnt++;
echo(" [$cnt] $top\n");
$phar->addFile(realpath($ftop),$top);
} else {
continue;
}
}
echo("Compressing files...\n");
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
echo ("Created: $path$pharname\n");