@@ -68,17 +68,24 @@ const skipEmbedWebUi = process.argv.includes("--skip-embed-web-ui")
6868const createEmbeddedWebUIBundle = async ( ) => {
6969 console . log ( `Building Web UI to embed in the binary` )
7070 const appDir = path . join ( import . meta. dirname , "../../app" )
71+ const dist = path . join ( appDir , "dist" )
7172 await $ `bun run --cwd ${ appDir } build`
72- const allFiles = await Array . fromAsync ( new Bun . Glob ( "**/*" ) . scan ( { cwd : path . join ( appDir , "dist" ) } ) )
73- const fileMap = `
74- // Import all files as file_$i with type: "file"
75- ${ allFiles . map ( ( filePath , i ) => `import file_${ i } from "${ path . join ( appDir , "dist" , filePath ) } " with { type: "file" };` ) . join ( "\n" ) }
76- // Export with original mappings
77- export default {
78- ${ allFiles . map ( ( filePath , i ) => `"${ filePath } ": file_${ i } ,` ) . join ( "\n" ) }
79- }
80- ` . trim ( )
81- return fileMap
73+ const files = ( await Array . fromAsync ( new Bun . Glob ( "**/*" ) . scan ( { cwd : dist } ) ) )
74+ . map ( ( file ) => file . replaceAll ( "\\" , "/" ) )
75+ . sort ( )
76+ const imports = files . map ( ( file , i ) => {
77+ const spec = path . relative ( dir , path . join ( dist , file ) ) . replaceAll ( "\\" , "/" )
78+ return `import file_${ i } from ${ JSON . stringify ( spec . startsWith ( "." ) ? spec : `./${ spec } ` ) } with { type: "file" };`
79+ } )
80+ const entries = files . map ( ( file , i ) => ` ${ JSON . stringify ( file ) } : file_${ i } ,` )
81+ return [
82+ `// Import all files as file_$i with type: "file"` ,
83+ ...imports ,
84+ `// Export with original mappings` ,
85+ `export default {` ,
86+ ...entries ,
87+ `}` ,
88+ ] . join ( "\n" )
8289}
8390
8491const embeddedFileMap = skipEmbedWebUi ? null : await createEmbeddedWebUIBundle ( )
0 commit comments