Skip to content

Commit 864ada8

Browse files
smnandrerglozman
andauthored
Support download minify on Windows (#20)
Thanks to @rglozman 's help ! --------- Signed-off-by: Simon André <[email protected]> Co-authored-by: rglozman <[email protected]>
1 parent 8eb1e7b commit 864ada8

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 0.9.3
4+
5+
- Support for Windows
6+
37
## 0.9.0
48

59
- First version of the bundle

src/Minifier/SystemUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function getPlatform(string $platform): ?string
6262

6363
private function getArchitecture(string $architecture): ?string
6464
{
65-
return match ($architecture) {
65+
return match (\strtolower($architecture)) {
6666
'amd64', 'x86_64' => self::ARCH_AMD64,
6767
'arm64' => self::ARCH_ARM64,
6868
'i386', 'i686' => self::ARCH_X86,

src/MinifyInstaller.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,32 @@ public function download(string $version): void
8282
$this->filesystem->appendToFile($downloadFilename, $chunk->getContent(), true);
8383
}
8484

85-
// TODO windows
85+
if (str_ends_with($downloadFilename, '.zip')) {
86+
$download = function () use ($downloadFilename, $tempDir) {
87+
$archive = new \ZipArchive();
88+
$archive->open($downloadFilename);
89+
$archive->extractTo($tempDir, 'minify');
90+
$archive->close();
91+
};
92+
} else {
93+
$download = function () use ($downloadFilename, $tempDir) {
94+
$archive = new \PharData($downloadFilename);
95+
$archive->extractTo($tempDir, ['minify'], true);
96+
};
97+
}
8698

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

93105
$this->filesystem->mkdir(dirname($this->getInstallBinaryPath()));
94-
$this->filesystem->copy(Path::join($tempDir, 'minify'), $this->getInstallBinaryPath());
106+
if (str_ends_with($downloadFilename, '.zip')) {
107+
$this->filesystem->copy(Path::join($tempDir, 'minify.exe'), $this->getInstallBinaryPath());
108+
} else {
109+
$this->filesystem->copy(Path::join($tempDir, 'minify'), $this->getInstallBinaryPath());
110+
}
95111
$this->filesystem->remove($tempDir);
96112
}
97113

tests/Command/MinifyAssetCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testMinifyAssetCommandFailsWhenInputFileIsNotCssOrJS(): void
7676
$this->assertSame(Command::FAILURE, $tester->getStatusCode());
7777
$display = $tester->getDisplay();
7878
$this->assertStringContainsString('The type of', $display);
79-
$this->assertStringContainsString('TestKernel.php" is "php", it must be "css" or "js".', $display);
79+
$this->assertStringContainsString('it must be "css" or "js".', $display);
8080
}
8181

8282
public function testMinifyAssetCommandFailsWhenOutputFileIsNotWritable(): void

0 commit comments

Comments
 (0)