2020-09-11 23:16:11 +08:00
|
|
|
#!/usr/bin/php
|
2020-08-10 18:43:02 +08:00
|
|
|
<?php
|
|
|
|
chdir(__DIR__);
|
2020-08-10 19:47:48 +08:00
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$gulp = trim(`which gulp`);
|
|
|
|
if (!$gulp) {
|
|
|
|
exit('gulp not installed, run as root: npm install --global gulp-cli');
|
|
|
|
}
|
2020-08-10 19:47:48 +08:00
|
|
|
|
2020-12-01 01:58:20 +08:00
|
|
|
$options = getopt('', ['docker']);
|
|
|
|
$options['docker'] = isset($options['docker']);
|
|
|
|
|
2020-08-10 19:47:48 +08:00
|
|
|
$package = json_decode(file_get_contents('package.json'));
|
|
|
|
|
2020-10-15 22:21:52 +08:00
|
|
|
$zip_destination = "snappymail-{$package->version}.zip";
|
|
|
|
$tar_destination = "snappymail-{$package->version}.tar";
|
2020-11-26 22:13:55 +08:00
|
|
|
$docker_zip = "./.docker/release/snappymail-{$package->version}.zip";
|
2020-08-10 19:47:48 +08:00
|
|
|
|
|
|
|
@unlink($zip_destination);
|
|
|
|
@unlink($tar_destination);
|
|
|
|
@unlink("{$tar_destination}.gz");
|
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
passthru($gulp, $return_var);
|
|
|
|
if ($return_var) {
|
|
|
|
exit("gulp failed with error code {$return_var}\n");
|
|
|
|
}
|
|
|
|
|
2020-10-15 22:21:52 +08:00
|
|
|
$cmddir = escapeshellcmd(__DIR__) . '/snappymail/v/0.0.0/static';
|
2020-09-23 21:12:22 +08:00
|
|
|
|
2020-08-12 06:25:36 +08:00
|
|
|
if ($gzip = trim(`which gzip`)) {
|
2020-09-23 21:12:22 +08:00
|
|
|
passthru("{$gzip} -k --best {$cmddir}/js/*.js");
|
|
|
|
passthru("{$gzip} -k --best {$cmddir}/js/min/*.js");
|
|
|
|
passthru("{$gzip} -k --best {$cmddir}/css/app*.css");
|
2020-10-15 22:21:52 +08:00
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/boot.js.gz');
|
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/min/boot.min.js.gz');
|
2020-08-12 06:25:36 +08:00
|
|
|
}
|
|
|
|
|
2020-08-24 06:09:54 +08:00
|
|
|
if ($brotli = trim(`which brotli`)) {
|
2020-09-23 21:12:22 +08:00
|
|
|
passthru("{$brotli} -k --best {$cmddir}/js/*.js");
|
|
|
|
passthru("{$brotli} -k --best {$cmddir}/js/min/*.js");
|
|
|
|
passthru("{$brotli} -k --best {$cmddir}/css/app*.css");
|
2020-10-15 22:21:52 +08:00
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/boot.js.br');
|
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/min/boot.min.js.br');
|
2020-08-24 06:09:54 +08:00
|
|
|
}
|
|
|
|
|
2020-08-10 19:47:48 +08:00
|
|
|
// Temporary rename folder to speed up PharData
|
2020-10-15 22:21:52 +08:00
|
|
|
//if (!rename('snappymail/v/0.0.0', "snappymail/v/{$package->version}")){
|
|
|
|
if (!rename('snappymail/v/0.0.0', "snappymail/v/{$package->version}")) {
|
|
|
|
exit('Failed to temporary rename snappymail/v/0.0.0');
|
2020-08-10 19:47:48 +08:00
|
|
|
}
|
|
|
|
register_shutdown_function(function(){
|
|
|
|
// Rename folder back to original
|
2020-10-15 22:21:52 +08:00
|
|
|
@rename("snappymail/v/{$GLOBALS['package']->version}", 'snappymail/v/0.0.0');
|
2020-08-10 19:47:48 +08:00
|
|
|
});
|
2020-08-10 18:43:02 +08:00
|
|
|
|
|
|
|
$zip = new ZipArchive();
|
2020-08-10 19:47:48 +08:00
|
|
|
if (!$zip->open($zip_destination, ZIPARCHIVE::CREATE)) {
|
|
|
|
exit("Failed to create {$zip_destination}");
|
2020-08-10 18:43:02 +08:00
|
|
|
}
|
|
|
|
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar = new PharData($tar_destination);
|
|
|
|
|
2020-10-15 22:21:52 +08:00
|
|
|
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('snappymail/v'), RecursiveIteratorIterator::SELF_FIRST);
|
2020-08-10 18:43:02 +08:00
|
|
|
foreach ($files as $file) {
|
|
|
|
$file = str_replace('\\', '/', $file);
|
2020-11-26 22:10:43 +08:00
|
|
|
//echo "{$file}\n";
|
2020-08-10 18:43:02 +08:00
|
|
|
// Ignore "." and ".." folders
|
2020-08-10 19:47:48 +08:00
|
|
|
if (!in_array(substr($file, strrpos($file, '/')+1), array('.', '..'))) {
|
|
|
|
if (is_dir($file)) {
|
|
|
|
$zip->addEmptyDir($file);
|
|
|
|
} else if (is_file($file)) {
|
|
|
|
$zip->addFile($file);
|
|
|
|
}
|
2020-08-10 18:43:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 01:58:20 +08:00
|
|
|
if ($options['docker']) {
|
|
|
|
$tar->buildFromDirectory('./snappymail/', "@v/{$package->version}@");
|
|
|
|
} else {
|
|
|
|
$tar->buildFromDirectory('./', "@snappymail/v/{$package->version}@");
|
|
|
|
}
|
2020-08-10 19:47:48 +08:00
|
|
|
|
2020-11-03 23:22:26 +08:00
|
|
|
$zip->addFile('data/.htaccess');
|
|
|
|
$tar->addFile('data/.htaccess');
|
2020-09-26 18:25:57 +08:00
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$zip->addFromString('data/VERSION', $package->version);
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar->addFromString('data/VERSION', $package->version);
|
|
|
|
|
2020-11-03 23:22:26 +08:00
|
|
|
$zip->addFile('data/README.md');
|
|
|
|
$tar->addFile('data/README.md');
|
|
|
|
|
|
|
|
//$zip->addFile('data/EMPTY');
|
|
|
|
//$tar->addFile('data/EMPTY');
|
2020-08-10 19:47:48 +08:00
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$zip->addFile('_include.php');
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar->addFile('_include.php');
|
2020-08-10 18:43:02 +08:00
|
|
|
|
2020-09-23 20:49:43 +08:00
|
|
|
$zip->addFile('.htaccess');
|
|
|
|
$tar->addFile('.htaccess');
|
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$index = file_get_contents('index.php');
|
|
|
|
$index = str_replace('0.0.0', $package->version, $index);
|
|
|
|
$index = str_replace('source', 'community', $index);
|
|
|
|
$zip->addFromString('index.php', $index);
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar->addFromString('index.php', $index);
|
2020-08-10 18:43:02 +08:00
|
|
|
|
2020-08-12 06:25:36 +08:00
|
|
|
$zip->addFile('README.md');
|
|
|
|
$tar->addFile('README.md');
|
|
|
|
|
2020-11-24 00:13:38 +08:00
|
|
|
$data = file_get_contents('dev/serviceworker.js');
|
|
|
|
//$data = file_get_contents('snappymail/v/0.0.0/static/js/min/serviceworker.min.js');
|
|
|
|
$zip->addFromString('serviceworker.js', $data);
|
|
|
|
$tar->addFromString('serviceworker.js', $data);
|
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$zip->close();
|
|
|
|
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar->compress(Phar::GZ);
|
|
|
|
unlink($tar_destination);
|
|
|
|
|
|
|
|
echo "\n{$zip_destination} created\n{$tar_destination}.gz created\n";
|
2020-11-26 22:13:55 +08:00
|
|
|
|
|
|
|
// Docker build
|
2020-12-02 22:19:44 +08:00
|
|
|
if (readline("Build Docker image? (Y/N): ") === "Y") {
|
2020-11-26 22:13:55 +08:00
|
|
|
copy($zip_destination, $docker_zip);
|
|
|
|
|
|
|
|
$docker = trim(`which docker`);
|
|
|
|
if(!$docker) {
|
|
|
|
exit("Docker not installed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
passthru("{$docker} build " . __DIR__ . "/.docker/release/ --build-arg FILES_ZIP={$zip_destination} -t snappymail:{$package->version}");
|
2020-12-01 01:58:20 +08:00
|
|
|
}
|