This repository was archived by the owner on Jan 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathConsoleScript.php
More file actions
92 lines (80 loc) · 3.64 KB
/
Copy pathConsoleScript.php
File metadata and controls
92 lines (80 loc) · 3.64 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
87
88
89
90
91
92
<?php
/*
* DevTools plugin for PocketMine-MP
* Copyright (C) 2014 PocketMine Team <https://github.com/PocketMine/DevTools>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
const VERSION = "1.11.0";
$opts = getopt("", ["make:", "relative:", "out:", "entry:", "compress"]);
if(!isset($opts["make"])){
echo "== PocketMine-MP DevTools CLI interface ==\n\n";
echo "Usage: ". PHP_BINARY ." -dphar.readonly=0 ".$argv[0]." --make <sourceFolder> --relative <relativePath> --entry \"relativeSourcePath.php\" --out <pharName.phar>\n";
exit(0);
}
if(ini_get("phar.readonly") == 1){
echo "Set phar.readonly to 0 with -dphar.readonly=0\n";
exit(1);
}
$folderPath = rtrim(str_replace("\\", "/", realpath($opts["make"])), "/") . "/";
$relativePath = isset($opts["relative"]) ? rtrim(str_replace("\\", "/", realpath($opts["relative"])), "/") . "/" : $folderPath;
$pharName = isset($opts["out"]) ? $opts["out"] : "output.phar";
if(!is_dir($folderPath)){
echo $folderPath ." is not a folder\n";
exit(1);
}
echo "\nCreating ".$pharName."...\n";
$phar = new \Phar($pharName);
if($metadata["name"] === "DevTools"){
$phar->setStub('<?php require("phar://". __FILE__ ."/src/DevTools/ConsoleScript.php"); __HALT_COMPILER();');
}elseif(isset($opts["entry"]) and $opts["entry"] != null){
$entry = addslashes(str_replace("\\", "/", $opts["entry"]));
echo "Setting entry point to ".$entry."\n";
$phar->setStub('<?php require("phar://". __FILE__ ."/'.$entry.'"); __HALT_COMPILER();');
}else{
if(file_exists($relativePath . "plugin.yml")){
$metadata = yaml_parse_file($relativePath."plugin.yml");
$phar->setMetadata([
"name" => $metadata["name"],
"version" => $metadata["version"],
"main" => $metadata["main"],
"api" => $metadata["api"],
"depend" => (isset($metadata["depend"]) ? $metadata["depend"] : ""),
"description" => (isset($metadata["description"]) ?$metadata["description"] : ""),
"authors" => (isset($metadata["authors"]) ? $metadata["authors"] : ""),
"website" => (isset($metadata["website"]) ? $metadata["website"] : ""),
"creationDate" => time()
]);
$phar->setStub('<?php echo "PocketMine-MP plugin '. $metadata["name"] .' v'. $metadata["version"].'\nThis file has been generated using DevTools v" . $version . " at '.date("r").'\n----------------\n";if(extension_loaded("phar")){$phar = new \Phar(__FILE__);foreach($phar->getMetadata() as $key => $value){echo ucfirst($key).": ".(is_array($value) ? implode(", ", $value):$value)."\n";}} __HALT_COMPILER();');
}else{
echo "Missing entry point or plugin.yml\n";
exit(1);
}
}
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
echo "Adding files...\n";
$maxLen = 0;
$count = 0;
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($folderPath)) as $file){
$path = rtrim(str_replace(["\\", $relativePath], ["/", ""], $file), "/");
if($path{0} === "." or strpos($path, "/.") !== false){
continue;
}
$phar->addFile($file, $path);
if(strlen($path) > $maxLen){
$maxLen = strlen($path);
}
echo "\r[".(++$count)."] ".str_pad($path, $maxLen, " ");
}
$phar->stopBuffering();
echo "Done!\n";
exit(0);