Skip to content

Commit d1d5eca

Browse files
committed
New command and readme updated
1 parent 7675851 commit d1d5eca

File tree

4 files changed

+87
-11
lines changed

4 files changed

+87
-11
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
This is a very simple, but handy package for setting up local Laravel development environment.
55
This package contains commands to do all the trivial steps you normally do when setting up your local Laravel development environment.
66

7-
One can create a .default_vars.env in the users home directory with the common .env variables that one alwasy set e.g. MAIL_HOST=127.0.0.1 for Homestead based development environments.
7+
Create a .default_vars.env in the your home directory with the common .env variables that you always set e.g. MAIL_HOST=127.0.0.1 for Homestead based development environments.
88

99
It is also possible to specify a specific file to be used by using the --file options.
1010

11-
If you ant dynamic vars you can use this:
11+
If you want dynamic vars you can use this:
1212

1313
VAR_NAME=[ASK_FOR_VALUE]
1414

1515
Then you wil be prompted to enter a value
1616

17+
1718
## Installation
1819

1920
You can install the package via composer:
@@ -25,13 +26,20 @@ composer require rabol/laravel-setup-local-dev --dev
2526
## Usage
2627

2728
``` php
28-
// Usage description here
29+
// Setup you .env vars
2930
php artisan setuplocaldev:setenv
30-
3131
or
32+
php artisan setuplocaldev:setenv --file=myvars
3233

33-
php artisan setuplocaldev:setenv --file=test.env
34+
// Execute commontasks
35+
php artisan setuplocaldev:commontasks
36+
or
37+
php artisan setuplocaldev:commontasks --file=mytasks
3438

39+
// All of the above
40+
php artisan setuplocaldev:all
41+
or
42+
php artisan setuplocaldev:all --file_env=myvars --file_tasks=mytasks
3543

3644
```
3745

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
],
1818
"require": {
1919
"php": "^7.3|^8.0",
20-
"illuminate/support": "^6.0|^7.0|^8.0",
2120
"jackiedo/dotenv-editor": "^1.2",
22-
"juliardi/homedir": "^1.0"
21+
"juliardi/homedir": "^1.0",
22+
"laravel/framework": "^7.0|^8.0",
23+
"symfony/process": "^5.2"
2324
},
2425
"require-dev": {
25-
"orchestra/testbench": "^4.0",
26+
"orchestra/testbench": "^6.7",
2627
"phpunit/phpunit": "^9.5"
2728
},
2829
"autoload": {

src/Console/Commands/CommonTasksCommand.php

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace Rabol\LaravelSetupLocalDev\Console\Commands;
44

55
use Illuminate\Console\Command;
6+
use Symfony\Component\Process\Exception\RuntimeException;
7+
use Symfony\Component\Process\Process;
8+
use Symfony\Component\Process\Exception\ProcessFailedException;
9+
use Symfony\Component\VarDumper\VarDumper;
610

711
class CommonTasksCommand extends Command
812
{
@@ -11,14 +15,14 @@ class CommonTasksCommand extends Command
1115
*
1216
* @var string
1317
*/
14-
protected $signature = 'command:name';
18+
protected $signature = 'setuplocaldev:commontasks {--file= : Read tasks from a file.}';
1519

1620
/**
1721
* The console command description.
1822
*
1923
* @var string
2024
*/
21-
protected $description = 'Command description';
25+
protected $description = 'Execute common setup tasks';
2226

2327
/**
2428
* Create a new command instance.
@@ -37,6 +41,65 @@ public function __construct()
3741
*/
3842
public function handle()
3943
{
40-
//
44+
45+
$this->info('Executing common taskss.');
46+
47+
if($this->option('file') !== null)
48+
{
49+
$commonTasksFile = $this->option('file');
50+
}
51+
else
52+
{
53+
$commonTasksFile = get_home_directory();
54+
$commonTasksFile .= '/.default_laravel_local_dev.tasks';
55+
}
56+
57+
if(!file_exists($commonTasksFile))
58+
{
59+
$this->error('File: \'' . $commonTasksFile . '\' does not exists.');
60+
exit();
61+
}
62+
63+
// .default_laravel_local_dev.tasks
64+
$file = fopen($commonTasksFile, "r") or exit("Unable to open file!");
65+
while(!feof($file))
66+
{
67+
$task = trim(fgets($file));
68+
if(!strlen($task))
69+
continue;
70+
71+
$this->info($task);
72+
73+
// Split the task into an array:
74+
$taskArray = explode(' ', $task);
75+
try {
76+
$process = new Process($taskArray);
77+
$process->setTimeout(3600);
78+
$process->run();
79+
80+
// executes after the command finishes
81+
if (!$process->isSuccessful()) {
82+
//throw new ProcessFailedException($process);
83+
$error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
84+
$process->getCommandLine(),
85+
$process->getExitCode(),
86+
$process->getExitCodeText(),
87+
$process->getWorkingDirectory()
88+
);
89+
$this->error($error);
90+
}
91+
else
92+
{
93+
$this->info($process->getOutput());
94+
}
95+
}
96+
catch (\Exception $e)
97+
{
98+
$this->error("Could not execute command: $task");
99+
$this->error($e->getMessage());
100+
}
101+
}
102+
103+
fclose($file);
41104
}
42105
}

src/LaravelSetupLocalDevServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Support\ServiceProvider;
66
use Rabol\LaravelSetupLocalDev\Console\Commands\SetEnvCommand;
7+
use Rabol\LaravelSetupLocalDev\Console\Commands\CommonTasksCommand;
8+
use Rabol\LaravelSetupLocalDev\Console\Commands\AllCommand;
79

810
class LaravelSetupLocalDevServiceProvider extends ServiceProvider
911
{
@@ -43,6 +45,8 @@ public function boot()
4345
// Registering package commands.
4446
$this->commands([
4547
SetEnvCommand::class,
48+
CommonTasksCommand::class,
49+
AllCommand::class,
4650
]);
4751
}
4852
}

0 commit comments

Comments
 (0)