Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CommandRouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function handle(Filesystem $filesystem)
if ($this->option('types') || $this->option('types-only')) {
$types = config('ziggy.output.types', Types::class);

$filesystem->put(base_path("{$name}.d.ts"), new $types($ziggy));
$filesystem->put(base_path("{$name}-types.d.ts"), new $types($ziggy));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$filesystem->put(base_path("{$name}-types.d.ts"), new $types($ziggy));
$filesystem->put(base_path("{$name}-module.d.ts"), new $types($ziggy));

}

$this->info('Files generated!');
Expand Down
22 changes: 11 additions & 11 deletions tests/Unit/CommandRouteGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,18 @@
if (windows_os()) {
// `json_encode` always uses Unix line endings
file_put_contents(
base_path('resources/js/ziggy.d.ts'),
preg_replace('/\r?\n/', "\r\n", file_get_contents(base_path('resources/js/ziggy.d.ts'))),
base_path('resources/js/ziggy-types.d.ts'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
base_path('resources/js/ziggy-types.d.ts'),
base_path('resources/js/ziggy-module.d.ts'),

preg_replace('/\r?\n/', "\r\n", file_get_contents(base_path('resources/js/ziggy-types.d.ts'))),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
preg_replace('/\r?\n/', "\r\n", file_get_contents(base_path('resources/js/ziggy-types.d.ts'))),
preg_replace('/\r?\n/', "\r\n", file_get_contents(base_path('resources/js/ziggy-module.d.ts'))),

);
}

expect(base_path('resources/js/ziggy.d.ts'))->toEqualFile('./tests/fixtures/ziggy.d.ts');
expect(base_path('resources/js/ziggy-types.d.ts'))->toEqualFile('./tests/fixtures/ziggy.d.ts');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(base_path('resources/js/ziggy-types.d.ts'))->toEqualFile('./tests/fixtures/ziggy.d.ts');
expect(base_path('resources/js/ziggy-module.d.ts'))->toEqualFile('./tests/fixtures/ziggy.d.ts');

});

test('generate dts file without generating routes file', function () {
artisan('ziggy:generate --types-only');

expect(base_path('resources/js/ziggy.d.ts'))->toBeFile();
expect(base_path('resources/js/ziggy-types.d.ts'))->toBeFile();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(base_path('resources/js/ziggy-types.d.ts'))->toBeFile();
expect(base_path('resources/js/ziggy-module.d.ts'))->toBeFile();

expect(base_path('resources/js/ziggy.js'))->not->toBeFile();
});

Expand All @@ -139,8 +139,8 @@

artisan('ziggy:generate --types-only');

expect(base_path('resources/js/custom.d.ts'))->toBeFile();
expect(base_path('resources/js/ziggy.d.ts'))->not->toBeFile();
expect(base_path('resources/js/custom-types.d.ts'))->toBeFile();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(base_path('resources/js/custom-types.d.ts'))->toBeFile();
expect(base_path('resources/js/custom-module.d.ts'))->toBeFile();

expect(base_path('resources/js/ziggy-types.d.ts'))->not->toBeFile();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(base_path('resources/js/ziggy-types.d.ts'))->not->toBeFile();
expect(base_path('resources/js/ziggy-module.d.ts'))->not->toBeFile();

});

test('generate correct routes and dts files based on provided arguments', function (string $args, array $files) {
Expand All @@ -153,11 +153,11 @@

expect(array_map(base_path(...), $files))->each->toBeFile();
})->with([
['resources/js/x.js --types', ['resources/js/x.js', 'resources/js/x.d.ts']],
['resources/js/y.ts --types', ['resources/js/y.js', 'resources/js/y.d.ts']],
['resources/js/z.d.ts --types', ['resources/js/z.js', 'resources/js/z.d.ts']],
['resources/scripts/foo --types', ['resources/scripts/foo.js', 'resources/scripts/foo.d.ts']],
['resources/js --types', ['resources/js/ziggy.js', 'resources/js/ziggy.d.ts']],
['resources/js/x.js --types', ['resources/js/x.js', 'resources/js/x-types.d.ts']],
['resources/js/y.ts --types', ['resources/js/y.js', 'resources/js/y-types.d.ts']],
['resources/js/z.d.ts --types', ['resources/js/z.js', 'resources/js/z-types.d.ts']],
['resources/scripts/foo --types', ['resources/scripts/foo.js', 'resources/scripts/foo-types.d.ts']],
['resources/js --types', ['resources/js/ziggy.js', 'resources/js/ziggy-types.d.ts']],
Comment on lines +156 to +160
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
['resources/js/x.js --types', ['resources/js/x.js', 'resources/js/x-types.d.ts']],
['resources/js/y.ts --types', ['resources/js/y.js', 'resources/js/y-types.d.ts']],
['resources/js/z.d.ts --types', ['resources/js/z.js', 'resources/js/z-types.d.ts']],
['resources/scripts/foo --types', ['resources/scripts/foo.js', 'resources/scripts/foo-types.d.ts']],
['resources/js --types', ['resources/js/ziggy.js', 'resources/js/ziggy-types.d.ts']],
['resources/js/x.js --types', ['resources/js/x.js', 'resources/js/x-module.d.ts']],
['resources/js/y.ts --types', ['resources/js/y.js', 'resources/js/y-module.d.ts']],
['resources/js/z.d.ts --types', ['resources/js/z.js', 'resources/js/z-module.d.ts']],
['resources/scripts/foo --types', ['resources/scripts/foo.js', 'resources/scripts/foo-module.d.ts']],
['resources/js --types', ['resources/js/ziggy.js', 'resources/js/ziggy-module.d.ts']],

]);

class CustomFile extends File
Expand Down