Skip to content

Commit

Permalink
Support download minify on Windows (#20)
Browse files Browse the repository at this point in the history
Thanks to @rglozman 's help !

---------

Signed-off-by: Simon André <[email protected]>
Co-authored-by: rglozman <[email protected]>
  • Loading branch information
smnandre and rglozman authored Nov 14, 2024
1 parent 8eb1e7b commit 864ada8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.9.3

- Support for Windows

## 0.9.0

- First version of the bundle
2 changes: 1 addition & 1 deletion src/Minifier/SystemUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function getPlatform(string $platform): ?string

private function getArchitecture(string $architecture): ?string
{
return match ($architecture) {
return match (\strtolower($architecture)) {
'amd64', 'x86_64' => self::ARCH_AMD64,
'arm64' => self::ARCH_ARM64,
'i386', 'i686' => self::ARCH_X86,
Expand Down
28 changes: 22 additions & 6 deletions src/MinifyInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,32 @@ public function download(string $version): void
$this->filesystem->appendToFile($downloadFilename, $chunk->getContent(), true);
}

// TODO windows
if (str_ends_with($downloadFilename, '.zip')) {
$download = function () use ($downloadFilename, $tempDir) {
$archive = new \ZipArchive();
$archive->open($downloadFilename);
$archive->extractTo($tempDir, 'minify');
$archive->close();
};
} else {
$download = function () use ($downloadFilename, $tempDir) {
$archive = new \PharData($downloadFilename);
$archive->extractTo($tempDir, ['minify'], true);
};
}

$archive = new \PharData($downloadFilename);
if (!isset($archive['minify'])) {
throw new LogicException('The minify binary is missing from the archive.');
try {
$download();
} catch (\Throwable $e) {
throw new InstallException(sprintf('Error extracting the binary from archive "%s".', $downloadFilename), 0, $e->getPrevious());
}
$archive->extractTo($tempDir, ['minify'], true);

$this->filesystem->mkdir(dirname($this->getInstallBinaryPath()));
$this->filesystem->copy(Path::join($tempDir, 'minify'), $this->getInstallBinaryPath());
if (str_ends_with($downloadFilename, '.zip')) {
$this->filesystem->copy(Path::join($tempDir, 'minify.exe'), $this->getInstallBinaryPath());
} else {
$this->filesystem->copy(Path::join($tempDir, 'minify'), $this->getInstallBinaryPath());
}
$this->filesystem->remove($tempDir);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Command/MinifyAssetCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testMinifyAssetCommandFailsWhenInputFileIsNotCssOrJS(): void
$this->assertSame(Command::FAILURE, $tester->getStatusCode());
$display = $tester->getDisplay();
$this->assertStringContainsString('The type of', $display);
$this->assertStringContainsString('TestKernel.php" is "php", it must be "css" or "js".', $display);
$this->assertStringContainsString('it must be "css" or "js".', $display);
}

public function testMinifyAssetCommandFailsWhenOutputFileIsNotWritable(): void
Expand Down

0 comments on commit 864ada8

Please sign in to comment.