@@ -35,26 +35,29 @@ export const getConfigValue = <T>(value: T | undefined, defaultValue: T) => {
35
35
return value
36
36
}
37
37
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
+
39
41
if ( type !== 'all' ) {
40
42
return value
41
43
}
44
+
42
45
return space + value
43
46
}
44
47
45
- export const unquoteFromKeys = ( json : string , type ?: string ) => {
48
+ export const unquoteFromKeys = ( json : string , type ?: string , spaceNum = 4 ) => {
46
49
const result = json . replace ( / " ( \\ [ ^ ] | [ ^ \\ " ] ) * " \s * : ? / g, ( match ) => {
47
50
if ( / [ 0 - 9 ] / . test ( match ) && / [ a - z A - Z ] / . test ( match ) ) {
48
51
return match
49
52
}
50
53
if ( / : $ / . test ( match ) ) {
51
- return joinSpace ( match . replace ( / ^ " | " (? = \s * : $ ) / g, '' ) , type )
54
+ return joinSpace ( match . replace ( / ^ " | " (? = \s * : $ ) / g, '' ) , spaceNum , type )
52
55
}
53
56
54
57
return match
55
58
} )
56
59
57
- return result . replace ( / } / g, ( match ) => joinSpace ( match , type ) )
60
+ return result . replace ( / } / g, ( match ) => joinSpace ( match , spaceNum , type ) )
58
61
}
59
62
60
63
export const getTemplateConfigByType = (
@@ -66,8 +69,10 @@ export const getTemplateConfigByType = (
66
69
plugins : string [ ]
67
70
) => {
68
71
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 ) } ,`
71
76
72
77
const getTemplateConfig = ( ) => {
73
78
let config = `{
@@ -77,15 +82,15 @@ export const getTemplateConfigByType = (
77
82
${ extendTheme } `
78
83
79
84
if ( plugins . length > 0 ) {
80
- config += `\n plugins: [${ plugins } ]`
85
+ config += `\n plugins: [${ plugins } ]`
81
86
}
82
87
83
88
config += '\n}'
84
89
85
90
return config
86
91
}
87
92
88
- const configs = `/** @type {import('tailwindcss').Config} */\n module .exports = ${ getTemplateConfig ( ) } `
93
+ const configs = `/** @type {import('tailwindcss').Config} */\nmodule .exports = ${ getTemplateConfig ( ) } `
89
94
90
95
return configs
91
96
}
0 commit comments