|
6 | 6 |
|
7 | 7 | trait Init
|
8 | 8 | {
|
9 |
| - /* -------------------------------------------------------------------------- */ |
10 |
| - /* OPS */ |
11 |
| - /* -------------------------------------------------------------------------- */ |
12 |
| - |
13 |
| - protected function postUpdate($comp_file) |
| 9 | + protected function doStuff() |
14 | 10 | {
|
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]; |
26 | 28 | }
|
27 | 29 | }
|
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]; |
40 | 30 |
|
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); |
46 | 33 |
|
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); |
69 | 35 | }
|
70 | 36 | }
|
0 commit comments