Skip to content

Commit 4d6b6b2

Browse files
authored
Windows build (#213)
* Windows build * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Fix code styling * wip * wip * wip * Fix code styling * wip * Fix code styling * wip * wip * Fix code styling * wip --------- Co-authored-by: driesvints <driesvints@users.noreply.github.com>
1 parent 156e165 commit 4d6b6b2

File tree

7 files changed

+72
-42
lines changed

7 files changed

+72
-42
lines changed

.github/workflows/tests.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- cron: '0 0 * * *'
1111

1212
jobs:
13-
tests:
13+
ubuntu:
1414
runs-on: ubuntu-latest
1515

1616
strategy:
@@ -28,7 +28,7 @@ jobs:
2828
- php: 8.2
2929
laravel: 8
3030

31-
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
31+
name: Ubuntu - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
3232

3333
steps:
3434
- name: Checkout code
@@ -48,3 +48,33 @@ jobs:
4848
4949
- name: Execute tests
5050
run: vendor/bin/phpunit --verbose
51+
52+
windows:
53+
runs-on: windows-latest
54+
55+
strategy:
56+
fail-fast: true
57+
matrix:
58+
php: [8.2]
59+
laravel: [10]
60+
61+
name: Windows - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
62+
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v2
66+
67+
- name: Setup PHP
68+
uses: shivammathur/setup-php@v2
69+
with:
70+
php-version: ${{ matrix.php }}
71+
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, pdo_mysql, fileinfo, ftp, gmp
72+
coverage: none
73+
74+
- name: Install dependencies
75+
run: |
76+
composer require "illuminate/contracts=^${{ matrix.laravel }}" --prefer-dist --no-interaction --no-update
77+
composer update --prefer-dist --no-interaction --no-progress
78+
79+
- name: Execute tests
80+
run: vendor/bin/phpunit --verbose

pint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"notPath": [
3+
"tests/fixtures/blade-icons.php",
34
"tests/fixtures/generated-manifest.php"
45
]
56
}

src/IconsManifest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public function delete(): bool
7878
private function format(string $pathname, string $path): string
7979
{
8080
return (string) Str::of($pathname)
81-
->after($path.'/')
82-
->replace('/', '.')
81+
->after($path.DIRECTORY_SEPARATOR)
82+
->replace(DIRECTORY_SEPARATOR, '.')
8383
->basename('.svg');
8484
}
8585

src/Svg.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ protected function deferContent(string $contents, $defer = false): string
4848
}
4949

5050
$svgContent = strip_tags($contents, ['circle', 'ellipse', 'line', 'path', 'polygon', 'polyline', 'rect', 'g', 'mask', 'defs', 'use']);
51-
$hash = 'icon-'.(is_string($defer) ? $defer : md5($svgContent));
52-
$contents = str_replace($svgContent, strtr('<use href=":href"></use>', [':href' => '#'.$hash]), $contents);
53-
$contents .= <<<BLADE
5451

52+
// Force Unix line endings for hash.
53+
$hashContent = str_replace(PHP_EOL, "\n", $svgContent);
54+
$hash = 'icon-'.(is_string($defer) ? $defer : md5($hashContent));
55+
56+
$contents = str_replace($svgContent, strtr('<use href=":href"></use>', [':href' => '#'.$hash]), $contents).PHP_EOL;
57+
$svgContent = ltrim($svgContent, PHP_EOL);
58+
$contents .= <<<BLADE
5559
@once("{$hash}")
5660
@push("bladeicons")
5761
<g id="{$hash}">

tests/IconsManifestTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function tearDown(): void
3030
private function expectedManifest(): string
3131
{
3232
return trim(str_replace(
33-
'{{ dir }}',
34-
__DIR__,
33+
['{{ dir }}', '/'],
34+
[__DIR__, DIRECTORY_SEPARATOR],
3535
file_get_contents(__DIR__.'/fixtures/generated-manifest.php'),
3636
));
3737
}
@@ -43,9 +43,13 @@ public function it_can_write_the_manifest_file()
4343
$manifest->write($this->prepareSets()->all());
4444

4545
$this->assertTrue(file_exists($this->manifestPath));
46-
$this->assertSame(
46+
$this->assertEquals(
4747
$this->expectedManifest(),
48-
str_replace(" \n", "\n", file_get_contents($this->manifestPath)),
48+
stripslashes(str_replace(
49+
["\n", '=> '.PHP_EOL],
50+
[PHP_EOL, '=>'.PHP_EOL],
51+
file_get_contents($this->manifestPath)
52+
)),
4953
);
5054
}
5155

