@zenithbuild/bundler 1.3.16 → 1.3.17

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/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export * from './bundle-generator';
2
+ export * from './generateFinalBundle';
3
+ export * from './build-analyzer';
4
+ export * from './bundler';
5
+ export * from './css';
6
+ export * from './runtime-generator';
7
+ export * from './types';
8
+ export * from './ssg-build';
9
+ export * from './spa-build';
10
+ export * from './discovery/componentDiscovery';
11
+ export * from './discovery/layouts';
12
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@zenithbuild/bundler",
3
- "version": "1.3.16",
3
+ "version": "1.3.17",
4
4
  "scripts": {
5
- "build": "napi build --platform --release",
5
+ "build": "tsc && napi build --platform --release",
6
6
  "artifacts": "napi artifacts",
7
7
  "version": "napi version"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@napi-rs/cli": "^3.5.1",
11
- "@types/bun": "latest"
11
+ "@types/bun": "latest",
12
+ "typescript": "^5"
12
13
  },
13
- "main": "src/index.ts",
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
14
16
  "exports": {
15
- ".": "./src/index.ts",
17
+ ".": "./dist/index.js",
16
18
  "./dev-server": "./dev-server.js"
17
19
  },
18
20
  "files": [
@@ -31,6 +33,7 @@
31
33
  },
32
34
  "peerDependencies": {
33
35
  "typescript": "^5",
34
- "@zenithbuild/compiler": "^1.3.15"
36
+ "@zenithbuild/compiler": "^1.3.17",
37
+ "@zenithbuild/router": "^1.3.17"
35
38
  }
36
- }
39
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Component Discovery
3
+ *
4
+ * Discovers and catalogs components in a Zenith project using standard
5
+ * file system walking and the unified native "syscall" for metadata.
6
+ */
7
+
8
+ import * as fs from 'fs'
9
+ import * as path from 'path'
10
+ import { parseZenFile, type TemplateNode, type ExpressionIR } from '@zenithbuild/compiler'
11
+
12
+ export interface SlotDefinition {
13
+ name: string | null // null = default slot, string = named slot
14
+ location: {
15
+ line: number
16
+ column: number
17
+ }
18
+ }
19
+
20
+ export interface ComponentMetadata {
21
+ name: string // Component name (e.g., "Card", "Button")
22
+ path: string // Absolute path to .zen file
23
+ template: string // Raw template HTML
24
+ nodes: TemplateNode[] // Parsed template nodes
25
+ expressions: ExpressionIR[] // Component-level expressions
26
+ slots: SlotDefinition[]
27
+ props: string[] // Declared props
28
+ states: Record<string, string> // Declared state (name -> initializer)
29
+ styles: string[] // Raw CSS from <style> blocks
30
+ script: string | null // Raw script content for bundling
31
+ scriptAttributes: Record<string, string> | null // Script attributes (setup, lang)
32
+ hasScript: boolean
33
+ hasStyles: boolean
34
+ }
35
+
36
+ /**
37
+ * Discover all components in a directory recursively
38
+ */
39
+ export function discoverComponents(baseDir: string): Map<string, ComponentMetadata> {
40
+ const components = new Map<string, ComponentMetadata>()
41
+
42
+ if (!fs.existsSync(baseDir)) return components;
43
+
44
+ const walk = (dir: string) => {
45
+ const files = fs.readdirSync(dir);
46
+ for (const file of files) {
47
+ const fullPath = path.join(dir, file);
48
+ if (fs.statSync(fullPath).isDirectory()) {
49
+ walk(fullPath);
50
+ } else if (file.endsWith('.zen')) {
51
+ const name = path.basename(file, '.zen');
52
+ try {
53
+ // Call the "One True Bridge" in metadata mode
54
+ const ir = parseZenFile(fullPath, undefined, { mode: 'metadata' });
55
+
56
+ // Map IR to ComponentMetadata format
57
+ components.set(name, {
58
+ name,
59
+ path: fullPath,
60
+ template: ir.template.raw,
61
+ nodes: ir.template.nodes,
62
+ expressions: ir.template.expressions,
63
+ slots: [], // Native bridge needs to return slot info in IR if used
64
+ props: ir.props || [],
65
+ states: ir.script?.states || {},
66
+ styles: ir.styles?.map((s: any) => s.raw) || [],
67
+ script: ir.script?.raw || null,
68
+ scriptAttributes: ir.script?.attributes || null,
69
+ hasScript: !!ir.script,
70
+ hasStyles: ir.styles?.length > 0
71
+ });
72
+ } catch (e) {
73
+ console.error(`[Zenith Discovery] Failed to parse component ${file}:`, e);
74
+ }
75
+ }
76
+ }
77
+ };
78
+
79
+ walk(baseDir);
80
+ return components;
81
+ }
82
+
83
+ /**
84
+ * Universal Zenith Component Tag Rule: PascalCase
85
+ */
86
+ export function isComponentTag(tagName: string): boolean {
87
+ return tagName.length > 0 && tagName[0] === tagName[0]?.toUpperCase()
88
+ }
89
+
90
+ /**
91
+ * Get component metadata by name
92
+ */
93
+ export function getComponent(
94
+ components: Map<string, ComponentMetadata>,
95
+ name: string
96
+ ): ComponentMetadata | undefined {
97
+ return components.get(name)
98
+ }
@@ -0,0 +1,50 @@
1
+ import * as fs from 'fs'
2
+ import * as path from 'path'
3
+ import { parseZenFile } from '@zenithbuild/compiler'
4
+
5
+ export interface LayoutMetadata {
6
+ name: string
7
+ filePath: string
8
+ props: string[]
9
+ states: Map<string, any>
10
+ html: string
11
+ scripts: string[]
12
+ styles: string[]
13
+ }
14
+
15
+ /**
16
+ * Discover layouts in a directory using standard file system walking
17
+ * and the unified native bridge for metadata.
18
+ */
19
+ export function discoverLayouts(layoutsDir: string): Map<string, LayoutMetadata> {
20
+ const layouts = new Map<string, LayoutMetadata>()
21
+
22
+ if (!fs.existsSync(layoutsDir)) return layouts
23
+
24
+ const files = fs.readdirSync(layoutsDir)
25
+ for (const file of files) {
26
+ if (file.endsWith('.zen')) {
27
+ const fullPath = path.join(layoutsDir, file)
28
+ const name = path.basename(file, '.zen')
29
+
30
+ try {
31
+ // Call the "One True Bridge" in metadata mode
32
+ const ir = parseZenFile(fullPath, undefined, { mode: 'metadata' })
33
+
34
+ layouts.set(name, {
35
+ name,
36
+ filePath: fullPath,
37
+ props: ir.props || [],
38
+ states: new Map(),
39
+ html: ir.template.raw,
40
+ scripts: ir.script ? [ir.script.content] : [],
41
+ styles: ir.styles?.map((s: any) => s.raw) || []
42
+ })
43
+ } catch (e) {
44
+ console.error(`[Zenith Layout Discovery] Failed to parse layout ${file}:`, e)
45
+ }
46
+ }
47
+ }
48
+
49
+ return layouts
50
+ }
package/src/index.ts CHANGED
@@ -5,3 +5,7 @@ export * from './bundler'
5
5
  export * from './css'
6
6
  export * from './runtime-generator'
7
7
  export * from './types'
8
+ export * from './ssg-build'
9
+ export * from './spa-build'
10
+ export * from './discovery/componentDiscovery'
11
+ export * from './discovery/layouts'