2020-09-18 23:30:17 +00:00
|
|
|
<?php
|
2020-09-25 16:36:06 +00:00
|
|
|
|
2020-09-25 16:35:16 +00:00
|
|
|
/**
|
2020-09-25 16:36:06 +00:00
|
|
|
* OPcache GUI - build script
|
2020-09-25 16:35:16 +00:00
|
|
|
*
|
|
|
|
* @author Andrew Collington, andy@amnuts.com
|
2024-06-23 13:01:33 +00:00
|
|
|
* @version 3.5.5
|
2020-09-25 16:35:16 +00:00
|
|
|
* @link https://github.com/amnuts/opcache-gui
|
2021-06-27 11:47:40 +00:00
|
|
|
* @license MIT, https://acollington.mit-license.org/
|
2020-09-25 16:35:16 +00:00
|
|
|
*/
|
2020-09-18 23:30:17 +00:00
|
|
|
|
2023-08-15 16:56:23 +00:00
|
|
|
$remoteJsLocations = [
|
|
|
|
'cloudflare' => [
|
|
|
|
'cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js',
|
|
|
|
'cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js',
|
|
|
|
'cdnjs.cloudflare.com/ajax/libs/axios/1.3.6/axios.min.js',
|
|
|
|
],
|
|
|
|
'jsdelivr' => [
|
|
|
|
'cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js',
|
|
|
|
'cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js',
|
|
|
|
'cdn.jsdelivr.net/npm/axios/dist/axios.min.js',
|
|
|
|
],
|
|
|
|
'unpkg' => [
|
|
|
|
'unpkg.com/react@18/umd/react.production.min.js',
|
|
|
|
'unpkg.com/react-dom@18/umd/react-dom.production.min.js',
|
|
|
|
'unpkg.com/axios/dist/axios.min.js',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$defaultRemoteJsFrom = array_keys($remoteJsLocations)[0];
|
|
|
|
|
|
|
|
$options = getopt('jr:l:', ['local-js', 'remote-js', 'lang:']);
|
2022-07-17 21:21:38 +00:00
|
|
|
$makeJsLocal = (isset($options['j']) || isset($options['local-js']));
|
2023-08-15 16:56:23 +00:00
|
|
|
$useRemoteJsFrom = $options['r'] ?? $options['remote-js'] ?? $defaultRemoteJsFrom;
|
2022-07-18 20:21:27 +00:00
|
|
|
$useLanguage = $options['l'] ?? $options['lang'] ?? null;
|
|
|
|
$languagePack = 'null';
|
2020-09-18 23:30:17 +00:00
|
|
|
$parentPath = dirname(__DIR__);
|
|
|
|
|
2023-08-15 16:56:23 +00:00
|
|
|
if (!isset($remoteJsLocations[$useRemoteJsFrom])) {
|
|
|
|
$validRemotes = implode(', ', array_keys($remoteJsLocations));
|
|
|
|
echo "\nThe '{$useRemoteJsFrom}' remote js location is not valid - must be one of {$validRemotes} - defaulting to '{$defaultRemoteJsFrom}'\n\n";
|
|
|
|
$useRemoteJsFrom = $defaultRemoteJsFrom;
|
|
|
|
}
|
|
|
|
|
2022-07-18 20:21:27 +00:00
|
|
|
if ($useLanguage !== null) {
|
|
|
|
$useLanguage = preg_replace('/[^a-z_-]/', '', $useLanguage);
|
|
|
|
$languageFile = __DIR__ . "/_languages/{$useLanguage}.json";
|
|
|
|
if (!file_exists($languageFile)) {
|
2023-08-15 16:56:23 +00:00
|
|
|
echo "\nThe '{$useLanguage}' file does not exist - using default English\n\n";
|
2022-07-18 20:21:27 +00:00
|
|
|
} else {
|
|
|
|
$languagePack = "<<< EOJSON\n" . file_get_contents($languageFile) . "\nEOJSON";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 23:30:17 +00:00
|
|
|
if (!file_exists($parentPath . '/node_modules')) {
|
|
|
|
echo "🐢 Installing node modules\n";
|
|
|
|
exec('npm install');
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "🏗️ Building js and css\n";
|
|
|
|
chdir($parentPath);
|
|
|
|
exec('npm run compile-jsx');
|
|
|
|
exec('npm run compile-scss');
|
|
|
|
|
|
|
|
echo "🚀 Creating single build file\n";
|
|
|
|
$template = trim(file_get_contents(__DIR__ . '/template.phps'));
|
|
|
|
$jsOutput = trim(file_get_contents(__DIR__ . '/interface.js'));
|
|
|
|
$cssOutput = trim(file_get_contents(__DIR__ . '/interface.css'));
|
2023-09-30 14:20:54 +00:00
|
|
|
$phpOutput = trim(implode('', array_slice(file($parentPath . '/src/Opcache/Service.php'), 7)));
|
2022-07-18 20:21:27 +00:00
|
|
|
|
2020-09-18 23:30:17 +00:00
|
|
|
$output = str_replace(
|
2022-07-17 01:43:40 +00:00
|
|
|
['{{JS_OUTPUT}}', '{{CSS_OUTPUT}}', '{{PHP_OUTPUT}}', '{{LANGUAGE_PACK}}'],
|
2022-07-18 20:21:27 +00:00
|
|
|
[$jsOutput, $cssOutput, $phpOutput, $languagePack],
|
2020-09-18 23:30:17 +00:00
|
|
|
$template
|
|
|
|
);
|
2023-08-15 16:56:23 +00:00
|
|
|
|
2022-07-16 21:52:27 +00:00
|
|
|
if ($makeJsLocal) {
|
2023-08-15 16:56:23 +00:00
|
|
|
echo "🔗 Making js locally in-line\n";
|
|
|
|
$jsContents = [];
|
|
|
|
foreach ($remoteJsLocations[$useRemoteJsFrom] as $jsUrl) {
|
|
|
|
$jsContents[] = file_get_contents('https://' . $jsUrl);
|
2022-07-16 21:52:27 +00:00
|
|
|
}
|
2023-08-15 16:56:23 +00:00
|
|
|
$output = str_replace('{{JS_LIBRARIES}}',
|
|
|
|
"<script>\n" . implode(";\n\n", $jsContents) . ";\n</script>",
|
|
|
|
$output
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
echo "🔗 Using remote js links from '{$useRemoteJsFrom}'\n";
|
|
|
|
$output = str_replace('{{JS_LIBRARIES}}',
|
|
|
|
implode("\n ", array_map(static function ($jsUrl) {
|
|
|
|
return "<script src=\"//{$jsUrl}\"></script>";
|
|
|
|
}, $remoteJsLocations[$useRemoteJsFrom])),
|
|
|
|
$output
|
|
|
|
);
|
2022-07-16 21:52:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 23:30:17 +00:00
|
|
|
file_put_contents($parentPath . '/index.php', $output);
|
|
|
|
|
|
|
|
echo "💯 Done!\n";
|