@@ -336,6 +336,73 @@ async function main() {
336336 writeFile ( filePath , rawIconCssCodeBuffer ) ;
337337 } ) ;
338338 } ) ;
339+
340+ // Make sure icon css is imported before main css.
341+ // In the doc prior to first of june 2023, we instructed to import first the main css and then the icon css.
342+ // Since @gouvfr /dsfr@1.9.ish it has to be the opposite.
343+ // We auto correct the order here.
344+ reorder_css_imports: {
345+ const indexHtmlFilePath = ( ( ) => {
346+ let out = pathJoin ( cwd , "public" , "index.html" ) ;
347+
348+ if ( fs . existsSync ( out ) ) {
349+ return out ;
350+ }
351+
352+ out = pathJoin ( cwd , "index.html" ) ;
353+
354+ if ( fs . existsSync ( out ) ) {
355+ return out ;
356+ }
357+
358+ return undefined ;
359+ } ) ( ) ;
360+
361+ if ( indexHtmlFilePath === undefined ) {
362+ break reorder_css_imports;
363+ }
364+
365+ const indexHtml = fs . readFileSync ( indexHtmlFilePath ) . toString ( "utf8" ) ;
366+
367+ const lines = indexHtml . split ( "\n" ) ;
368+
369+ const importDsfrIndexLine = lines . findIndex ( line =>
370+ / < l i n k \s + r e l = " s t y l e s h e e t " \s + h r e f = " ( .* ?% P U B L I C _ U R L % ) ? \/ d s f r \/ d s f r .m i n .c s s " \s * \/ > / . test (
371+ line
372+ )
373+ ) ;
374+
375+ if ( importDsfrIndexLine === - 1 ) {
376+ break reorder_css_imports;
377+ }
378+
379+ if (
380+ ! / < l i n k \s + r e l = " s t y l e s h e e t " \s + h r e f = " ( % P U B L I C _ U R L % ) ? \/ d s f r \/ u t i l i t y \/ i c o n s \/ i c o n s \. m i n \. c s s " \s * \/ > / . test (
381+ lines [ importDsfrIndexLine + 1 ]
382+ )
383+ ) {
384+ break reorder_css_imports;
385+ }
386+
387+ fs . writeFileSync (
388+ indexHtmlFilePath ,
389+ Buffer . from (
390+ lines
391+ . map ( ( line , i ) => {
392+ switch ( i ) {
393+ case importDsfrIndexLine :
394+ return lines [ importDsfrIndexLine + 1 ] ;
395+ case importDsfrIndexLine + 1 :
396+ return lines [ importDsfrIndexLine ] ;
397+ default :
398+ return line ;
399+ }
400+ } )
401+ . join ( "\n" ) ,
402+ "utf8"
403+ )
404+ ) ;
405+ }
339406}
340407
341408if ( require . main === module ) {
0 commit comments