Skip to content

Commit

Permalink
feat: add excel seeder installation (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilhorlyck authored Oct 20, 2023
1 parent ac7cee7 commit f6a0c46
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function handle(): int
// - [ ] Setup backup
// - [x] API Documentation
// - [x] Generate ERD
// - [ ] Excel seeder
// - [ ] Activity log for models
// - [ ] Conventional commit script
// - [ ] Release script
Expand All @@ -40,6 +41,7 @@ public function handle(): int
// 'backup' => 'Setup backup',
'api-docs' => 'API Documentation',
'erd' => 'Generate ERD',
'excel-seeder' => 'Excel seeder',
'activity-log' => 'Activity log for models',
// 'conventional-commits' => 'Conventional commit script',
// 'release' => 'Release script',
Expand Down Expand Up @@ -273,6 +275,59 @@ public function handle(): int
]);
}

// Excel seeder
if ($chosenSteps->contains('excel-seeder')) {
$this->info('Installing excel seeder...');
exec('composer require --dev bfinlay/laravel-excel-seeder');
info('excel seeder installed successfully.');

$this->addTooReadme([
'### [Excel seeder](https://github.com/bfinlay/laravel-excel-seeder)',
'#### Usage',
'',
'Just add the SpreadsheetSeeder to be called in your /database/seeder/DatabaseSeeder.php',

'\`\`\`php',
'use Illuminate\Database\Seeder;',
'use bfinlay\SpreadsheetSeeder\SpreadsheetSeeder;',

'class DatabaseSeeder extends Seeder',
'{',
' public function run()',
' {',
' $this->call([',
' SpreadsheetSeeder::class,',
' ]);',
' }',
'}',
'\`\`\`',
'',
'Place your spreadsheets into the path /database/seeders/ of your Laravel project.',

'With the default settings, the seeder makes certain assumptions about the XLSX files:',
'* worksheet (tab) names match --> table names in database',
'* worksheet (tab) has a header row and the column names match --> table column names in database',
'* If there is only one worksheet in the XLSX workbook either the worksheet (tab) name or workbook filename must match a table in the database. ',
'',
'',
'An Excel example:',
'',
'| first_name | last_name | birthday |',
'| ------------- | ------------- | ---------- |',
'| Foo | Bar | 1970-01-01 |',
'| John | Doe | 1980-01-01 |',
'',
'A CSV example:',
'\`\`\`',
' first_name,last_name,birthday',
' Foo,Bar,1970-01-01',
' John,Doe,1980-01-01',
'\`\`\`',

]);

}

// Activity log for models
if ($chosenSteps->contains('activity-log')) {
$this->info('Installing activity log...');
Expand Down

0 comments on commit f6a0c46

Please sign in to comment.