tests/SvgTest.php

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,18 @@ public function it_can_compile_to_defered_html_with_group_custom_defer()
9898
/** @test */
9999
public function it_can_compile_to_defered_html_with_group_and_whitespace()
100100
{
101-
$svgPath = '
102-
<g id="test" transform="translate(1 1)">
101+
$svgPath = '<g id="test" transform="translate(1 1)">
103102
<path d="M14 5l7 7m0 0l-7 7m7-7H3"></path>
104103
</g>';
105104
$svg = new Svg('heroicon-o-arrow-right', '<svg>'.$svgPath.'</svg>', ['defer' => true]);
106105

107106
$svgHtml = $svg->toHtml();
108107

109-
$this->assertEquals('<svg defer="1"><use href="#icon-e691490d4580d7276ba2a39a287f365f"></use></svg>
110-
@once("icon-e691490d4580d7276ba2a39a287f365f")
108+
$this->assertEquals('<svg defer="1"><use href="#icon-7f6f192a3c61bd15e25530394ec18d86"></use></svg>
109+
@once("icon-7f6f192a3c61bd15e25530394ec18d86")
111110
@push("bladeicons")
112-
<g id="icon-e691490d4580d7276ba2a39a287f365f">
113-
114-
<g id="test" transform="translate(1 1)">
111+
<g id="icon-7f6f192a3c61bd15e25530394ec18d86">
112+
<g id="test" transform="translate(1 1)">
115113
<path d="M14 5l7 7m0 0l-7 7m7-7H3"></path>
116114
</g>
117115
</g>
@@ -122,20 +120,18 @@ public function it_can_compile_to_defered_html_with_group_and_whitespace()
122120
/** @test */
123121
public function it_can_compile_to_defered_html_with_mask_tag()
124122
{
125-
$svgPath = '
126-
<mask id="test" fill="#fff">
123+
$svgPath = '<mask id="test" fill="#fff">
127124
<path d="M0 30c0 16.56 13.44 30 30 30 16.56 0 30-13.44 30-30C60 13.44 46.56 0 30 0 13.44 0 0 13.44 0 30Zm4.35 0C4.35 15.84 15.845 4.35 30 4.35c6.295 0 12.08 2.27 16.495 6.04l-29.87 29.93-6.165 6.17C6.625 42.075 4.35 36.3 4.35 30Zm45.26-16.555c3.77 4.475 6.04 10.26 6.04 16.49 0 14.22-11.49 25.715-25.65 25.715-6.3 0-12.08-2.275-16.49-6.04l5.905-5.91-.005-.005 30.2-30.25Z" />
128125
</mask>';
129126
$svg = new Svg('heroicon-o-arrow-right', '<svg>'.$svgPath.'</svg>', ['defer' => true]);
130127

131128
$svgHtml = $svg->toHtml();
132129

133-
$this->assertEquals('<svg defer="1"><use href="#icon-e993fd00a973c62bf85d410a1a01dfe9"></use></svg>
134-
@once("icon-e993fd00a973c62bf85d410a1a01dfe9")
130+
$this->assertEquals('<svg defer="1"><use href="#icon-75e079eb3e6f7403d66f76ff7f0475c5"></use></svg>
131+
@once("icon-75e079eb3e6f7403d66f76ff7f0475c5")
135132
@push("bladeicons")
136-
<g id="icon-e993fd00a973c62bf85d410a1a01dfe9">
137-
138-
<mask id="test" fill="#fff">
133+
<g id="icon-75e079eb3e6f7403d66f76ff7f0475c5">
134+
<mask id="test" fill="#fff">
139135
<path d="M0 30c0 16.56 13.44 30 30 30 16.56 0 30-13.44 30-30C60 13.44 46.56 0 30 0 13.44 0 0 13.44 0 30Zm4.35 0C4.35 15.84 15.845 4.35 30 4.35c6.295 0 12.08 2.27 16.495 6.04l-29.87 29.93-6.165 6.17C6.625 42.075 4.35 36.3 4.35 30Zm45.26-16.555c3.77 4.475 6.04 10.26 6.04 16.49 0 14.22-11.49 25.715-25.65 25.715-6.3 0-12.08-2.275-16.49-6.04l5.905-5.91-.005-.005 30.2-30.25Z" />
140136
</mask>
141137
</g>
@@ -146,8 +142,7 @@ public function it_can_compile_to_defered_html_with_mask_tag()
146142
/** @test */
147143
public function it_can_compile_to_defered_html_with_defs_tag()
148144
{
149-
$svgPath = '
150-
<defs>
145+
$svgPath = '<defs>
151146
<path d="M0 29.997495C0 46.567015 13.427975 60 30.002505 60 46.567015 60 60 46.567015 60 29.997495 60 13.432985 46.567015 0 30.002505 0 13.427975 0 0 13.432985 0 29.997495Z" id="fodmap-a"/>
152147
<path d="M15.685498 3.670797C2.64507 10.886334-3.260408 26.270404 1.80359 40.303137c3.280262 9.091274 9.639234 15.2328 18.784665 18.459875.408143.141184.745743.226903 1.022877.236988h.100776c.665122-.025211.92714-.529442.891869-1.699256-.105815-3.101018.146125-6.222204-.095738-9.303052-.403104-5.0776 3.824453-8.718143 8.591162-8.460986 3.900035.206735 7.825264.095804 11.730338.005043 2.7008-.060508 4.252751-1.724468 4.167092-4.175028-.08566-2.279122-1.72831-3.711136-4.378722-3.731305-4.04616-.02017-8.09232 0-12.13848 0-1.360478 0-2.715916.010084-4.076394.025211-2.957778.030254-5.920595.060508-8.868296-.070592-5.376405-.226904-8.581085-5.985215-6.177575-10.760277 1.451176-2.899325 3.814376-4.255705 6.978745-4.301085 4.111665-.060508 8.228368-.050423 12.334994-.141185 3.174447-.070592 4.51477-1.482437 4.539963-4.659089.020155-3.232117-.04031-6.474318.025194-9.711477.025194-1.321084-.569385-1.81523-1.76862-1.905991C32.479834.040338 31.492228 0 30.5147 0c-5.189969 0-10.168308 1.09418-14.829202 3.670797Z" id="fodmap-c"/>
153148
<path d="M24.539044 1.93889c-.005033 2.724387.005033 5.453746.0151 8.178134.0151 5.210143-3.110582 8.25768-8.44085 8.247736-3.840411-.009943-7.680822-.019886-11.5162.009943-2.81865.019886-4.660839 1.635627-4.595406 3.942408.0604 2.306781 1.726423 3.738576 4.535007 3.763434 4.107176.044743 8.214352.009943 12.321528.009943v-.034801h5.657433c1.952922.004971 3.905844.014915 5.863799.019886 4.721239.004972 8.179119 3.19171 8.158985 7.521896-.025166 4.330185-3.462913 7.482123-8.199252 7.511952-3.905843.019886-7.811687.014915-11.71753.059658-3.437747.039772-4.711173 1.332365-4.731306 4.757736-.020134 3.19171.130866 6.388391-.0604 9.57513-.115766 1.90906.649296 2.366438 2.370686 2.455925 14.13855.750699 27.230174-8.605684 30.80382-22.093393C48.905267 21.163721 41.03318 5.861411 26.809063.477265 26.02387.178975 25.510472 0 25.178274 0c-.583864 0-.634197.541895-.63923 1.93889Z" id="fodmap-e"/>
@@ -156,12 +151,11 @@ public function it_can_compile_to_defered_html_with_defs_tag()
156151

157152
$svgHtml = $svg->toHtml();
158153

159-
$this->assertEquals('<svg defer="1"><use href="#icon-50715b5a52a453df06f228c92c5882b1"></use></svg>
160-
@once("icon-50715b5a52a453df06f228c92c5882b1")
154+
$this->assertEquals('<svg defer="1"><use href="#icon-cf7005271ce6acebfa1a20cb123ad8b0"></use></svg>
155+
@once("icon-cf7005271ce6acebfa1a20cb123ad8b0")
161156
@push("bladeicons")
162-
<g id="icon-50715b5a52a453df06f228c92c5882b1">
163-
164-
<defs>
157+
<g id="icon-cf7005271ce6acebfa1a20cb123ad8b0">
158+
<defs>
165159
<path d="M0 29.997495C0 46.567015 13.427975 60 30.002505 60 46.567015 60 60 46.567015 60 29.997495 60 13.432985 46.567015 0 30.002505 0 13.427975 0 0 13.432985 0 29.997495Z" id="fodmap-a"/>
166160
<path d="M15.685498 3.670797C2.64507 10.886334-3.260408 26.270404 1.80359 40.303137c3.280262 9.091274 9.639234 15.2328 18.784665 18.459875.408143.141184.745743.226903 1.022877.236988h.100776c.665122-.025211.92714-.529442.891869-1.699256-.105815-3.101018.146125-6.222204-.095738-9.303052-.403104-5.0776 3.824453-8.718143 8.591162-8.460986 3.900035.206735 7.825264.095804 11.730338.005043 2.7008-.060508 4.252751-1.724468 4.167092-4.175028-.08566-2.279122-1.72831-3.711136-4.378722-3.731305-4.04616-.02017-8.09232 0-12.13848 0-1.360478 0-2.715916.010084-4.076394.025211-2.957778.030254-5.920595.060508-8.868296-.070592-5.376405-.226904-8.581085-5.985215-6.177575-10.760277 1.451176-2.899325 3.814376-4.255705 6.978745-4.301085 4.111665-.060508 8.228368-.050423 12.334994-.141185 3.174447-.070592 4.51477-1.482437 4.539963-4.659089.020155-3.232117-.04031-6.474318.025194-9.711477.025194-1.321084-.569385-1.81523-1.76862-1.905991C32.479834.040338 31.492228 0 30.5147 0c-5.189969 0-10.168308 1.09418-14.829202 3.670797Z" id="fodmap-c"/>
167161
<path d="M24.539044 1.93889c-.005033 2.724387.005033 5.453746.0151 8.178134.0151 5.210143-3.110582 8.25768-8.44085 8.247736-3.840411-.009943-7.680822-.019886-11.5162.009943-2.81865.019886-4.660839 1.635627-4.595406 3.942408.0604 2.306781 1.726423 3.738576 4.535007 3.763434 4.107176.044743 8.214352.009943 12.321528.009943v-.034801h5.657433c1.952922.004971 3.905844.014915 5.863799.019886 4.721239.004972 8.179119 3.19171 8.158985 7.521896-.025166 4.330185-3.462913 7.482123-8.199252 7.511952-3.905843.019886-7.811687.014915-11.71753.059658-3.437747.039772-4.711173 1.332365-4.731306 4.757736-.020134 3.19171.130866 6.388391-.0604 9.57513-.115766 1.90906.649296 2.366438 2.370686 2.455925 14.13855.750699 27.230174-8.605684 30.80382-22.093393C48.905267 21.163721 41.03318 5.861411 26.809063.477265 26.02387.178975 25.510472 0 25.178274 0c-.583864 0-.634197.541895-.63923 1.93889Z" id="fodmap-e"/>
@@ -174,18 +168,15 @@ public function it_can_compile_to_defered_html_with_defs_tag()
174168
/** @test */
175169
public function it_can_compile_to_defered_html_with_use_tag()
176170
{
177-
$svgPath = '
178-
<use xlink:href="#fodmap-e"/>';
179-
$svg = new Svg('heroicon-o-arrow-right', '<svg>'.$svgPath.'</svg>', ['defer' => true]);
171+
$svg = new Svg('heroicon-o-arrow-right', '<svg><use xlink:href="#fodmap-e"/></svg>', ['defer' => true]);
180172

181173
$svgHtml = $svg->toHtml();
182174

183-
$this->assertEquals('<svg defer="1"><use href="#icon-7f8be00eb404e323e6b73eb94cf8a0d7"></use></svg>
184-
@once("icon-7f8be00eb404e323e6b73eb94cf8a0d7")
175+
$this->assertEquals('<svg defer="1"><use href="#icon-540a77d3751047fd94004bffda3ffb55"></use></svg>
176+
@once("icon-540a77d3751047fd94004bffda3ffb55")
185177
@push("bladeicons")
186-
<g id="icon-7f8be00eb404e323e6b73eb94cf8a0d7">
187-
188-
<use xlink:href="#fodmap-e"/>
178+
<g id="icon-540a77d3751047fd94004bffda3ffb55">
179+
<use xlink:href="#fodmap-e"/>
189180
</g>
190181
@endpush
191182
@endonce', $svgHtml);

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ protected function prepareSets(array $config = [], array $setOptions = []): Fact
2727

2828
$factory = $factory
2929
->add('default', array_merge([
30-
'path' => __DIR__.'/resources/svg',
30+
'path' => __DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'svg',
3131
'prefix' => 'icon',
3232
], $setOptions['default'] ?? []))
3333
->add('zondicons', array_merge([
34-
'path' => __DIR__.'/resources/zondicons',
34+
'path' => __DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'zondicons',
3535
'prefix' => 'zondicon',
3636
], $setOptions['zondicons'] ?? []));
3737

0 commit comments

Comments
 (0)