@@ -11,6 +11,7 @@ import { themes } from "../src/lib/registry/themes";
11
11
import { buildRegistry } from "./registry" ;
12
12
import { transformContent } from "./transformers" ;
13
13
import { BASE_STYLES , BASE_STYLES_WITH_VARIABLES , THEME_STYLES_WITH_VARIABLES } from "./templates" ;
14
+ import { getChunks } from "./transform-chunks.js" ;
14
15
15
16
const REGISTRY_PATH = path . resolve ( "static" , "registry" ) ;
16
17
const REGISTRY_IGNORE = [ "super-form" ] ;
@@ -24,6 +25,54 @@ async function main() {
24
25
process . exit ( 1 ) ;
25
26
}
26
27
28
+ // ----------------------------------------------------------------------------
29
+ // Build blocks registry (__registry__/blocks.js) and block chunks (__registry__/chunks/[style]/[block]-[chunk].svelte)
30
+ // ----------------------------------------------------------------------------
31
+ const registryChunksDirPath = path . resolve ( "src" , "__registry__" , "chunks" ) ;
32
+ const libPath = path . resolve ( "src" , "lib" , "registry" ) ;
33
+ rimraf . sync ( registryChunksDirPath ) ;
34
+ let blocksIndex = `
35
+ // This file is autogenerated by scripts/build-registry.ts
36
+ // Do not edit this file directly.
37
+ export const Blocks = {
38
+ ` ;
39
+ // Create the __registry__/chunks/[style] dir
40
+ for ( const style of styles ) {
41
+ blocksIndex += `\t"${ style . name } ": {` ;
42
+ const chunkStyleDir = path . resolve ( registryChunksDirPath , style . name ) ;
43
+ // Create directory if it doesn't exist.
44
+ if ( ! fs . existsSync ( chunkStyleDir ) ) {
45
+ fs . mkdirSync ( chunkStyleDir , { recursive : true } ) ;
46
+ }
47
+ // Creates chunk files
48
+ for ( const block of result . data ) {
49
+ if ( block . type !== "components:block" || block . style !== style . name ) continue ;
50
+ const file = block . files [ 0 ] ;
51
+ const blockPath = path . resolve ( libPath , block . style , "block" , file . name ) ;
52
+ const chunkDir = path . resolve ( registryChunksDirPath , block . style ) ;
53
+
54
+ const chunks = getChunks ( file . content , blockPath ) ;
55
+ for ( const chunk of chunks ) {
56
+ const chunkPath = path . resolve ( chunkDir , `${ chunk . name } .svelte` ) ;
57
+ fs . writeFileSync ( chunkPath , chunk . content , { encoding : "utf8" } ) ;
58
+ }
59
+
60
+ blocksIndex += `
61
+ "${ block . name } ": {
62
+ name: "${ block . name } ",
63
+ type: "${ block . type } ",
64
+ chunks: [${ chunks . map ( ( chunk ) => ` { name: "${ chunk . name } ", description: "${ chunk . description } ", container: { className: "${ chunk . container . className } " }, raw: () => import("./chunks/${ style . name } /${ chunk . name } .svelte?raw").then((m) => m.default), component: () => import("./chunks/${ style . name } /${ chunk . name } .svelte").then((m) => m.default) }` ) } ],
65
+ component: () => import("../lib/registry/${ style . name } /block/${ block . name } .svelte").then((m) => m.default),
66
+ raw: () => import("../lib/registry/${ style . name } /block/${ block . name } .svelte?raw").then((m) => m.default),
67
+ },` ;
68
+ }
69
+ // end of style
70
+ blocksIndex += `\n\t},` ;
71
+ }
72
+ blocksIndex += "\n};\n" ;
73
+ const blocksPath = path . resolve ( "src" , "__registry__" , "blocks.js" ) ;
74
+ fs . writeFileSync ( blocksPath , blocksIndex ) ;
75
+
27
76
// ----------------------------------------------------------------------------
28
77
// Build __registry__/index.js.
29
78
// ----------------------------------------------------------------------------
@@ -38,15 +87,19 @@ export const Index = {
38
87
39
88
// Build style index.
40
89
for ( const item of result . data ) {
41
- if ( item . type === "components:ui" || item . style !== "default" ) {
90
+ if (
91
+ item . type === "components:ui" ||
92
+ item . type === "components:block" ||
93
+ item . style !== "default"
94
+ ) {
42
95
continue ;
43
96
}
97
+ const type = item . type . split ( ":" ) [ 1 ] ;
44
98
45
99
const resolveFiles = item . files . map (
46
100
( file ) => `../lib/registry/${ style . name } /${ file . path } `
47
101
) ;
48
102
49
- const type = item . type . split ( ":" ) [ 1 ] ;
50
103
index += `
51
104
"${ item . name } ": {
52
105
name: "${ item . name } ",
0 commit comments