@@ -11,20 +11,19 @@ const CORE_CONFIG_IMPORT: ImportDeclarationStructure = {
1111
1212class CodeBuilder {
1313 private lines : string [ ] = [ ] ;
14- private depth = 0 ;
1514
16- addLine ( text : string ) : void {
17- this . lines . push ( `${ ' ' . repeat ( this . depth ) } ${ text } ` ) ;
15+ addLine ( text : string , depth = 0 ) : void {
16+ this . lines . push ( `${ ' ' . repeat ( depth ) } ${ text } ` ) ;
1817 }
1918
20- addEmptyLine ( ) : void {
21- this . lines . push ( '' ) ;
19+ addLines ( texts : string [ ] , depth = 0 ) : void {
20+ texts . forEach ( text => {
21+ this . addLine ( text , depth ) ;
22+ } ) ;
2223 }
2324
24- indent ( fn : ( ) => void ) : void {
25- this . depth ++ ;
26- fn ( ) ;
27- this . depth -- ;
25+ addEmptyLine ( ) : void {
26+ this . lines . push ( '' ) ;
2827 }
2928
3029 toString ( ) : string {
@@ -57,25 +56,19 @@ function collectImports(
5756export function generateConfigSource ( plugins : PluginCodegenResult [ ] ) : string {
5857 const builder = new CodeBuilder ( ) ;
5958
60- collectImports ( plugins ) . forEach ( declaration => {
61- builder . addLine ( formatImport ( declaration ) ) ;
62- } ) ;
63-
59+ builder . addLines ( collectImports ( plugins ) . map ( formatImport ) ) ;
6460 builder . addEmptyLine ( ) ;
6561 builder . addLine ( 'export default {' ) ;
66- builder . indent ( ( ) => {
67- if ( plugins . length === 0 ) {
68- builder . addLine ( 'plugins: [],' ) ;
69- } else {
70- builder . addLine ( 'plugins: [' ) ;
71- builder . indent ( ( ) => {
72- plugins . forEach ( ( { pluginInit } ) => {
73- builder . addLine ( `${ pluginInit } ,` ) ;
74- } ) ;
75- } ) ;
76- builder . addLine ( '],' ) ;
77- }
78- } ) ;
62+ if ( plugins . length === 0 ) {
63+ builder . addLine ( 'plugins: [],' , 1 ) ;
64+ } else {
65+ builder . addLine ( 'plugins: [' , 1 ) ;
66+ builder . addLines (
67+ plugins . map ( ( { pluginInit } ) => `${ pluginInit } ,` ) ,
68+ 2 ,
69+ ) ;
70+ builder . addLine ( '],' , 1 ) ;
71+ }
7972 builder . addLine ( '} satisfies CoreConfig;' ) ;
8073
8174 return builder . toString ( ) ;
0 commit comments