Skip to content

Commit 2055217

Browse files
Merge pull request #13 from michaelnabil230/main
Fix: Convert Hyphenated File Names to Camel Case
2 parents 37ac4ce + abe4314 commit 2055217

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/GenerateCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ private function writeBarrelFiles(array|Collection $children, string $parent): v
250250
return;
251251
}
252252

253-
$children->each(function ($grandkids, $child) use ($parent) {
253+
$normalizeToCamelCase = fn ($value) => str_contains($value, '-') ? Str::camel($value) : $value;
254+
255+
$children->each(function ($grandkids, $child) use ($parent, $normalizeToCamelCase) {
254256
$grandkids = collect($grandkids);
255257

256258
if (array_is_list($grandkids->all())) {
@@ -259,17 +261,15 @@ private function writeBarrelFiles(array|Collection $children, string $parent): v
259261

260262
$directory = join_paths($this->base(), $parent, $child);
261263

262-
$imports = $grandkids->keys()->map(fn ($grandkid) => "import * as {$grandkid} from './{$grandkid}'")->implode(PHP_EOL);
264+
$grandKidKeys = $grandkids->keys()->mapWithKeys(fn ($grandkid) => [$normalizeToCamelCase($grandkid) => $grandkid]);
263265

264-
$this->appendContent(join_paths($directory, 'index.ts'), $imports);
266+
$imports = $grandKidKeys->map(fn ($grandkid, $key) => "import * as {$key} from './{$grandkid}'")->implode(PHP_EOL);
265267

266-
$keys = $grandkids->keys()->map(fn ($k) => str_repeat(' ', 4).$k)->implode(', '.PHP_EOL);
268+
$this->appendContent(join_paths($directory, 'index.ts'), $imports);
267269

268-
$varExport = $child;
270+
$keys = $grandKidKeys->keys()->map(fn ($key) => str_repeat(' ', 4).$key)->implode(', '.PHP_EOL);
269271

270-
if (str_contains($varExport, '-')) {
271-
$varExport = Str::camel($varExport);
272-
}
272+
$varExport = $normalizeToCamelCase($child);
273273

274274
$this->appendContent(join_paths($directory, 'index.ts'), <<<JAVASCRIPT
275275

tests/PathNameNormalization.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect, it } from "vitest";
2+
import v1 from "../workbench/resources/js/routes/api/v1/index";
3+
4+
it('can normalize to camel case', () => {
5+
expect(v1.taskStatus.index(1).url).toBe("/api/v1/tasks/1/task-status");
6+
expect(v1.taskStatus.index(1)).toEqual({
7+
url: "/api/v1/tasks/1/task-status",
8+
method: "get",
9+
});
10+
});

vite.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { defineConfig } from 'vite'
22

33
export default defineConfig({
4-
test: {
5-
include: ['tests/*.test.ts'],
6-
environment: 'happy-dom',
7-
globalSetup: 'build.ts',
8-
},
4+
test: {
5+
include: ['tests/*.test.ts'],
6+
environment: 'happy-dom',
7+
globalSetup: 'build.ts',
8+
},
99
resolve: {
1010
alias: {
1111
'@actions/': './workbench/resources/js/actions'

workbench/routes/web.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@
5757
Route::get('/disallowed/404', [DisallowedMethodNameController::class, '404']);
5858

5959
Route::get('/anonymous-middleware', [AnonymousMiddlewareController::class, 'show']);
60+
61+
Route::prefix('/api/v1')->name('api.v1.')->group(function () {
62+
Route::get('/tasks', fn () => 'ok')->name('tasks');
63+
64+
Route::prefix('/tasks/{task}/task-status')->name('task-status.')->group(function () {
65+
Route::get('/', fn () => 'ok')->name('index');
66+
});
67+
});

0 commit comments

Comments
 (0)