@bromscandium/vite-plugin 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bromscandium
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @bromscandium/vite-plugin
2
+
3
+ Vite plugin for BromiumJS with file-based routing and HMR support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @bromscandium/vite-plugin -D
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ // vite.config.ts
15
+ import { defineConfig } from 'vite';
16
+ import bromium from '@bromscandium/vite-plugin';
17
+
18
+ export default defineConfig({
19
+ plugins: [
20
+ bromium({
21
+ pagesDir: 'src/pages',
22
+ routesOutput: 'src/routes.generated.ts',
23
+ generateTypes: true,
24
+ })
25
+ ],
26
+ esbuild: {
27
+ jsx: 'automatic',
28
+ jsxImportSource: 'bromium'
29
+ }
30
+ });
31
+ ```
32
+
33
+ ## File-based Routing
34
+
35
+ ```
36
+ src/pages/
37
+ ├── page.tsx → /
38
+ ├── about.tsx → /about
39
+ ├── users/
40
+ │ ├── page.tsx → /users
41
+ │ ├── [id].tsx → /users/:id
42
+ │ └── [id]/
43
+ │ └── settings.tsx → /users/:id/settings
44
+ ├── posts/
45
+ │ └── [...slug].tsx → /posts/:slug* (catch-all)
46
+ └── (auth)/ → Route group (no URL segment)
47
+ ├── login.tsx → /login
48
+ └── register.tsx → /register
49
+ ```
50
+
51
+ | Pattern | Example | Description |
52
+ |---------|---------|-------------|
53
+ | `page.tsx` | `/` | Index route |
54
+ | `about.tsx` | `/about` | Static route |
55
+ | `[id].tsx` | `/users/:id` | Dynamic segment |
56
+ | `[...slug].tsx` | `/posts/:slug*` | Catch-all route |
57
+ | `(folder)/` | - | Route group |
58
+ | `layout.tsx` | - | Layout component |
59
+
60
+ ## Options
61
+
62
+ | Option | Default | Description |
63
+ |--------|---------|-------------|
64
+ | `pagesDir` | `'src/pages'` | Pages directory |
65
+ | `routesOutput` | `'src/routes.generated.ts'` | Output file |
66
+ | `base` | `''` | Base path for routes |
67
+ | `generateTypes` | `true` | Generate TypeScript types |
68
+
69
+ ## License
70
+
71
+ MIT
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Route code generation utilities.
3
+ * @module
4
+ */
5
+ import { ScannedRoute } from './scanner.js';
6
+ /**
7
+ * Options for route code generation.
8
+ */
9
+ export interface CodegenOptions {
10
+ /** The pages directory path */
11
+ pagesDir: string;
12
+ /** The output file path for generated routes */
13
+ outputPath: string;
14
+ /** Optional base path for routes */
15
+ base?: string;
16
+ }
17
+ /**
18
+ * Generates TypeScript code for route configuration from scanned routes.
19
+ * The output exports a `routes` array compatible with the Bromium router.
20
+ *
21
+ * @param routes - Array of scanned route information
22
+ * @param options - Code generation options
23
+ * @returns Generated TypeScript source code
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const routes = scanPages('./src/pages');
28
+ * const code = generateRouteConfig(routes, {
29
+ * pagesDir: './src/pages',
30
+ * outputPath: './src/routes.generated.ts',
31
+ * });
32
+ * fs.writeFileSync('./src/routes.generated.ts', code);
33
+ * ```
34
+ */
35
+ export declare function generateRouteConfig(routes: ScannedRoute[], options: CodegenOptions): string;
36
+ /**
37
+ * Generates TypeScript type definitions for routes.
38
+ * Provides type-safe route paths and parameter types.
39
+ *
40
+ * @param routes - Array of scanned route information
41
+ * @returns Generated TypeScript declaration code
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const routes = scanPages('./src/pages');
46
+ * const types = generateRouteTypes(routes);
47
+ * fs.writeFileSync('./src/routes.generated.d.ts', types);
48
+ * ```
49
+ */
50
+ export declare function generateRouteTypes(routes: ScannedRoute[]): string;
51
+ //# sourceMappingURL=codegen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,EAAE,cAAc,GACtB,MAAM,CAiDR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAoBjE"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Route code generation utilities.
3
+ * @module
4
+ */
5
+ import * as path from 'path';
6
+ /**
7
+ * Generates TypeScript code for route configuration from scanned routes.
8
+ * The output exports a `routes` array compatible with the Bromium router.
9
+ *
10
+ * @param routes - Array of scanned route information
11
+ * @param options - Code generation options
12
+ * @returns Generated TypeScript source code
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const routes = scanPages('./src/pages');
17
+ * const code = generateRouteConfig(routes, {
18
+ * pagesDir: './src/pages',
19
+ * outputPath: './src/routes.generated.ts',
20
+ * });
21
+ * fs.writeFileSync('./src/routes.generated.ts', code);
22
+ * ```
23
+ */
24
+ export function generateRouteConfig(routes, options) {
25
+ const { outputPath } = options;
26
+ const outputDir = path.dirname(outputPath);
27
+ const routeObjects = [];
28
+ routes.forEach((route) => {
29
+ let relativePath = path.relative(outputDir, route.filePath);
30
+ relativePath = relativePath.replace(/\\/g, '/');
31
+ relativePath = relativePath.replace(/\.(tsx?|jsx?)$/, '');
32
+ if (!relativePath.startsWith('.') && !relativePath.startsWith('/')) {
33
+ relativePath = './' + relativePath;
34
+ }
35
+ let layoutImport = '';
36
+ if (route.layoutPath) {
37
+ let layoutRelativePath = path.relative(outputDir, route.layoutPath);
38
+ layoutRelativePath = layoutRelativePath.replace(/\\/g, '/');
39
+ layoutRelativePath = layoutRelativePath.replace(/\.(tsx?|jsx?)$/, '');
40
+ if (!layoutRelativePath.startsWith('.') && !layoutRelativePath.startsWith('/')) {
41
+ layoutRelativePath = './' + layoutRelativePath;
42
+ }
43
+ layoutImport = `,\n layout: () => import('${layoutRelativePath}')`;
44
+ }
45
+ const routePath = route.routePath;
46
+ const routeObj = ` {
47
+ path: '${routePath}',
48
+ component: () => import('${relativePath}')${layoutImport},
49
+ }`;
50
+ routeObjects.push(routeObj);
51
+ });
52
+ return `// Auto-generated by @bromscandium/vite-plugin
53
+ // Do not edit manually - changes will be overwritten
54
+
55
+ import type { Route } from '@bromscandium/router';
56
+
57
+ export const routes: Route[] = [
58
+ ${routeObjects.join(',\n')}
59
+ ];
60
+
61
+ export default routes;
62
+ `;
63
+ }
64
+ /**
65
+ * Generates TypeScript type definitions for routes.
66
+ * Provides type-safe route paths and parameter types.
67
+ *
68
+ * @param routes - Array of scanned route information
69
+ * @returns Generated TypeScript declaration code
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const routes = scanPages('./src/pages');
74
+ * const types = generateRouteTypes(routes);
75
+ * fs.writeFileSync('./src/routes.generated.d.ts', types);
76
+ * ```
77
+ */
78
+ export function generateRouteTypes(routes) {
79
+ const routePaths = routes.map(r => ` | '${r.routePath}'`).join('\n');
80
+ const paramTypes = routes
81
+ .filter(r => r.params.length > 0)
82
+ .map(r => {
83
+ const params = r.params.map(p => ` ${p}: string;`).join('\n');
84
+ return ` '${r.routePath}': {\n${params}\n };`;
85
+ })
86
+ .join('\n');
87
+ return `// Auto-generated route types
88
+
89
+ export type RoutePath =
90
+ ${routePaths || " | '/'"}
91
+
92
+ export interface RouteParams {
93
+ ${paramTypes || " '/': Record<string, never>;"}
94
+ }
95
+ `;
96
+ }
97
+ //# sourceMappingURL=codegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAc7B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAsB,EACtB,OAAuB;IAEvB,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE/B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3C,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,IAAI,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC5D,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEhD,YAA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AAC,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEtE,MAAM,UAAU,GAAG,MAAM;SACtB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;SAChC,GAAG,CAAC,CAAC,CAAC,EAAE;QACP,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,OAAO,MAAM,CAAC,CAAC,SAAS,SAAS,MAAM,QAAQ,CAAC;IAClD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO;;;EAGP,UAAU,IAAI,SAAS;;;EAGvB,UAAU,IAAI,+BAA+B;;CAE9C,CAAC;AACF,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { bromiumPlugin } from './plugin.js';
2
+ export { bromiumPlugin, type BromiumPluginOptions } from './plugin.js';
3
+ export { scanPages, watchPages, type ScannedRoute } from './scanner.js';
4
+ export { generateRouteConfig, generateRouteTypes, type CodegenOptions } from './codegen.js';
5
+ export default bromiumPlugin;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAE5F,eAAe,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Vite plugin exports
2
+ import { bromiumPlugin } from './plugin.js';
3
+ export { bromiumPlugin } from './plugin.js';
4
+ export { scanPages, watchPages } from './scanner.js';
5
+ export { generateRouteConfig, generateRouteTypes } from './codegen.js';
6
+ export default bromiumPlugin;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,aAAa,EAA6B,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAqB,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAuB,MAAM,cAAc,CAAC;AAE5F,eAAe,aAAa,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Main Vite plugin for BromiumJS file-based routing.
3
+ * @module
4
+ */
5
+ import type { Plugin } from 'vite';
6
+ /**
7
+ * Configuration options for the Bromium Vite plugin.
8
+ */
9
+ export interface BromiumPluginOptions {
10
+ /**
11
+ * Directory containing page components.
12
+ * @default 'src/pages'
13
+ */
14
+ pagesDir?: string;
15
+ /**
16
+ * Output path for generated routes file.
17
+ * @default 'src/routes.generated.ts'
18
+ */
19
+ routesOutput?: string;
20
+ /**
21
+ * Base path for all routes (e.g., '/app/').
22
+ * @default ''
23
+ */
24
+ base?: string;
25
+ /**
26
+ * Generate TypeScript type definitions for routes.
27
+ * @default true
28
+ */
29
+ generateTypes?: boolean;
30
+ }
31
+ /**
32
+ * Creates the Bromium Vite plugin for file-based routing.
33
+ * Automatically scans the pages directory and generates route configuration.
34
+ *
35
+ * @param options - Plugin configuration options
36
+ * @returns A Vite plugin instance
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * // vite.config.ts
41
+ * import { defineConfig } from 'vite';
42
+ * import { bromiumPlugin } from '@bromscandium/vite-plugin';
43
+ *
44
+ * export default defineConfig({
45
+ * plugins: [
46
+ * bromiumPlugin({
47
+ * pagesDir: 'src/pages',
48
+ * base: '/app/',
49
+ * generateTypes: true,
50
+ * }),
51
+ * ],
52
+ * });
53
+ * ```
54
+ */
55
+ export declare function bromiumPlugin(options?: BromiumPluginOptions): Plugin;
56
+ export default bromiumPlugin;
57
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AAMlE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAoFxE;AAED,eAAe,aAAa,CAAC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Main Vite plugin for BromiumJS file-based routing.
3
+ * @module
4
+ */
5
+ import * as path from 'path';
6
+ import * as fs from 'fs';
7
+ import { scanPages, watchPages } from './scanner.js';
8
+ import { generateRouteConfig, generateRouteTypes } from './codegen.js';
9
+ /**
10
+ * Creates the Bromium Vite plugin for file-based routing.
11
+ * Automatically scans the pages directory and generates route configuration.
12
+ *
13
+ * @param options - Plugin configuration options
14
+ * @returns A Vite plugin instance
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * // vite.config.ts
19
+ * import { defineConfig } from 'vite';
20
+ * import { bromiumPlugin } from '@bromscandium/vite-plugin';
21
+ *
22
+ * export default defineConfig({
23
+ * plugins: [
24
+ * bromiumPlugin({
25
+ * pagesDir: 'src/pages',
26
+ * base: '/app/',
27
+ * generateTypes: true,
28
+ * }),
29
+ * ],
30
+ * });
31
+ * ```
32
+ */
33
+ export function bromiumPlugin(options = {}) {
34
+ const { pagesDir = 'src/pages', routesOutput = 'src/routes.generated.ts', base = '', generateTypes = true, } = options;
35
+ let root;
36
+ let fullPagesDir;
37
+ let fullRoutesOutput;
38
+ let stopWatcher = null;
39
+ async function generateRoutes() {
40
+ if (!fs.existsSync(fullPagesDir)) {
41
+ fs.mkdirSync(fullPagesDir, { recursive: true });
42
+ }
43
+ const routes = scanPages(fullPagesDir);
44
+ const code = generateRouteConfig(routes, {
45
+ pagesDir: fullPagesDir,
46
+ outputPath: fullRoutesOutput,
47
+ base,
48
+ });
49
+ const outputDir = path.dirname(fullRoutesOutput);
50
+ if (!fs.existsSync(outputDir)) {
51
+ fs.mkdirSync(outputDir, { recursive: true });
52
+ }
53
+ fs.writeFileSync(fullRoutesOutput, code, 'utf-8');
54
+ if (generateTypes) {
55
+ const typesPath = fullRoutesOutput.replace(/\.ts$/, '.d.ts');
56
+ const typesCode = generateRouteTypes(routes);
57
+ fs.writeFileSync(typesPath, typesCode, 'utf-8');
58
+ }
59
+ console.log(`[bromium] Generated routes from ${routes.length} pages`);
60
+ }
61
+ return {
62
+ name: 'bromium-plugin',
63
+ configResolved(config) {
64
+ root = config.root;
65
+ fullPagesDir = path.resolve(root, pagesDir);
66
+ fullRoutesOutput = path.resolve(root, routesOutput);
67
+ },
68
+ async buildStart() {
69
+ await generateRoutes();
70
+ },
71
+ configureServer(server) {
72
+ stopWatcher = watchPages(fullPagesDir, async () => {
73
+ await generateRoutes();
74
+ const module = server.moduleGraph.getModuleById(fullRoutesOutput);
75
+ if (module) {
76
+ server.moduleGraph.invalidateModule(module);
77
+ server.ws.send({
78
+ type: 'full-reload',
79
+ path: '*',
80
+ });
81
+ }
82
+ });
83
+ },
84
+ buildEnd() {
85
+ if (stopWatcher) {
86
+ stopWatcher();
87
+ stopWatcher = null;
88
+ }
89
+ },
90
+ transform(_code, id) {
91
+ if (!id.endsWith('.tsx') && !id.endsWith('.jsx')) {
92
+ return null;
93
+ }
94
+ return null;
95
+ },
96
+ };
97
+ }
98
+ export default bromiumPlugin;
99
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AA+BvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAAC,UAAgC,EAAE;IAC9D,MAAM,EACJ,QAAQ,GAAG,WAAW,EACtB,YAAY,GAAG,yBAAyB,EACxC,IAAI,GAAG,EAAE,EACT,aAAa,GAAG,IAAI,GACrB,GAAG,OAAO,CAAC;IAEZ,IAAI,IAAY,CAAC;IACjB,IAAI,YAAoB,CAAC;IACzB,IAAI,gBAAwB,CAAC;IAC7B,IAAI,WAAW,GAAwB,IAAI,CAAC;IAE5C,KAAK,UAAU,cAAc;QAC3B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YACjC,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,MAAM,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;QAEvC,MAAM,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE;YACvC,QAAQ,EAAE,YAAY;YACtB,UAAU,EAAE,gBAAgB;YAC5B,IAAI;SACL,CAAC,CAAC;QAEH,MAAM,S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AAC,MAAM,CAAC,CAAC;oBAC5C,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;wBACb,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,GAAG;qBACV,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,QAAQ;YACN,IAAI,WAAW,EAAE,CAAC;gBAChB,WAAW,EAAE,CAAC;gBACd,WAAW,GAAG,IAAI,CAAC;YACrB,CAAC;QACH,CAAC;QAED,SAAS,CAAC,KAAa,EAAE,EAAU;YACjC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjD,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * File system scanner for discovering page routes.
3
+ * @module
4
+ */
5
+ /**
6
+ * Information about a scanned route from the file system.
7
+ */
8
+ export interface ScannedRoute {
9
+ /** Absolute path to the page file */
10
+ filePath: string;
11
+ /** URL path for the route (e.g., '/users/:id') */
12
+ routePath: string;
13
+ /** Whether the route contains dynamic segments */
14
+ isDynamic: boolean;
15
+ /** Names of dynamic parameters in the route */
16
+ params: string[];
17
+ /** Whether this is a page component (page.tsx) */
18
+ isPage: boolean;
19
+ /** Whether this is a layout component */
20
+ isLayout: boolean;
21
+ /** Whether this is a catch-all route ([...slug]) */
22
+ isCatchAll: boolean;
23
+ /** URL path segments */
24
+ segments: string[];
25
+ /** Path to the layout file if one exists for this route */
26
+ layoutPath?: string;
27
+ /** File system relative path (includes route groups) */
28
+ fsPath: string;
29
+ }
30
+ /**
31
+ * Scans a pages directory and returns all discovered routes.
32
+ * Supports Next.js-style file-based routing conventions including:
33
+ * - `page.tsx` files for page components
34
+ * - `layout.tsx` files for layout wrappers
35
+ * - `[param]` for dynamic route segments
36
+ * - `[...slug]` for catch-all routes
37
+ * - `(group)` folders for route grouping without URL segments
38
+ *
39
+ * @param pagesDir - The directory to scan for pages
40
+ * @returns An array of scanned route information, sorted by priority
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const routes = scanPages('./src/pages');
45
+ * // Returns routes sorted: static > dynamic > catch-all
46
+ * ```
47
+ */
48
+ export declare function scanPages(pagesDir: string): ScannedRoute[];
49
+ /**
50
+ * Watches a pages directory for changes and invokes a callback when files change.
51
+ *
52
+ * @param pagesDir - The directory to watch
53
+ * @param onChange - Callback invoked when a page file changes
54
+ * @returns A function to stop watching
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const stop = watchPages('./src/pages', () => {
59
+ * console.log('Pages changed, regenerating routes...');
60
+ * });
61
+ *
62
+ * // Later: stop watching
63
+ * stop();
64
+ * ```
65
+ */
66
+ export declare function watchPages(pagesDir: string, onChange: () => void): () => void;
67
+ //# sourceMappingURL=scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,SAAS,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,kDAAkD;IAClD,MAAM,EAAE,OAAO,CAAC;IAChB,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,oDAAoD;IACpD,UAAU,EAAE,OAAO,CAAC;IACpB,wBAAwB;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;CAChB;AAQD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CAoC1D;AAyJD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,IAAI,GACnB,MAAM,IAAI,CAeZ"}