@mantiq/vite 0.6.1 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantiq/vite",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "Vite dev server & manifest integration",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -30,3 +30,6 @@ export { ServeStaticFiles } from './middleware/ServeStaticFiles.ts'
30
30
 
31
31
  // ── Helpers ──────────────────────────────────────────────────────────────────
32
32
  export { vite } from './helpers/vite.ts'
33
+
34
+ // ── Vite Plugins ─────────────────────────────────────────────────────────────
35
+ export { mantiq } from './plugins/mantiq.ts'
@@ -0,0 +1,78 @@
1
+ import type { Plugin } from 'vite'
2
+ import { existsSync } from 'node:fs'
3
+ import { resolve } from 'node:path'
4
+
5
+ /**
6
+ * Mantiq Vite plugin — auto-discovers and registers plugins from
7
+ * installed @mantiq/* packages.
8
+ *
9
+ * Packages declare their Vite plugin via `"mantiq.vitePlugin"` in
10
+ * package.json. The plugin is dynamically imported and registered.
11
+ *
12
+ * Currently supports:
13
+ * - @mantiq/studio → studioPlugin({ path }) for admin panel hot reload
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // vite.config.ts — user only adds mantiq()
18
+ * import { mantiq } from '@mantiq/vite'
19
+ *
20
+ * export default defineConfig({
21
+ * plugins: [react(), tailwindcss(), mantiq()],
22
+ * })
23
+ * ```
24
+ */
25
+ export async function mantiq(): Promise<Plugin[]> {
26
+ const plugins: Plugin[] = []
27
+ const cwd = process.cwd()
28
+
29
+ // ── Auto-discover Studio ────────────────────────────────────────────────
30
+
31
+ try {
32
+ // Check if @mantiq/studio is installed
33
+ const studioPkg = resolve(cwd, 'node_modules', '@mantiq', 'studio', 'package.json')
34
+ if (existsSync(studioPkg)) {
35
+ // Check if Studio is configured (app/Studio/ directory exists)
36
+ const studioDir = resolve(cwd, 'app', 'Studio')
37
+ if (existsSync(studioDir)) {
38
+ // Discover panel path from the first panel file
39
+ const panelPath = await discoverPanelPath(studioDir)
40
+
41
+ // @ts-ignore — @mantiq/studio may not be installed
42
+ const { studioPlugin } = await import('@mantiq/studio/vite') as any
43
+ const plugin = studioPlugin({ path: panelPath })
44
+ plugins.push(plugin)
45
+ }
46
+ }
47
+ } catch {
48
+ // Studio not installed or not configured — skip silently
49
+ }
50
+
51
+ // ── Future: auto-discover other @mantiq/* Vite plugins ──────────────────
52
+ // When more packages need Vite integration, scan node_modules/@mantiq/*/package.json
53
+ // for "mantiq.vitePlugin" field and dynamically import each.
54
+
55
+ return plugins
56
+ }
57
+
58
+ /**
59
+ * Read the first StudioPanel class found in app/Studio/ to extract
60
+ * the panel path (e.g., '/admin'). Falls back to '/admin'.
61
+ */
62
+ async function discoverPanelPath(studioDir: string): Promise<string> {
63
+ try {
64
+ const { Glob } = await import('bun')
65
+ const glob = new Glob('**/*Panel.ts')
66
+
67
+ for await (const file of glob.scan(studioDir)) {
68
+ const content = await Bun.file(resolve(studioDir, file)).text()
69
+ // Look for: path = '/admin' or path = "/admin"
70
+ const match = content.match(/path\s*=\s*['"]([^'"]+)['"]/)
71
+ if (match) return match[1]!
72
+ }
73
+ } catch {
74
+ // Glob not available or no panel files
75
+ }
76
+
77
+ return '/admin'
78
+ }