@van1s1mys/ai-router-plugin-vite 1.0.0 → 1.0.1

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/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @van1s1mys/ai-router-plugin-vite
2
+
3
+ Vite plugin for [@van1s1mys/ai-router](https://www.npmjs.com/package/@van1s1mys/ai-router) — auto-scans your pages directory and exposes routes via a virtual module.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @van1s1mys/ai-router @van1s1mys/ai-router-plugin-vite
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ ```ts
14
+ // vite.config.ts
15
+ import { defineConfig } from 'vite';
16
+ import { aiRouter } from '@van1s1mys/ai-router-plugin-vite';
17
+
18
+ export default defineConfig({
19
+ plugins: [aiRouter()],
20
+ });
21
+ ```
22
+
23
+ ```ts
24
+ // app.ts
25
+ import { SmartRouter } from '@van1s1mys/ai-router';
26
+ import { routes } from 'virtual:ai-router';
27
+
28
+ const router = new SmartRouter({ routes });
29
+ await router.ready;
30
+
31
+ const result = await router.search('how much does it cost?');
32
+ ```
33
+
34
+ ## Options
35
+
36
+ ```ts
37
+ aiRouter({
38
+ // Directories to scan (default: auto-detect)
39
+ dirs: ['src/pages'],
40
+
41
+ // File extensions to include
42
+ extensions: ['.tsx', '.jsx', '.vue', '.svelte', '.astro', '.md', '.mdx'],
43
+
44
+ // Patterns to exclude
45
+ exclude: ['_layout', 'api/'],
46
+
47
+ // Additional manual routes merged with scanned ones
48
+ routes: [
49
+ { path: '/pricing', title: 'Pricing', description: 'cost, plans' },
50
+ ],
51
+ });
52
+ ```
53
+
54
+ ## Route annotations
55
+
56
+ Add `@ai-route` comments to page files for richer metadata:
57
+
58
+ ```tsx
59
+ // @ai-route title="Pricing" description="plans, cost, billing, subscription"
60
+
61
+ export default function PricingPage() { ... }
62
+ ```
63
+
64
+ ## HMR
65
+
66
+ Routes are re-scanned automatically when files in the scanned directories change.
67
+
68
+ ## License
69
+
70
+ [MIT](../../LICENSE) © [IvanMalkS](https://github.com/IvanMalkS)
package/dist/index.cjs CHANGED
@@ -57,4 +57,3 @@ function aiRouter(options = {}) {
57
57
  0 && (module.exports = {
58
58
  aiRouter
59
59
  });
60
- //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -37,4 +37,3 @@ function aiRouter(options = {}) {
37
37
  export {
38
38
  aiRouter
39
39
  };
40
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@van1s1mys/ai-router-plugin-vite",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Vite plugin for ai-router — auto-scan pages and generate route config",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Vite plugin for ai-router.\n *\n * Scans page directories at build time and exposes a `virtual:ai-router`\n * module that exports the generated route config array.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { aiRouter } from 'ai-router-plugin-vite';\n *\n * export default defineConfig({\n * plugins: [\n * aiRouter({ dirs: ['src/pages'] }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // app.ts\n * import { routes } from 'virtual:ai-router';\n * import { SmartRouter } from 'ai-router';\n *\n * const router = new SmartRouter({ routes });\n * ```\n *\n * @module\n */\n\nimport type { Plugin } from 'vite';\nimport {\n scanRoutes,\n generateRoutesModule,\n VIRTUAL_MODULE_ID,\n RESOLVED_VIRTUAL_MODULE_ID,\n type PluginOptions,\n} from '@ai-router/shared';\n\nexport type { PluginOptions } from '@ai-router/shared';\n\n/**\n * Creates a Vite plugin that generates route config from the file system.\n *\n * The plugin provides a virtual module `virtual:ai-router` that exports\n * a `routes` array compatible with {@link SmartRouter}.\n *\n * Supports HMR — routes are re-scanned when files in `dirs` change.\n *\n * @param options - Directories to scan, file extensions, exclusions, and manual routes.\n * @returns Vite plugin instance.\n *\n * @example\n * ```ts\n * // Auto-scan + manual overrides\n * aiRouter({\n * dirs: ['src/pages'],\n * routes: [\n * { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },\n * ],\n * });\n * ```\n */\nexport function aiRouter(options: PluginOptions = {}): Plugin {\n let root = process.cwd();\n\n return {\n name: 'ai-router',\n\n configResolved(config) {\n root = config.root;\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n const routes = scanRoutes(root, options);\n return generateRoutesModule(routes);\n }\n },\n\n handleHotUpdate({ file, server }) {\n if (options.dirs?.some((dir) => file.includes(dir))) {\n const module = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n server.ws.send({ type: 'full-reload' });\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BA,oBAMO;AA0BA,SAAS,SAAS,UAAyB,CAAC,GAAW;AAC5D,MAAI,OAAO,QAAQ,IAAI;AAEvB,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,eAAe,QAAQ;AACrB,aAAO,OAAO;AAAA,IAChB;AAAA,IAEA,UAAU,IAAI;AACZ,UAAI,OAAO,iCAAmB;AAC5B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,0CAA4B;AACrC,cAAM,aAAS,0BAAW,MAAM,OAAO;AACvC,mBAAO,oCAAqB,MAAM;AAAA,MACpC;AAAA,IACF;AAAA,IAEA,gBAAgB,EAAE,MAAM,OAAO,GAAG;AAChC,UAAI,QAAQ,MAAM,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,CAAC,GAAG;AACnD,cAAMA,UAAS,OAAO,YAAY,cAAc,wCAA0B;AAC1E,YAAIA,SAAQ;AACV,iBAAO,YAAY,iBAAiBA,OAAM;AAC1C,iBAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["module"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Vite plugin for ai-router.\n *\n * Scans page directories at build time and exposes a `virtual:ai-router`\n * module that exports the generated route config array.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { aiRouter } from 'ai-router-plugin-vite';\n *\n * export default defineConfig({\n * plugins: [\n * aiRouter({ dirs: ['src/pages'] }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // app.ts\n * import { routes } from 'virtual:ai-router';\n * import { SmartRouter } from 'ai-router';\n *\n * const router = new SmartRouter({ routes });\n * ```\n *\n * @module\n */\n\nimport type { Plugin } from 'vite';\nimport {\n scanRoutes,\n generateRoutesModule,\n VIRTUAL_MODULE_ID,\n RESOLVED_VIRTUAL_MODULE_ID,\n type PluginOptions,\n} from '@ai-router/shared';\n\nexport type { PluginOptions } from '@ai-router/shared';\n\n/**\n * Creates a Vite plugin that generates route config from the file system.\n *\n * The plugin provides a virtual module `virtual:ai-router` that exports\n * a `routes` array compatible with {@link SmartRouter}.\n *\n * Supports HMR — routes are re-scanned when files in `dirs` change.\n *\n * @param options - Directories to scan, file extensions, exclusions, and manual routes.\n * @returns Vite plugin instance.\n *\n * @example\n * ```ts\n * // Auto-scan + manual overrides\n * aiRouter({\n * dirs: ['src/pages'],\n * routes: [\n * { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },\n * ],\n * });\n * ```\n */\nexport function aiRouter(options: PluginOptions = {}): Plugin {\n let root = process.cwd();\n\n return {\n name: 'ai-router',\n\n configResolved(config) {\n root = config.root;\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n const routes = scanRoutes(root, options);\n return generateRoutesModule(routes);\n }\n },\n\n handleHotUpdate({ file, server }) {\n if (options.dirs?.some((dir) => file.includes(dir))) {\n const module = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n server.ws.send({ type: 'full-reload' });\n }\n }\n },\n };\n}\n"],"mappings":";AA8BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA0BA,SAAS,SAAS,UAAyB,CAAC,GAAW;AAC5D,MAAI,OAAO,QAAQ,IAAI;AAEvB,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,eAAe,QAAQ;AACrB,aAAO,OAAO;AAAA,IAChB;AAAA,IAEA,UAAU,IAAI;AACZ,UAAI,OAAO,mBAAmB;AAC5B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,4BAA4B;AACrC,cAAM,SAAS,WAAW,MAAM,OAAO;AACvC,eAAO,qBAAqB,MAAM;AAAA,MACpC;AAAA,IACF;AAAA,IAEA,gBAAgB,EAAE,MAAM,OAAO,GAAG;AAChC,UAAI,QAAQ,MAAM,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,CAAC,GAAG;AACnD,cAAM,SAAS,OAAO,YAAY,cAAc,0BAA0B;AAC1E,YAAI,QAAQ;AACV,iBAAO,YAAY,iBAAiB,MAAM;AAC1C,iBAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}