From 044ffac135b5cd48ee1dda734bbae54badd081b7 Mon Sep 17 00:00:00 2001 From: Manuel Odelain Date: Fri, 23 Feb 2024 10:29:21 +0100 Subject: [PATCH] feat: handle layers --- playground/nuxt.config.ts | 3 ++- src/module.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 345b236..fcf1f32 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -1,5 +1,6 @@ export default defineNuxtConfig({ devtools: { enabled: true }, - modules: ['../src/module'], + // modules: ['../src/module'], css: ['~/assets/css/main.css'], + extends: ['github:rezozero/nuxt-layer'], }) diff --git a/src/module.ts b/src/module.ts index 8d9c0de..b250647 100644 --- a/src/module.ts +++ b/src/module.ts @@ -84,14 +84,24 @@ export default defineNuxtModule({ // PAGES extendPages(async (pages) => { + // scan project files const files = await resolveFiles(nuxt.options.rootDir, pattern) + // scan layers files + const layersFiles = await Promise.all( + nuxt.options._layers.map((layer) => resolveFiles(layer.config.rootDir, pattern)), + ) + + files.concat(layersFiles.flat()) + + // generate child routes files.forEach((file) => { const fileRoute = getFileRoute(file) route.children!.push(fileRoute) }) + // add route pages.push(route) })