-
Notifications
You must be signed in to change notification settings - Fork 640
/
build.php
164 lines (151 loc) · 5.16 KB
/
build.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
157
158
159
160
161
162
163
164
#!/usr/bin/php
<?php
$config = [
'project_path' => '/work/DesktopNaotu',
'build_path' => '/work/OutApp',
'release_path' => '/home/www/downloads/releases'
];
function config($key) {
global $config;
return $config[$key];
}
function changeDir($type) {
global $config;
switch ($type) {
case 'project':
chdir(config('project_path'));
break;
case 'release':
chdir(config('release_path'));
break;
}
}
function getAllVersions() {
changeDir('project');
exec('git tag', $output, $return_ver);
if ($return_ver == 0) {
foreach ($output as $key => $value) {
$output[$key] = substr($value, 1);
}
return $output;
} else {
return [];
}
}
function getExistsVersion() {
$d = dir(config('release_path'));
$result = [];
while (false !== ($entry = $d->read())) {
$full_path = config('release_path') . '/' . $entry;
if (is_dir($full_path) && ($entry !== '.') && ($entry !== '..')) {
$result []= $entry;
}
}
return $result;
}
function getNewVersions() {
$ignoreVersions = ['0.1.1', '0.1.3', '0.1.5', '0.1.6', '0.1.7',
'1.0.0', '1.0.1', '1.0.2', '1.0.3', '1.5.2018',
'2.0.2018', '2.1.1',
'3.0.0', '3.2.0-Beta', '3.2.1-Bata'];
$allVersions = getAllVersions();
$existsVersions = getExistsVersion();
$result = [];
foreach ($allVersions as $version) {
if (in_array($version, $ignoreVersions) || in_array($version, $existsVersions)) {
continue;
}
$result []= $version;
}
return $result;
}
function RunCommand($command) {
echo "Running {$command}\n";
exec($command);
}
function package($ver, $version) {
$currentDir = getcwd();
changeDir('project');
$releaseDir = config('release_path');
$versionReleaseDir = $releaseDir . "/{$version}";
if (!file_exists($versionReleaseDir)) {
mkdir($versionReleaseDir);
}
switch ($ver) {
case "win32":
RunCommand("rm -rf " . config('build_path') . "/DesktopNaotu-win32-ia32");
RunCommand('npm run packwin32');
$dir = config('build_path') . '/DesktopNaotu-win32-ia32';
chdir($dir);
$archiveName = config('build_path') . "/iNaotu-{$version}-win32.7z";
RunCommand("7za a {$archiveName} $dir/*");
RunCommand("cp {$archiveName} {$versionReleaseDir}");
break;
case "win32dev":
RunCommand("rm -rf " . config('build_path') . "/DesktopNaotu-win32-ia32");
RunCommand('npm run packwin32dev');
$dir = config('build_path') . '/DesktopNaotu-win32-ia32';
chdir($dir);
$archiveName = config('build_path') . "/iNaotu-{$version}-win32-dev.7z";
RunCommand("7za a {$archiveName} $dir/*");
RunCommand("cp {$archiveName} {$versionReleaseDir}");
break;
case "win64":
RunCommand("rm -rf " . config('build_path') . "/DesktopNaotu-win32-x64");
RunCommand('npm run packwin64');
$dir = config('build_path') . '/DesktopNaotu-win32-x64';
chdir($dir);
$archiveName = config('build_path') . "/iNaotu-{$version}-win64.7z";
RunCommand("7za a {$archiveName} $dir/*");
RunCommand("cp {$archiveName} {$versionReleaseDir}");
break;
case "linux":
RunCommand("rm -rf " . config('build_path') . "/DesktopNaotu-linux-x64");
RunCommand('npm run packlinux');
$dir = config('build_path') . '/DesktopNaotu-linux-x64';
chdir($dir);
$archiveName = config('build_path') . "/iNaotu-{$version}-linux-x64.7z";
RunCommand("7za a {$archiveName} $dir/*");
RunCommand("cp {$archiveName} {$versionReleaseDir}");
break;
case "macos":
RunCommand("rm -rf " . config('build_path') . "/DesktopNaotu-darwin-x64");
RunCommand('npm run packmacos');
$dir = config('build_path') . '/DesktopNaotu-darwin-x64';
chdir($dir);
$archiveName = config('build_path') . "/iNaotu-{$version}-macos-x64.7z";
RunCommand("7za a {$archiveName} $dir/*");
RunCommand("cp {$archiveName} {$versionReleaseDir}");
break;
}
chdir($currentDir);
}
function build($version) {
changeDir('project');
RunCommand('git checkout .');
RunCommand("git checkout v{$version}");
RunCommand('npm install');
RunCommand('bower install');
RunCommand('gulp');
RunCommand("rm -rf " . config('build_path') . "/*");
package('win32', $version);
package('win32dev', $version);
package('win64', $version);
package('linux', $version);
package('macos', $version);
}
function updateRepo() {
changeDir('project');
RunCommand('git checkout master');
RunCommand('git checkout .');
RunCommand('git pull');
}
function run() {
updateRepo();
$newVersions = getNewVersions();
foreach ($newVersions as $version) {
echo "Building {$version}\n";
build($version);
}
}
run();