-
Notifications
You must be signed in to change notification settings - Fork 2
/
compileApp.php
114 lines (99 loc) · 2.87 KB
/
compileApp.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
<?php
//header("Content-Type: application/json");
if (isset($_GET['proj'])) {
$project = strval($_GET['proj']);
}
if (isset($_GET['assets'])) {
$assets = $_GET['assets'];
}
include 'config.php';
chdir($projects_path);
chdir($project);
if(file_exists($assets.".assetsfolder") == true && file_get_contents($assets.".assetsfolder") == '1'){
function deleteDirectory($dir) {
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir)) {
return unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
return rmdir($dir);
}
deleteDirectory("www");
mkdir("www");
function recurseCopy(
string $sourceDirectory,
string $destinationDirectory,
string $childFolder = ''
): void {
$directory = opendir($sourceDirectory);
if (is_dir($destinationDirectory) === false) {
mkdir($destinationDirectory);
}
if ($childFolder !== '') {
if (is_dir("$destinationDirectory/$childFolder") === false) {
mkdir("$destinationDirectory/$childFolder");
}
while (($file = readdir($directory)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
if (is_dir("$sourceDirectory/$file") === true) {
recurseCopy("$sourceDirectory/$file", "$destinationDirectory/$childFolder/$file");
} else {
copy("$sourceDirectory/$file", "$destinationDirectory/$childFolder/$file");
}
}
closedir($directory);
return;
}
while (($file = readdir($directory)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
if (is_dir("$sourceDirectory/$file") === true) {
recurseCopy("$sourceDirectory/$file", "$destinationDirectory/$file");
}
else {
copy("$sourceDirectory/$file", "$destinationDirectory/$file");
}
}
closedir($directory);
}
chdir($projects_path.$slash.$project);
recurseCopy($assets,'./www');
$out = "";
$succ = false;
$file = "unknown";
$waitForAPK = false;
if($doSetPath){putenv("PATH=".$path_var);}
exec($cordova_path." build -- --jvmargs='-Xmx1G'",$out);
foreach ($out as $key => $value) {
if((strpos($value,"BUILD SUCCESSFUL")=== false)== false){
$succ = true;
$waitForAPK = false;
}else if((strpos($value,"Built the following apk(s):")=== false)==false){
$waitForAPK = true;
}else if($waitForAPK){
$file = trim($value);
$waitForAPK = false;
}
}
//var_dump($out);
//putenv("PATH");
if ($succ == false) {
$file = false;
}
echo json_encode(array("file"=>$file,"success"=>$succ));
}else{
echo '{"success":0}';
}
?>