-
Notifications
You must be signed in to change notification settings - Fork 11
/
build_android_for_eclipse.php
executable file
Β·156 lines (124 loc) Β· 4.35 KB
/
build_android_for_eclipse.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/php
<?php
/**
* This script just download and copy the stuff to the platform/android/assets folder
* it does not run the cordova build
*
*/
include 'config.php';
$weinre = false;
// weinre
$serverIP = '192.168.0.13';
$live = true;
$curpath = getcwd();
if (preg_match('/platforms\/android/',$curpath)) {
$ap = '../../';
}
$server = 'http://seven.dev/';
$srcPath = $ap.'./www_source/';
$path = $ap.'./platforms/android/assets/www/';
// clean assets
echo "Cleaning assets...";
$cleanPaths = array(
'~/Dev/crunch/app/cache/data/*',
'~/Dev/crunch/app/cache/min/*',
// '/Users/arzynik/Sites/crunchbutton/cache/data/*',
// '/Users/arzynik/Sites/crunchbutton/cache/min/*',
$path.'assets'
);
foreach ($cleanPaths as $p) {
shell_exec('rm -Rf '.$p);
}
// delete all js that isnt the generated plugins file
shell_exec("rm -rf $(ls ".$path."*.js|grep -v 'cordova_plugins.js')");
echo "complete.\n";
// create and copy template dirs
echo "Creating directories...";
shell_exec('cp -R '.$srcPath.'assets '.$path.'assets && mv '.$path.'assets/js/* '.$path);
echo "complete.\n";
// delete unused/iphone files
echo "Deleting files...";
$_remove_js = [ 'cordova.js', 'phonegap.js' ];
foreach( $_remove_js as $js ){
shell_exec("rm -rf $path/$js");
}
echo "complete.\n";
// rename files
echo "Renaming files...";
$_rename = [ [ 'from' => 'cordova.3.1.0-android.js', 'to' => 'cordova.js' ] ];
foreach( $_rename as $key => $value ){
$from = $value[ 'from' ];
$to = $value[ 'to' ];
shell_exec("mv $path/$from $path/$to");
}
echo "complete.\n";
// download assets from server
echo "Downloading assets bundle...\n";
function download($file, $dst = null, $usegzip = false) {
global $server, $path, $curpath;
$parts = pathinfo($path.'assets/'.$file);
$dstpath = $dst !== null ? $path.$dst.$parts['basename'] : $path.'assets/'.$file;
echo ' '.$file.'... ';
if (!file_exists($parts['dirname'])) {
mkdir($parts['dirname'], 0755, true);
}
if ($usegzip) {
shell_exec('/usr/local/bin/wget -q -O - --header="Accept-Encoding: gzip" "'.$server.'assets/'.$file.($live ? '?__live=1' : '').'" | gunzip > "'.$dstpath.'"');
} else {
shell_exec('/usr/local/bin/wget -q -O '.$dstpath.' "'.$server.'assets/'.$file.($live ? '?__live=1' : '').'"');
// file_put_contents($path.'assets/'.$file, file_get_contents($server.$file));
}
echo "complete.\n";
}
$assets = json_decode(file_get_contents($server.'api/build'.($live ? '?__live=1' : '')));
$config = json_decode(file_get_contents($server.'api/build/config'.($live ? '?__live=1' : '')));
foreach ($assets as $asset) {
$type = explode('/',$asset);
$type = $type[0];
switch ($type) {
case 'view':
$content .= '<script type="text/ng-template" id="assets/'.$asset.'">'.file_get_contents($server.'assets/'.$asset).'</script>';
break;
case 'audio':
case 'images':
case 'fonts':
download($asset);
break;
case 'js':
download($asset, '', true);
break;
case 'css':
download($asset, null, true);
break;
}
}
echo "Asset download complete.\n";
// create the index file
echo "Building body...\n";
$index = file_get_contents($path.'assets/view/template_android.html');
$body = file_get_contents($server.'assets/view/body.html'.($live ? '?__live=1' : ''));
$index = str_replace('<body></body>', '<body bgcolor="#fffef8" class="ios7 no-init">'.$body.'</body>', $index);
$index = str_replace('<templates></templates>', $content, $index);
if( $weinre ){
$weinreURL = '<script src="http://' . $serverIP . ':8080/target/target-script-min.js#anonymous"></script>';
$index = str_replace( '<!--weinre-->', $weinreURL, $index );
} else {
$index = str_replace( '<!--weinre-->', '', $index );
}
file_put_contents($path.'index.html', $index);
// add facebook to index js
echo "Building index js...\n";
$index = file_get_contents($path.'index.js');
if( $live ){
$index = str_replace('FACEBOOK_APP_IP', 'ID', $index);
} else {
$index = str_replace('FACEBOOK_APP_IP', $config->facebook, $index);
}
$index = str_replace('IPHONE_NATIVE_VERSION', IPHONE_NATIVE_VERSION, $index);
$index = str_replace('ANDROID_NATIVE_VERSION', ANDROID_NATIVE_VERSION, $index);
$index = str_replace('APP_SERVER_URL', $live ? 'https://crunchbutton.com/' : 'http://beta.crunchr.co/', $index);
file_put_contents($path.'index.js', $index);
date_default_timezone_set( 'UTC' );
// yay
echo "\033[32m".($live ? 'LIVE' : 'BETA')." build complete! " . date( 'Y-m-d H:i:s' ) . " (UTC) \033[37m
";