Skip to content

Commit 836ff3f

Browse files
authored
Merge pull request #353 from nado1001/fix/update-tailwind-config-format
Fix/update tailwind config format
2 parents 9f44ce0 + d352d73 commit 836ff3f

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

example/with-css-variables/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@types/react-dom": "18.2.18",
2020
"autoprefixer": "10.4.16",
2121
"postcss": "8.4.33",
22-
"sd-tailwindcss-transformer": "^1.4.1",
22+
"sd-tailwindcss-transformer": "^1.4.2",
2323
"style-dictionary": "3.9.1",
2424
"tailwindcss": "3.4.0",
2525
"typescript": "4.9.5"

example/with-css-variables/sd.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const sdConfig = makeSdTailwindConfig({
99
formatType: 'cjs',
1010
isVariables: true,
1111
prefix: PREFIX,
12+
extend: true,
1213
source: [`./style-dictionary/tokens/**/*.json`],
1314
transforms: ['attribute/cti', 'name/cti/kebab'],
1415
buildPath: `./`,

example/with-css-variables/styles/tailwind.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Do not edit directly
3-
* Generated on Wed, 15 Nov 2023 12:36:10 GMT
3+
* Generated on Sun, 07 Apr 2024 11:20:44 GMT
44
*/
55

66
:root {

example/with-css-variables/tailwind.config.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @type {import('tailwindcss').Config} */
2-
module.exports = {
2+
module.exports = {
33
mode: "jit",
44
content: ["./pages/**/*.{js,ts,jsx,tsx}","./components/**/*.{js,ts,jsx,tsx}"],
55
darkMode: "class",
@@ -36,5 +36,5 @@
3636
}
3737
},
3838
},
39-
plugins: [require("@tailwindcss/typography"),require("@tailwindcss/container-queries")]
39+
plugins: [require("@tailwindcss/typography"),require("@tailwindcss/container-queries")]
4040
}

example/with-css-variables/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,10 @@ scheduler@^0.23.0:
10971097
dependencies:
10981098
loose-envify "^1.1.0"
10991099

1100-
sd-tailwindcss-transformer@^1.4.1:
1101-
version "1.4.1"
1102-
resolved "https://registry.yarnpkg.com/sd-tailwindcss-transformer/-/sd-tailwindcss-transformer-1.4.1.tgz#40403243bdaee6b1c78a4d12cc59e2dea3f59075"
1103-
integrity sha512-g/CbF9vj9zZUGUsj7QrCLckCDLNhG0w+ppssmN+uT/u7FCUV9EPE42uwjVghNBrb0ggqxrZcVoc/4Kl+tqDeSQ==
1100+
sd-tailwindcss-transformer@^1.4.2:
1101+
version "1.4.2"
1102+
resolved "https://registry.yarnpkg.com/sd-tailwindcss-transformer/-/sd-tailwindcss-transformer-1.4.2.tgz#e27fe8875a7c4e932a1123235bab9577d0996a14"
1103+
integrity sha512-vFSahWFeQvxRtjYgcbJMd9s6ILYtAagx6nmFayZymPa7foHmaa8iaJ+63xlplcnI7P17G+9Ji7kofdbFfmDtGA==
11041104

11051105
sentence-case@^3.0.4:
11061106
version "3.0.4"

src/utils.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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-zA-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

6063
export 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

Comments
 (0)