Skip to content

Commit

Permalink
Merge pull request #24 from AmrAhmedFekry/master
Browse files Browse the repository at this point in the history
Add some modifications
  • Loading branch information
hassanzohdy committed Sep 23, 2019
2 parents 5f3b84c + 84ba6c8 commit cd59ed1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
4 changes: 3 additions & 1 deletion module/Migrations/mongodb-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class TableName extends Migration
public function up()
{
Schema::create('TableName', function (Blueprint $table) {
// Table-Schema
$table->int('id')->unique();
// Table-Schema

});
}

Expand Down
1 change: 1 addition & 0 deletions module/Migrations/mysql-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function up()
{
Schema::create('TableName', function (Blueprint $table) {
$table->loggers();
$table->int('id')->unique();

// Table-Schema

Expand Down
14 changes: 10 additions & 4 deletions src/Console/Commands/EngezMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class EngezMigration extends Command implements EngezInterface
*
* @var string
*/
protected $signature = 'engez:migration {moduleName} {--data=} {--index=} {--unique=}';
protected $signature = 'engez:migration {moduleName} {--data=} {--uploads=} {--index=} {--unique=}';

/**
* The console command description.
Expand Down Expand Up @@ -64,7 +64,8 @@ public function init()
$this->info['moduleName'] = Str::studly($this->argument('moduleName'));
$this->info['index'] = [];
$this->info['unique'] = [];

$this->info['uploads'] = [];

if ($this->hasOption('index')) {
$this->info['index'] = explode(',', $this->option('index'));
}
Expand All @@ -76,6 +77,10 @@ public function init()
if ($this->hasOption('data')) {
$this->info['data'] = explode(',', $this->option('data'));
}

if ($this->hasOption('uploads')) {
$this->info['uploads'] = explode(',', $this->option('uploads'));
}
}

/**
Expand Down Expand Up @@ -116,11 +121,12 @@ public function create()
unset($this->info['index'][array_search($singleIndexData, $this->info['index'])]);
}
}
$allData = array_filter(array_merge($this->info['data'], $this->info['uploads']));

if (isset($this->info['data'])) {
if (!empty($allData)) {
$schema = '';
$tabs = "\n" . str_repeat("\t", 3);
foreach ($this->info['data'] as $data) {
foreach ($allData as $data) {
$dataSchema = "{$tabs}\$table->string('$data');";

if (in_array($data, $this->info['index'])) {
Expand Down
51 changes: 31 additions & 20 deletions src/Console/Commands/ModuleBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ protected function create()
$this->info('Creating database files');
$this->createDatabase();

$this->info('Generating routes files');
$this->createRoutes();
// $this->info('Generating routes files');
// $this->createRoutes();

$this->info('Generating Module Postman File');
// $this->info('Generating Module Postman File');
$this->generatePostmanModule();

$this->info('Generating Module Docs');
// $this->info('Generating Module Docs');
$this->generateModuleDocs();

$this->info('Updating configurations.');
$this->updateConfig();
// $this->info('Updating configurations.');
// $this->updateConfig();
}

/**
Expand Down Expand Up @@ -351,14 +351,12 @@ protected function createResource()
protected function createDatabase()
{
$databaseFileName = strtolower(str::plural($this->moduleName));
$path = $this->modulePath("database/migrations");
$this->checkDirectory($path);


$databaseDriver = config('database.default');

if ($databaseDriver == 'mongodb') {
$this->createSchema($databaseFileName, $path);
}
// if ($databaseDriver == 'mongodb') {
$this->createSchema($databaseFileName);
// }

$this->createMigration();
}
Expand Down Expand Up @@ -394,6 +392,11 @@ protected function createMigration()
$migrationsOptions['--data'] = $data;
}

if ($this->hasOption('uploads')) {
$uploads = $this->option('uploads');
$migrationsOptions['--uploads'] = $uploads;
}

Artisan::call('engez:migration', $migrationsOptions);
}

Expand All @@ -403,22 +406,28 @@ protected function createMigration()
* @param string $dataFileName
* @return void
*/
protected function createSchema($databaseFileName, $path)
protected function createSchema($databaseFileName)
{
$path = $this->modulePath("database/migrations/schema");
$this->checkDirectory($path);

$defaultContent = [
'_id' => "objectId",
'id'=>'int',
];

$customData = $this->info['data'] ?? [];

$uploadsData = $this->info['uploads'] ?? [];

unset($customData['id'], $customData['_id']);

$customData = array_fill_keys($customData, 'string');

$content = array_merge($defaultContent, $customData);

$uploadsData = array_fill_keys($uploadsData, 'string');

$content = array_merge($defaultContent, $customData, $uploadsData);

$this->createFile("$path/{$databaseFileName}.json", json_encode($content, JSON_PRETTY_PRINT), 'Schema');
}

Expand Down Expand Up @@ -538,10 +547,13 @@ protected function generatePostmanModule()
'data' => $data
]);

$path = $this->modulePath($this->info['moduleName']);
$path = $this->modulePath("docs");
$this->checkDirectory($path);

$fileName = strtolower($this->info['moduleName']).'.postman.json';
$content = $postman->getContent();
$this->createFile("$path.json", $content, 'PostmanFile');

$this->createFile("{$path}/{$fileName}", $content, 'PostmanFile');
}

/**
Expand All @@ -559,9 +571,8 @@ protected function generateModuleDocs()
'data' => $data
]);

$path = $this->modulePath($this->info['moduleName']);

$path = $this->modulePath("docs");
$content = $postman->getContent();
$this->createFile("$path.md", $content, 'Docs');
$this->createFile("{$path}/README.md", $content, 'Docs');
}
}

0 comments on commit cd59ed1

Please sign in to comment.