snappymail/build/plugins.php

145 lines
4.3 KiB
PHP
Raw Normal View History

2022-02-07 19:29:19 +08:00
<?php
2022-02-24 19:43:44 +08:00
define('PLUGINS_DEST_DIR', __DIR__ . '/dist/releases/plugins');
2022-02-07 19:29:19 +08:00
is_dir(PLUGINS_DEST_DIR) || mkdir(PLUGINS_DEST_DIR, 0777, true);
2022-08-30 15:55:38 +08:00
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(PLUGINS_DEST_DIR, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $fileinfo) {
$fileinfo->isDir() || unlink($fileinfo->getRealPath());
}
2022-11-29 23:39:26 +08:00
$terser = ROOT_DIR . '/node_modules/terser/bin/terser';
2022-02-07 19:29:19 +08:00
$manifest = [];
require ROOT_DIR . '/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/AbstractPlugin.php';
$keys = [
'author',
'category',
'description',
'file',
'id',
'license',
'name',
'release',
'required',
'type',
'url',
'version'
];
2023-12-09 05:24:04 +08:00
/*
$released = [
'add-x-originating-ip-header',
'avatars',
2023-12-11 18:07:10 +08:00
'backup',
2023-12-09 05:24:04 +08:00
'black-list',
'change-password',
'change-password-froxlor',
'change-password-hestia',
'change-password-hmailserver',
'change-password-ispconfig',
'change-password-poppassd',
'custom-login-mapping',
'imap-contacts-suggestions',
'kolab',
'ldap-contacts-suggestions',
'ldap-identities',
'ldap-login-mapping',
'ldap-mail-accounts',
'login-external',
'login-external-sso',
'login-override',
'login-register',
'login-remote',
'mailbox-detect',
'nextcloud',
'override-smtp-credentials',
'set-remote-addr',
2023-12-11 18:07:10 +08:00
'smtp-use-from-adr-account',
2023-12-09 05:24:04 +08:00
'snowfall-on-login-screen',
'two-factor-auth',
'view-ics',
'white-list'
];
*/
2022-02-07 19:29:19 +08:00
foreach (glob(ROOT_DIR . '/plugins/*', GLOB_NOSORT | GLOB_ONLYDIR) as $dir) {
2022-10-13 05:08:28 +08:00
if (is_file("{$dir}/index.php") && !strpos($dir, '.bak')) {
2022-02-07 19:29:19 +08:00
require "{$dir}/index.php";
$name = basename($dir);
2023-12-09 05:24:04 +08:00
// if (!in_array($name, $released)) continue;
2022-02-07 19:29:19 +08:00
$class = new ReflectionClass(str_replace('-', '', $name) . 'Plugin');
$manifest_item = [];
foreach ($class->getConstants() as $key => $value) {
$key = \strtolower($key);
if (in_array($key, $keys)) {
$manifest_item[$key] = $value;
}
}
$version = $manifest_item['version'];
if (0 < floatval($version)) {
echo "+ {$name} {$version}\n";
2022-11-29 23:39:26 +08:00
// Minify JavaScript
foreach (glob("{$dir}/*.js") as $file) {
if (!strpos($file,'.min')) {
$mfile = str_replace('.js', '.min.js', $file);
passthru("{$terser} {$file} --output {$mfile} --compress 'drop_console' --ecma 6 --mangle");
}
}
foreach (glob("{$dir}/js/*.js") as $file) {
if (!strpos($file,'.min')) {
$mfile = str_replace('.js', '.min.js', $file);
passthru("{$terser} {$file} --output {$mfile} --compress 'drop_console' --ecma 6 --mangle");
}
}
2022-02-07 19:29:19 +08:00
$manifest_item['type'] = 'plugin';
$manifest_item['id'] = $name;
2022-05-01 03:04:41 +08:00
$manifest_item['file'] = "plugins/{$name}-{$version}.tgz";
2022-02-07 19:29:19 +08:00
$tar_destination = PLUGINS_DEST_DIR . "/{$name}-{$version}.tar";
$tgz_destination = PLUGINS_DEST_DIR . "/{$name}-{$version}.tgz";
@unlink($tgz_destination);
@unlink("{$tar_destination}.gz");
$tar = new PharData($tar_destination);
2022-10-13 05:08:28 +08:00
$tar->buildFromDirectory('./plugins/', '/' . \preg_quote("./plugins/{$name}/", '/') . '((?!\.bak).)*$/');
2022-02-07 19:29:19 +08:00
$tar->compress(Phar::GZ);
unlink($tar_destination);
rename("{$tar_destination}.gz", $tgz_destination);
2023-01-12 22:16:32 +08:00
/*
2022-02-07 19:29:19 +08:00
if (Phar::canWrite()) {
$phar_destination = PLUGINS_DEST_DIR . "/{$name}.phar";
@unlink($phar_destination);
$tar = new Phar($phar_destination);
2022-10-13 05:08:28 +08:00
$tar->buildFromDirectory("./plugins/{$name}/", '/^((?!\.bak).)*$/');
2022-02-07 19:29:19 +08:00
$tar->compress(Phar::GZ);
unlink($phar_destination);
rename("{$phar_destination}.gz", $phar_destination);
}
2023-01-12 22:16:32 +08:00
*/
2022-08-30 15:55:38 +08:00
if (isset($options['sign'])) {
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --armor --detach-sign '.escapeshellarg($tgz_destination), $return_var);
$manifest_item['pgp_sig'] = trim(preg_replace('/-----(BEGIN|END) PGP SIGNATURE-----/', '', file_get_contents($tgz_destination.'.asc')));
}
ksort($manifest_item);
$manifest[$name] = $manifest_item;
2022-02-07 19:29:19 +08:00
} else {
echo "- {$name} {$version}\n";
}
} else {
echo "- {$name}\n";
}
}
ksort($manifest);
$manifest = json_encode(array_values($manifest));
$manifest = str_replace('{"', "\n\t{\n\t\t\"", $manifest);
$manifest = str_replace('"}', "\"\n\t}", $manifest);
$manifest = str_replace('}]', "}\n]", $manifest);
$manifest = str_replace('","', "\",\n\t\t\"", $manifest);
$manifest = str_replace('\/', '/', $manifest);
2022-11-07 21:19:16 +08:00
file_put_contents(dirname(PLUGINS_DEST_DIR) . "/packages.json", $manifest);
2022-10-15 05:24:14 +08:00
exit;