@@ -35,26 +35,29 @@ export const getConfigValue = <T>(value: T | undefined, defaultValue: T) => {
3535 return value
3636}
3737
38- const joinSpace = ( value : string , type ?: string , space = ' ' . repeat ( 4 ) ) => {
38+ const joinSpace = ( value : string , spaceNum : number , type ?: string ) => {
39+ const space = ' ' . repeat ( spaceNum )
40+
3941 if ( type !== 'all' ) {
4042 return value
4143 }
44+
4245 return space + value
4346}
4447
45- export const unquoteFromKeys = ( json : string , type ?: string ) => {
48+ export const unquoteFromKeys = ( json : string , type ?: string , spaceNum = 4 ) => {
4649 const result = json . replace ( / " ( \\ [ ^ ] | [ ^ \\ " ] ) * " \s * : ? / g, ( match ) => {
4750 if ( / [ 0 - 9 ] / . test ( match ) && / [ a - z A - Z ] / . test ( match ) ) {
4851 return match
4952 }
5053 if ( / : $ / . test ( match ) ) {
51- return joinSpace ( match . replace ( / ^ " | " (? = \s * : $ ) / g, '' ) , type )
54+ return joinSpace ( match . replace ( / ^ " | " (? = \s * : $ ) / g, '' ) , spaceNum , type )
5255 }
5356
5457 return match
5558 } )
5659
57- return result . replace ( / } / g, ( match ) => joinSpace ( match , type ) )
60+ return result . replace ( / } / g, ( match ) => joinSpace ( match , spaceNum , type ) )
5861}
5962
6063export const getTemplateConfigByType = (
@@ -66,8 +69,10 @@ export const getTemplateConfigByType = (
6669 plugins : string [ ]
6770) => {
6871 const extendTheme = extend
69- ? `theme: { extend: ${ unquoteFromKeys ( content , type ) } , },`
70- : `theme: ${ unquoteFromKeys ( content , type ) } ,`
72+ ? `theme: {
73+ extend: ${ unquoteFromKeys ( content , type , 4 ) } ,
74+ },`
75+ : `theme: ${ unquoteFromKeys ( content , type , 2 ) } ,`
7176
7277 const getTemplateConfig = ( ) => {
7378 let config = `{
@@ -77,15 +82,15 @@ export const getTemplateConfigByType = (
7782 ${ extendTheme } `
7883
7984 if ( plugins . length > 0 ) {
80- config += `\n plugins: [${ plugins } ]`
85+ config += `\n plugins: [${ plugins } ]`
8186 }
8287
8388 config += '\n}'
8489
8590 return config
8691 }
8792
88- const configs = `/** @type {import('tailwindcss').Config} */\n module .exports = ${ getTemplateConfig ( ) } `
93+ const configs = `/** @type {import('tailwindcss').Config} */\nmodule .exports = ${ getTemplateConfig ( ) } `
8994
9095 return configs
9196}
0 commit comments