@@ -3,6 +3,13 @@ const fs = require('fs');
33const path = require ( 'path' ) ;
44
55const projectRoot = path . resolve ( __dirname , '..' ) ;
6+ const chartPath = path . join ( projectRoot , 'src' , 'components' , 'ChartUPlot.tsx' ) ;
7+ const chartPathOut = path . join (
8+ projectRoot ,
9+ 'dist' ,
10+ 'components' ,
11+ 'ChartUPlot.tsx' ,
12+ ) ;
613const htmlPath = path . join ( projectRoot , 'src' , 'components' , 'uplot.html' ) ;
714const htmlPathOut = path . join ( projectRoot , 'dist' , 'components' , 'uplot.html' ) ;
815const cssPath = path . join (
@@ -22,7 +29,8 @@ const jsPath = path.join(
2229
2330async function main ( ) {
2431 try {
25- const [ html , css , js ] = await Promise . all ( [
32+ const [ chart , html , css , js ] = await Promise . all ( [
33+ fs . promises . readFile ( chartPath , 'utf8' ) ,
2634 fs . promises . readFile ( htmlPath , 'utf8' ) ,
2735 fs . promises . readFile ( cssPath , 'utf8' ) ,
2836 fs . promises . readFile ( jsPath , 'utf8' ) ,
@@ -35,8 +43,22 @@ async function main() {
3543 . replace ( / ' \{ \{ U P L O T _ C S S \} \} ' / , cssTag )
3644 . replace ( / ' \{ \{ U P L O T _ J S \} \} ' / , jsTag ) ;
3745
38- await fs . promises . writeFile ( htmlPathOut , replaced , 'utf8' ) ;
39- console . log ( 'uplot assets injected into uplot.html' ) ;
46+ // var chartReplaced = chart.replace(
47+ // '{{UPLOT_HTML}}',
48+ // replaced.replace(/`/g, '\\`'),
49+ // );
50+
51+ // const escapedHtmlForTemplate = replaced
52+ // .replace(/`/g, '\\`') // escape backticks
53+ // .replace(/\$\{/g, '\\${');
54+ // var chartReplaced = chart.replace('{{UPLOT_HTML}}', escapedHtmlForTemplate);
55+
56+ var chartReplaced = chart . replace ( "'UPLOT_HTML'" , JSON . stringify ( replaced ) ) ;
57+
58+ await fs . promises . writeFile ( chartPathOut , chartReplaced , 'utf8' ) ;
59+
60+ // await fs.promises.writeFile(htmlPathOut, replaced, 'utf8');
61+ // console.log('uplot assets injected into uplot.html');
4062 } catch ( err ) {
4163 console . error ( 'Error injecting uplot assets:' , err ) ;
4264 process . exit ( 1 ) ;
0 commit comments