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
|
<?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(): bool
{
return \Piwik\Development::isEnabled();
}
protected function doExecute(): int
{
Build::checkVueCliServiceAvailable();
$clearWebpackCache = $this->getInput()->getOption('clear-webpack-cache');
if ($clearWebpackCache) {
$this->clearWebpackCache();
}
$this->createDummyPackageJson();
$dir = MATOMO_PLUGINS_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(MATOMO_PLUGINS_PATH . '/plugins/CoreVue/polyfills/package.json', $dummyPackageJson);
}
private function deleteExtraFiles()
{
@unlink(MATOMO_PLUGINS_PATH . "/plugins/CoreVue/polyfills/dist/index.html");
}
private function clearWebpackCache()
{
$path = MATOMO_PLUGINS_PATH . '/plugins/CoreVue/polyfills/node_modules/.cache';
Filesystem::unlinkRecursive($path, true);
}
}
|