1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Merge branch 'develop' of github.com:invoiceninja/invoiceninja into develop

This commit is contained in:
Hillel Coren 2018-05-03 07:03:20 +03:00
commit 44ee4e61c5

View File

@ -4,6 +4,7 @@ namespace App\Console\Commands;
use Artisan; use Artisan;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Symfony\Component\Console\Helper\ProgressBar;
class MakeModule extends Command class MakeModule extends Command
{ {
@ -12,7 +13,7 @@ class MakeModule extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'ninja:make-module {name} {fields?} {--migrate=}'; protected $signature = 'ninja:make-module {name : Module name} {fields? : Model fields} {--migrate : Run module migrations} {--p|--plain : Generate only base module scaffold}';
/** /**
* The console command description. * The console command description.
@ -41,6 +42,7 @@ class MakeModule extends Command
$name = $this->argument('name'); $name = $this->argument('name');
$fields = $this->argument('fields'); $fields = $this->argument('fields');
$migrate = $this->option('migrate'); $migrate = $this->option('migrate');
$plain = $this->option('plain');
$lower = strtolower($name); $lower = strtolower($name);
// convert 'name:string,description:text' to 'name,description' // convert 'name:string,description:text' to 'name,description'
@ -50,34 +52,85 @@ class MakeModule extends Command
}, $fillable); }, $fillable);
$fillable = implode(',', $fillable); $fillable = implode(',', $fillable);
ProgressBar::setFormatDefinition('custom', '%current%/%max% %elapsed:6s% [%bar%] %percent:3s%% %message%');
$progressBar = $this->output->createProgressBar($plain ? 2 : ($migrate ? 15 : 14));
$progressBar->setFormat('custom');
$this->info("Creating module: {$name}..."); $this->info("Creating module: {$name}...");
$progressBar->setMessage("Starting module creation...");
Artisan::call('module:make', ['name' => [$name]]); Artisan::call('module:make', ['name' => [$name]]);
Artisan::call('module:make-migration', ['name' => "create_{$lower}_table", '--fields' => $fields, 'module' => $name]); $progressBar->advance();
Artisan::call('module:make-model', ['model' => $name, 'module' => $name, '--fillable' => $fillable]);
if (! $plain) {
$progressBar->setMessage("Creating migrations...");
Artisan::call('module:make-migration', ['name' => "create_{$lower}_table", '--fields' => $fields, 'module' => $name]);
$progressBar->advance();
$progressBar->setMessage("Creating models...");
Artisan::call('module:make-model', ['model' => $name, 'module' => $name, '--fillable' => $fillable]);
$progressBar->advance();
$progressBar->setMessage("Creating views...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'views', '--fields' => $fields, '--filename' => 'edit.blade']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'views', '--fields' => $fields, '--filename' => 'edit.blade']);
$progressBar->advance();
$progressBar->setMessage("Creating datatables...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'datatable', '--fields' => $fields]); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'datatable', '--fields' => $fields]);
$progressBar->advance();
$progressBar->setMessage("Creating repositories...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository', '--fields' => $fields]); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository', '--fields' => $fields]);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'policy']); $progressBar->advance();
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']);
$progressBar->setMessage("Creating presenters...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'presenter']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'presenter']);
$progressBar->advance();
$progressBar->setMessage("Creating requests...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request']);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'create']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'create']);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'update']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'update']);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'api-controller']); $progressBar->advance();
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'transformer', '--fields' => $fields]);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'lang', '--filename' => 'texts']);
if ($migrate == 'true') { $progressBar->setMessage("Creating api-controllers...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'api-controller']);
$progressBar->advance();
$progressBar->setMessage("Creating transformers...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'transformer', '--fields' => $fields]);
$progressBar->advance();
// if the migrate flag was specified, run the migrations
if ($migrate) {
$progressBar->setMessage("Running migrations...");
Artisan::call('module:migrate', ['module' => $name]); Artisan::call('module:migrate', ['module' => $name]);
} else { $progressBar->advance();
$this->info("Use the following command to run the migrations:\nphp artisan module:migrate $name"); }
} }
$progressBar->setMessage("Creating policies...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'policy']);
$progressBar->advance();
$progressBar->setMessage("Creating auth-providers...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']);
$progressBar->advance();
$progressBar->setMessage("Creating translations...");
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'lang', '--filename' => 'texts']);
$progressBar->advance();
$progressBar->setMessage("Dumping module auto-load...");
Artisan::call('module:dump'); Artisan::call('module:dump');
$progressBar->finish();
$progressBar->clear();
$this->info('Done'); $this->info('Done');
if (!$migrate && !$plain) {
$this->info("==> Migrations were not run because the --migrate flag was not specified.");
$this->info("==> Use the following command to run the migrations:\nphp artisan module:migrate $name");
}
} }
protected function getArguments() protected function getArguments()
@ -91,7 +144,8 @@ class MakeModule extends Command
protected function getOptions() protected function getOptions()
{ {
return [ return [
['migrate', null, InputOption::VALUE_OPTIONAL, 'The model attributes.', null], ['migrate', null, InputOption::VALUE_NONE, 'Run module migrations.', null],
['plain', 'p', InputOption::VALUE_NONE, 'Generate only base module scaffold.', null],
]; ];
} }
} }