1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-22 06:57:53 +00:00
Files
matomo/plugins/CoreVue/Commands/BuildPolyfill.php
Michal Kleiner 9a3ef94df6 [Coding Style] Enable rule PSR12.Files.FileHeader + unify file headers (#22132)
* [Coding Style] Enable rule PSR12.Files.FileHeader

* Apply CS

* Replace Piwik with Matomo in file headers

* Unify file headers (position, no. of lines, https links)

* Rebuild dist files

* Apply CS

* Fix system test that relies on line numbers in a file that had the file header updated

---------

Co-authored-by: Stefan Giehl <stefan@matomo.org>
2024-04-20 20:50:47 +02:00

83 خطوط
2.4 KiB
PHP

<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CoreVue\Commands;
use Piwik\Filesystem;
use Piwik\Plugin\ConsoleCommand;
class BuildPolyfill extends ConsoleCommand
{
protected function configure()
{
$this->setName('vue:build-polyfill');
$this->setDescription('Builds the polyfill UMD.');
$this->addNoValueOption('clear-webpack-cache');
}
public function isEnabled()
{
return \Piwik\Development::isEnabled();
}
protected function doExecute(): int
{
Build::checkVueCliServiceAvailable();
$clearWebpackCache = $this->getInput()->getOption('clear-webpack-cache');
if ($clearWebpackCache) {
$this->clearWebpackCache();
}
$this->createDummyPackageJson();
$dir = PIWIK_INCLUDE_PATH . '/plugins/CoreVue/polyfills';
foreach (['development', 'production'] as $env) {
$command = "cd '$dir' && BROWSERSLIST_IGNORE_OLD_DATA=1 FORCE_COLOR=1 " . Build::getVueCliServiceBin()
. ' build --target app --mode ' . $env . ' --name MatomoPolyfills ./src/index.ts --dest ./dist';
if ($env == 'production') {
$command .= ' --no-clean';
}
passthru($command);
}
$this->deleteExtraFiles();
return self::SUCCESS;
}
private function createDummyPackageJson()
{
$packageJson = file_get_contents(PIWIK_INCLUDE_PATH . '/package.json');
$packageJson = json_decode($packageJson, true);
$dummyPackageJson = [
'name' => '@matomo/polyfills',
'version' => '1.0.0',
'description' => 'dummy package.json required for vue compilation in subdirectory',
'devDependencies' => $packageJson['devDependencies'],
];
$dummyPackageJson = json_encode($dummyPackageJson, JSON_PRETTY_PRINT);
file_put_contents(PIWIK_INCLUDE_PATH . '/plugins/CoreVue/polyfills/package.json', $dummyPackageJson);
}
private function deleteExtraFiles()
{
@unlink(PIWIK_INCLUDE_PATH . "/plugins/CoreVue/polyfills/dist/index.html");
}
private function clearWebpackCache()
{
$path = PIWIK_INCLUDE_PATH . '/plugins/CoreVue/polyfills/node_modules/.cache';
Filesystem::unlinkRecursive($path, true);
}
}