Skip to content

Commit cbb7be2

Browse files
committed
Require and use laravel-essentials
1 parent baec7a5 commit cbb7be2

File tree

8 files changed

+16
-67
lines changed

8 files changed

+16
-67
lines changed

bootstrap/helpers.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,3 @@ function codebarista_path(string $path = ''): string
88
return App::joinPaths(dirname(__DIR__), $path);
99
}
1010
}
11-
12-
if (! function_exists('pngcrush')) {
13-
function pngcrush(string $image): bool
14-
{
15-
$format = 'pngcrush -d %s -q -rem alla %s > /dev/null 2>&1';
16-
$dir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR);
17-
$name = basename($image);
18-
19-
$command = sprintf($format, $dir, escapeshellarg($image));
20-
21-
if (exec($command) !== false) {
22-
return rename($dir.DIRECTORY_SEPARATOR.$name, $image);
23-
}
24-
25-
return false;
26-
}
27-
}

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"require": {
17+
"codebarista/laravel-essentials": "^1.2",
1718
"laravel/framework": "^10.0|^11.0"
1819
},
1920
"require-dev": {
@@ -34,6 +35,9 @@
3435
"Codebarista\\LaravelEcharts\\Tests\\": "tests/"
3536
}
3637
},
38+
"scripts": {
39+
"test": "./vendor/bin/pest"
40+
},
3741
"extra": {
3842
"laravel": {
3943
"providers": [

src/Actions/StoreChartImage.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use Codebarista\LaravelEcharts\Enums\MimeTypes;
66
use Codebarista\LaravelEcharts\Exceptions\StoreChartImageException;
7-
use Codebarista\LaravelEcharts\Makeable;
7+
use Codebarista\LaravelEssentials\Traits\Makeable;
88
use Illuminate\Support\Arr;
99
use Illuminate\Support\Facades\File;
1010
use Illuminate\Support\Facades\Process;
1111
use Illuminate\Support\Str;
1212
use Throwable;
1313

14+
use function crush_png;
15+
1416
class StoreChartImage
1517
{
1618
use Makeable;
@@ -103,7 +105,7 @@ public function handle(array $option): string
103105
new StoreChartImageException($process->errorOutput()));
104106

105107
if ($this->optimize && $this->mimeType === MimeTypes::PNG) {
106-
pngcrush($this->fullPath);
108+
crush_png($this->fullPath);
107109
}
108110

109111
return $this->fullPath;

src/EchartsServiceProvider.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
namespace Codebarista\LaravelEcharts;
44

55
use Codebarista\LaravelEcharts\Console\Commands\NodeEcharts;
6-
use Illuminate\Support\Arr;
76
use Illuminate\Support\ServiceProvider;
87

98
class EchartsServiceProvider extends ServiceProvider
109
{
1110
private const string CONFIG = __DIR__.'/../config/echarts.php';
1211

13-
/**
14-
* Register any application services.
15-
*/
1612
public function register(): void
1713
{
1814
$this->mergeConfigFrom(self::CONFIG, 'echarts');
@@ -22,35 +18,12 @@ public function register(): void
2218
]);
2319
}
2420

25-
/**
26-
* Bootstrap any application services.
27-
*/
2821
public function boot(): void
2922
{
3023
if ($this->app->runningInConsole()) {
3124
$this->publishes([
3225
self::CONFIG => $this->app->configPath('echarts.php'),
3326
], 'config');
3427
}
35-
36-
$this->macros();
37-
}
38-
39-
/**
40-
* Register the package's macros
41-
*/
42-
protected function macros(): void
43-
{
44-
Arr::macro('toJson', static function (array $value, bool $pretty = false): string {
45-
$flags = JSON_THROW_ON_ERROR
46-
| JSON_UNESCAPED_SLASHES
47-
| JSON_NUMERIC_CHECK;
48-
49-
if ($pretty === true) {
50-
$flags |= JSON_PRETTY_PRINT;
51-
}
52-
53-
return json_encode($value, $flags);
54-
});
5528
}
5629
}

src/Makeable.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/Feature/HelpersTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

33
it('has the callable helpers', function () {
4-
expect('codebarista_path')->toBeCallable()
5-
->and('pngcrush')->toBeCallable();
4+
expect('codebarista_path')->toBeCallable();
65
});
76

87
it('resolves the tools path', function () {

tests/PackageTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
use Codebarista\LaravelEcharts\Actions\StoreChartImage;
88
use Codebarista\LaravelEcharts\EchartsServiceProvider;
9+
use Codebarista\LaravelEssentials\EssentialsServiceProvider;
910
use Orchestra\Testbench\TestCase;
1011

1112
abstract class PackageTestCase extends TestCase
1213
{
1314
protected function getPackageProviders($app): array
1415
{
1516
return [
17+
EssentialsServiceProvider::class,
1618
EchartsServiceProvider::class,
1719
];
1820
}

tools/echarts/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "laravel-echarts",
33
"type": "module",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"description": "Create images from echarts",
66
"main": "render.js",
77
"license": "MIT",
88
"dependencies": {
9-
"canvas": "^2.11.2",
10-
"echarts": "^5.4.3",
11-
"lodash": "^4.17.21",
12-
"yargs": "^17.7.2"
9+
"canvas": "^2.11",
10+
"echarts": "^5.4",
11+
"lodash": "^4.17",
12+
"yargs": "^17.7"
1313
}
1414
}

0 commit comments

Comments
 (0)