forked from TuffDev/PocketFactions
-
Notifications
You must be signed in to change notification settings - Fork 15
/
make.php
129 lines (117 loc) · 4.15 KB
/
make.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/*
* PocketFactions
*
* Copyright (C) 2015 LegendsOfMCPE
*
* 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.
*
* @author LegendsOfMCPE
*/
use pocketfactions\faction\FactionAccessPrimary;
use pocketfactions\faction\FactionAccessSecondary;
use pocketfactions\faction\FactionAccessTertiary;
use pocketfactions\PocketFactions;
chdir(__DIR__);
$filename = "bin/PocketFactions_Dev.phar";
$class = "dev";
$opts = getopt("", ["rc", "beta"]);
if(isset($opts["beta"])){
$filename = "bin/PocketFactions_Beta.phar";
$class = "beta";
}
if(isset($opts["rc"])){
$filename = "bin/PocketFactions_RC.phar";
$class = "rc";
}
$data = json_decode(file_get_contents("bin/id.json"));
$nextBuildId = ++$data->{$class};
$globalBuildId = ++$data->global;
$author = $data->author;
$version = $data->version->stage . "_" . $data->version->major . "." . $data->version->minor . "." . $globalBuildId . "_" . $class . "#" . $nextBuildId;
$description = $data->description;
$website = $data->website;
file_put_contents("bin/id.json", json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_BIGINT_AS_STRING));
if(is_file($filename)){
unlink($filename);
}
$pluginYml = yaml_emit($manifest = [
"name" => "PocketFactions",
"author" => "LegendsOfMCPE",
"authors" => [
"PEMapModder",
],
"version" => $version,
"api" => ["1.13.0"],
"main" => PocketFactions::class,
"description" => $description,
"website" => $website,
"build" => [
"author" => $author,
"buildTime" => [
"ISO8601" => date(DATE_ISO8601),
"unix" => time(),
],
"type" => $class,
"globalBuildNumber" => $globalBuildId,
"typeVersion" => $nextBuildId,
],
], YAML_UTF8_ENCODING, YAML_LN_BREAK);
$i = 0;
function addDir(\Phar $phar, $realPath, $localPath){
global $i;
$realPath = str_replace("\\", "/", $realPath);
$localPath = rtrim($localPath, "/\\") . "/";
echo "Directory transfer: $realPath > $localPath", PHP_EOL;
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($realPath)) as $path){
if(!$path->isFile()){
continue;
}
$path = str_replace("\\", "/", (string) $path);
if(strpos($path, ".git") !== false){
continue;
}
$relative = ltrim(substr($path, strlen($realPath)), "/");
$local = $localPath . $relative;
$num = str_pad((string) (++$i), 3, "0", STR_PAD_LEFT);
echo "\r[$num] Adding: " . realpath($path) . " to $local";
$phar->addFile($path, $local);
}
echo "\n";
}
$phar = new Phar($filename);
$phar->setStub('<?php require_once "entry/entry.php"; __HALT_COMPILER();');
$phar->setSignatureAlgorithm(Phar::SHA1);
$phar->setMetadata($manifest);
$phar->startBuffering();
$phar->addFromString("plugin.yml", $pluginYml);
addDir($phar, realpath("src"), "src");
addDir($phar, realpath("entry"), "entry");
require_once realpath("src/pocketfactions/faction/FactionAccessPrimary.php");
require_once realpath("src/pocketfactions/faction/FactionAccessSecondary.php");
require_once realpath("src/pocketfactions/faction/FactionAccessTertiary.php");
$consts = [];
loadFactionAccessConstants(FactionAccessPrimary::class, $consts);
loadFactionAccessConstants(FactionAccessSecondary::class, $consts);
loadFactionAccessConstants(FactionAccessTertiary::class, $consts);
file_put_contents("resources/access.json", json_encode($consts, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING));
addDir($phar, realpath("resources"), "resources");
$phar->stopBuffering();
if(is_file("priv/postCompile.php")){
require_once("priv/postCompile.php"); // this is for testing
}
function loadFactionAccessConstants($className, &$output){
$class = new ReflectionClass($className);
$file = $class->getFileName();
foreach($class->getConstants() as $constant => $v){
preg_match($regex = '#/\*\*[\n\r\t ]+((\*[^\*]+)+)[\n\r\t ]+\*/[\n\r\t ]+const[\n\r\t ]+' . $constant . '[\n\r\t ]+=[\n\r\t ]+#m', file_get_contents($file), $match);
$comment = trim(implode("\n", array_map(function ($str){
return substr(trim($str), 2);
}, explode("\n", $match[1]))));
$output[strtolower($constant)] = $comment;
}
}
exec("git add -A");