Skip to content
Merged
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 packages/void/src/cli/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ function runMigration(root: string, name: string): void {
}

function runRoute(root: string, routePath: string, methods: Array<string>): void {
const filePath = join(readProjectPaths(root).routesDir, routePath + '.ts');
const filePath = join(readProjectPaths(root).routesDir, `${routePath || 'index'}.ts`);
const exports = methods
.map((m) => {
const upper = m.toUpperCase();
Expand Down
9 changes: 9 additions & 0 deletions packages/void/test/unit/gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { log, outro } from '@voidzero-dev/vite-plus-prompts';
import { toSlash } from 'pathslash';
import { describe, it, expect, afterEach, beforeEach, vi } from 'vite-plus/test';
import { packageFixturePath } from '../../../../test/fixture-dir.ts';
import { parseGenArgs } from '../../src/cli/gen-args.ts';
import type { GenArgs } from '../../src/cli/gen-args.ts';
import { runGenCommand, formatTimestamp, detectValidator } from '../../src/cli/gen.ts';
import { Buffer } from '../../src/cli/node-buffer.ts';
Expand Down Expand Up @@ -1039,6 +1040,14 @@ describe('gen migration', () => {
});

describe('gen route', () => {
it('generates routes/index.ts for the root route', async () => {
await runGenCommand(TMP, parseGenArgs(['route', '/']));

const content = read('routes/index.ts');
expect(content).toContain('export const GET = defineHandler');
expect(existsSync(join(TMP, 'routes/.ts'))).toBe(false);
});

it('keeps an existing route and prints no creation success when skipped', async () => {
const path = join(TMP, 'routes/api/health.ts');
mkdirSync(dirname(path), { recursive: true });
Expand Down