Skip to content

Commit 9c405fb

Browse files
Fix command signature and default file to .ts instead of .d.ts
1 parent 6e579fa commit 9c405fb

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh
2020
You can install the package via composer:
2121

2222
```bash
23-
composer require likeadeckofcards/enum-convertor-laravel
23+
composer require --dev likeadeckofcards/enum-convertor-laravel
2424
```
2525

2626
You can publish the config file with:
@@ -44,7 +44,7 @@ return [
4444
/*
4545
* extension to use for the enum files
4646
*/
47-
'enum_extension' => '.d.ts',
47+
'enum_extension' => '.ts',
4848
];
4949
```
5050

config/enum-convertor-laravel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
/*
1313
* extension to use for the enum files
1414
*/
15-
'enum_extension' => '.d.ts',
15+
'enum_extension' => '.ts',
1616
];

src/Commands/EnumConvertorCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
class EnumConvertorCommand extends Command
1010
{
11-
public $signature = 'convert-enums';
11+
public $signature = 'convert-enums {--js}';
1212

13-
public $description = 'Convert PHP enums to JS/TS enums {--js}';
13+
public $description = 'Convert PHP enums to JS/TS enums';
1414

1515
public function handle(): int
1616
{
@@ -30,7 +30,7 @@ public function handle(): int
3030
});
3131

3232
$output = '';
33-
if ($this->hasOption('js')) {
33+
if ($this->option('js')) {
3434
$output = $this->convertToJSEnum($items, $outputPath);
3535
} else {
3636
$output = $this->convertToTSEnum($items, $outputPath);
@@ -56,10 +56,10 @@ private function convertToTSEnum($items, $outputPath): string
5656
$data = $items->map(function ($item, $key) {
5757
$item = $this->convertValue($item);
5858

59-
return " {$key} = {$item},";
59+
return " {$key}: {$item},";
6060
})->implode("\n");
6161

62-
$data = "export enum %enumName% {\n{$data}\n}";
62+
$data = "const %enumName% = {\n{$data}\n} as const;\n\nexport default %enumName%;\n\nexport type %enumName% = (typeof %enumName%)[keyof typeof %enumName%];";
6363

6464
return $data;
6565
}

0 commit comments

Comments
 (0)