Skip to content

Commit b0901ed

Browse files
committed
v2.0.2
- fix using incorrect event - better & quicker api
1 parent 55e1b42 commit b0901ed

File tree

4 files changed

+25
-76
lines changed

4 files changed

+25
-76
lines changed

logs/v2.0.0.txt

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

logs/v2.0.2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- fix using incorrect event, plz move `@php artisan pcl:post-update` from `scripts:post-autoload-dump` to "scripts:post-update-cmd"

src/PackageChangeLogServiceProvider.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class PackageChangeLogServiceProvider extends ServiceProvider
1111

1212
public function boot()
1313
{
14-
if (file_exists(base_path() . '/composer.json') &&
14+
if (
15+
file_exists(\base_path() . '/composer.json') &&
1516
!$this->app['cache']->store('file')->has('ct-pcl')
1617
) {
1718
$this->autoReg();
@@ -28,11 +29,7 @@ public function boot()
2829

2930
protected function autoReg()
3031
{
31-
$comp_file = base_path() . '/composer.json';
32-
33-
$this->postUpdate($comp_file);
34-
$this->postInstall($comp_file);
35-
$this->preUninstall($comp_file);
32+
$this->doStuff();
3633

3734
// run check once
3835
$this->app['cache']->store('file')->rememberForever('ct-pcl', function () {

src/Traits/Init.php

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,31 @@
66

77
trait Init
88
{
9-
/* -------------------------------------------------------------------------- */
10-
/* OPS */
11-
/* -------------------------------------------------------------------------- */
12-
13-
protected function postUpdate($comp_file)
9+
protected function doStuff()
1410
{
15-
$search = '@php artisan pcl:post-update';
16-
17-
if (!$this->checkExist($comp_file, $search)) {
18-
$data = $search;
19-
$res = json_decode(file_get_contents($comp_file), true);
20-
21-
if ($res['scripts']['post-autoload-dump']) {
22-
array_push($res['scripts']['post-autoload-dump'], $data);
23-
$json = json_encode($res, JSON_PRETTY_PRINT);
24-
$final = str_replace('\/', '/', $json);
25-
file_put_contents($comp_file, $final);
11+
$comp_file = \base_path() . '/composer.json';
12+
$json_data = file_get_contents($comp_file);
13+
$list = [
14+
'post-install' => 'post-install-cmd',
15+
'post-update' => 'post-update-cmd',
16+
'pre-uninstall' => 'pre-package-uninstall',
17+
];
18+
19+
$final = json_decode($json_data, true);
20+
21+
foreach ($list as $cmnd => $event) {
22+
$search = "@php artisan pcl:$cmnd";
23+
24+
if (!Str::contains($json_data, $search)) {
25+
isset($final['scripts'][$event])
26+
? array_push($final['scripts'][$event], $search)
27+
: $final['scripts'][$event] = [$search];
2628
}
2729
}
28-
}
29-
30-
protected function postInstall($comp_file)
31-
{
32-
$search = '@php artisan pcl:post-install';
33-
34-
if (!$this->checkExist($comp_file, $search)) {
35-
$res = json_decode(file_get_contents($comp_file), true);
36-
37-
isset($res['scripts']['post-install-cmd'])
38-
? array_push($res['scripts']['post-install-cmd'], $search)
39-
: $res['scripts']['post-install-cmd'] = [$search];
4030

41-
$json = json_encode($res, JSON_PRETTY_PRINT);
42-
$final = str_replace('\/', '/', $json);
43-
file_put_contents($comp_file, $final);
44-
}
45-
}
31+
$json = json_encode($final, JSON_PRETTY_PRINT);
32+
$final = str_replace('\/', '/', $json);
4633

47-
protected function preUninstall($comp_file)
48-
{
49-
$search = '@php artisan pcl:pre-uninstall';
50-
51-
if (!$this->checkExist($comp_file, $search)) {
52-
$res = json_decode(file_get_contents($comp_file), true);
53-
54-
isset($res['scripts']['pre-package-uninstall'])
55-
? array_push($res['scripts']['pre-package-uninstall'], $search)
56-
: $res['scripts']['pre-package-uninstall'] = [$search];
57-
58-
$json = json_encode($res, JSON_PRETTY_PRINT);
59-
$final = str_replace('\/', '/', $json);
60-
file_put_contents($comp_file, $final);
61-
}
62-
}
63-
64-
/* -------------------------------------------------------------------------- */
65-
66-
protected function checkExist($file, $search)
67-
{
68-
return Str::contains(file_get_contents($file), $search);
34+
return file_put_contents($comp_file, $final);
6935
}
7036
}

0 commit comments

Comments
 (0)