22
33/**
44 * Copy WebUI static assets from source to build output directory.
5- *
5+ *
66 * This script copies HTML, CSS, and other static files from src/webui/static/
77 * to dist/webui/static/ as part of the webui build process.
88 */
@@ -20,24 +20,24 @@ const filesToCopy = ['index.html', 'webui.css', 'gridstack-extra.min.css', 'favi
2020const vendorLibraries = [
2121 {
2222 src : 'node_modules/gridstack/dist/gridstack-all.js' ,
23- dest : 'gridstack-all.js'
23+ dest : 'gridstack-all.js' ,
2424 } ,
2525 {
2626 src : 'node_modules/gridstack/dist/gridstack.min.css' ,
27- dest : 'gridstack.min.css'
27+ dest : 'gridstack.min.css' ,
2828 } ,
2929 {
3030 src : 'node_modules/lucide/dist/umd/lucide.min.js' ,
31- dest : 'lucide.min.js'
32- }
31+ dest : 'lucide.min.js' ,
32+ } ,
3333] ;
3434
3535// Local lib files to copy
3636const libFiles = [
3737 {
3838 src : 'src/webui/static/lib/video-rtc.js' ,
39- dest : 'lib/video-rtc.js'
40- }
39+ dest : 'lib/video-rtc.js' ,
40+ } ,
4141] ;
4242
4343const GREEN = '\u001B[32m' ;
@@ -84,30 +84,42 @@ function appendVersion(assetPath, buildId) {
8484
8585function rewriteHtmlAssetUrls ( content , buildId ) {
8686 const assetAttributePattern = / ( \b (?: h r e f | s r c ) = [ " ' ] ) ( [ ^ " ' ] + \. (?: c s s | j s | p n g ) ) (?: \? [ ^ " ' ] * ) ? ( [ " ' ] ) / g;
87- const inlineModulePattern = / ( (?: i m p o r t | e x p o r t ) \s + (?: [ ^ ' " ] * ?\s + f r o m \s + ) ? [ " ' ] ) ( \. { 1 , 2 } \/ [ ^ " ' ] + \. j s ) (?: \? [ ^ " ' ] * ) ? ( [ " ' ] ) / g;
87+ const inlineModulePattern =
88+ / ( (?: i m p o r t | e x p o r t ) \s + (?: [ ^ ' " ] * ?\s + f r o m \s + ) ? [ " ' ] ) ( \. { 1 , 2 } \/ [ ^ " ' ] + \. j s ) (?: \? [ ^ " ' ] * ) ? ( [ " ' ] ) / g;
89+
90+ const withVersionedAttributes = content . replace (
91+ assetAttributePattern ,
92+ ( match , prefix , assetPath , suffix ) => {
93+ if ( ! isLocalAssetPath ( assetPath ) ) {
94+ return match ;
95+ }
8896
89- const withVersionedAttributes = content . replace ( assetAttributePattern , ( match , prefix , assetPath , suffix ) => {
90- if ( ! isLocalAssetPath ( assetPath ) ) {
91- return match ;
97+ return `${ prefix } ${ appendVersion ( assetPath , buildId ) } ${ suffix } ` ;
9298 }
99+ ) ;
93100
94- return ` ${ prefix } ${ appendVersion ( assetPath , buildId ) } ${ suffix } ` ;
95- } ) ;
96-
97- return withVersionedAttributes . replace ( inlineModulePattern , ( match , prefix , assetPath , suffix ) => {
98- return ` ${ prefix } ${ appendVersion ( assetPath , buildId ) } ${ suffix } ` ;
99- } ) ;
101+ return withVersionedAttributes . replace (
102+ inlineModulePattern ,
103+ ( _match , prefix , assetPath , suffix ) => {
104+ return ` ${ prefix } ${ appendVersion ( assetPath , buildId ) } ${ suffix } ` ;
105+ }
106+ ) ;
100107}
101108
102109function rewriteModuleImports ( content , buildId ) {
103- const staticImportPattern = / ( (?: i m p o r t | e x p o r t ) \s + (?: [ ^ ' " ] * ?\s + f r o m \s + ) ? [ " ' ] ) ( \. { 1 , 2 } \/ [ ^ " ' ] + \. j s ) (?: \? [ ^ " ' ] * ) ? ( [ " ' ] ) / g;
104- const dynamicImportPattern = / ( \b i m p o r t \s * \( \s * [ " ' ] ) ( \. { 1 , 2 } \/ [ ^ " ' ] + \. j s ) (?: \? [ ^ " ' ] * ) ? ( [ " ' ] \s * \) ) / g;
105-
106- const withStaticImports = content . replace ( staticImportPattern , ( match , prefix , assetPath , suffix ) => {
107- return `${ prefix } ${ appendVersion ( assetPath , buildId ) } ${ suffix } ` ;
108- } ) ;
110+ const staticImportPattern =
111+ / ( (?: i m p o r t | e x p o r t ) \s + (?: [ ^ ' " ] * ?\s + f r o m \s + ) ? [ " ' ] ) ( \. { 1 , 2 } \/ [ ^ " ' ] + \. j s ) (?: \? [ ^ " ' ] * ) ? ( [ " ' ] ) / g;
112+ const dynamicImportPattern =
113+ / ( \b i m p o r t \s * \( \s * [ " ' ] ) ( \. { 1 , 2 } \/ [ ^ " ' ] + \. j s ) (?: \? [ ^ " ' ] * ) ? ( [ " ' ] \s * \) ) / g;
114+
115+ const withStaticImports = content . replace (
116+ staticImportPattern ,
117+ ( _match , prefix , assetPath , suffix ) => {
118+ return `${ prefix } ${ appendVersion ( assetPath , buildId ) } ${ suffix } ` ;
119+ }
120+ ) ;
109121
110- return withStaticImports . replace ( dynamicImportPattern , ( match , prefix , assetPath , suffix ) => {
122+ return withStaticImports . replace ( dynamicImportPattern , ( _match , prefix , assetPath , suffix ) => {
111123 return `${ prefix } ${ appendVersion ( assetPath , buildId ) } ${ suffix } ` ;
112124 } ) ;
113125}
@@ -168,25 +180,25 @@ function copyWebUIAssets() {
168180 // Ensure destination directory exists
169181 fs . mkdirSync ( destDir , { recursive : true } ) ;
170182 logInfo ( `created directory ${ destDir } ` ) ;
171-
183+
172184 // Copy each file
173185 let copiedCount = 0 ;
174186 for ( const fileName of filesToCopy ) {
175187 const srcPath = path . join ( srcDir , fileName ) ;
176188 const destPath = path . join ( destDir , fileName ) ;
177-
189+
178190 // Check if source file exists
179191 if ( ! fs . existsSync ( srcPath ) ) {
180192 logWarn ( `source file missing ${ srcPath } ` ) ;
181193 continue ;
182194 }
183-
195+
184196 // Copy the file
185197 fs . copyFileSync ( srcPath , destPath ) ;
186198 logInfo ( `copied ${ fileName } ` ) ;
187199 copiedCount ++ ;
188200 }
189-
201+
190202 logInfo ( `webui asset copy complete ${ copiedCount } /${ filesToCopy . length } ` ) ;
191203
192204 // Copy vendor libraries
@@ -233,7 +245,6 @@ function copyWebUIAssets() {
233245
234246 logInfo ( `lib file copy complete ${ libCount } /${ libFiles . length } ` ) ;
235247 applyBuildStamp ( destDir ) ;
236-
237248 } catch ( error ) {
238249 logError ( `error copying WebUI assets: ${ error . message } ` ) ;
239250 process . exit ( 1 ) ;
0 commit comments