Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins/fs-routes): allow to customize fresh app tree and exts #2777

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions src/plugins/fs_routes/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export interface FsRoutesOptions {
ignoreFilePattern?: RegExp[];
loadRoute: (path: string) => Promise<unknown>;
loadIsland: (path: string) => Promise<unknown>;
islandDir?: string;
routesDir?: string;
fileExts?: string[];
}

export interface TESTING_ONLY__FsRoutesOptions {
Expand All @@ -68,8 +71,8 @@ export async function fsRoutes<State>(
const dir = options.dir
? parseRootPath(options.dir, fs.cwd())
: app.config.root;
const islandDir = path.join(dir, "islands");
const routesDir = path.join(dir, "routes");
const islandDir = path.join(dir, options.islandDir ?? "islands");
const routesDir = path.join(dir, options.routesDir ?? "routes");

const islandPaths: string[] = [];
const relRoutePaths: string[] = [];
Expand All @@ -83,6 +86,7 @@ export async function fsRoutes<State>(
},
ignore,
fs,
options.fileExts ?? [],
),
walkDir(
routesDir,
Expand All @@ -105,6 +109,7 @@ export async function fsRoutes<State>(
},
ignore,
fs,
options.fileExts ?? [],
),
]);

Expand Down Expand Up @@ -364,13 +369,14 @@ async function walkDir(
callback: (entry: WalkEntry) => void,
ignore: RegExp[],
fs: FsAdapter,
exts: string[],
) {
if (!await fs.isDirectory(dir)) return;

const entries = fs.walk(dir, {
includeDirs: false,
includeFiles: true,
exts: ["tsx", "jsx", "ts", "js"],
exts: ["tsx", "jsx", "ts", "js", ...exts],
skip: ignore,
});

Expand Down
Loading