@spark-ui/cli-utils 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.2.0](https://github.com/adevinta/spark/compare/@spark-ui/cli-utils@2.1.0...@spark-ui/cli-utils@2.2.0) (2023-02-24)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **cli-utils:** update cli setup-themes functions ([8723891](https://github.com/adevinta/spark/commit/8723891243a11a81176a3cdefe7fadf2951ce613))
|
|
11
|
+
|
|
6
12
|
# [2.1.0](https://github.com/adevinta/spark/compare/@spark-ui/cli-utils@2.0.7...@spark-ui/cli-utils@2.1.0) (2023-02-24)
|
|
7
13
|
|
|
8
14
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-ui/cli-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Spark CLI utils",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"url": "git@github.com:adevinta/spark.git",
|
|
30
30
|
"directory": "packages/utils/cli"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "53849c741f5ef573d7ef83218e1274145a22f8c8"
|
|
33
33
|
}
|
|
@@ -8,8 +8,36 @@ import { isHex, isStringOrNumber, toKebabCase, toKebabCaseKeys } from '../../uti
|
|
|
8
8
|
function toTailwindConfig(theme) {
|
|
9
9
|
const themeCpy = JSON.parse(JSON.stringify(theme))
|
|
10
10
|
|
|
11
|
+
/* eslint-disable complexity */
|
|
11
12
|
function flatten(obj, path) {
|
|
12
13
|
Object.entries(obj).forEach(([key, value]) => {
|
|
14
|
+
if (value !== null && typeof value === 'object' && !path && key === 'fontSize') {
|
|
15
|
+
Object.keys(value).forEach(k => {
|
|
16
|
+
if (isStringOrNumber(value[k])) {
|
|
17
|
+
obj[key][k] = `var(--${toKebabCase(key)}-${k})`
|
|
18
|
+
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
obj[key][k] = [
|
|
23
|
+
`var(--${toKebabCase(key)}-${k}-font-size`,
|
|
24
|
+
{
|
|
25
|
+
...(value[k].lineHeight && {
|
|
26
|
+
lineHeight: `var(--${toKebabCase(key)}-${k}-line-height`,
|
|
27
|
+
}),
|
|
28
|
+
...(value[k].letterSpacing && {
|
|
29
|
+
letterSpacing: `var(--${toKebabCase(key)}-${k}-letter-spacing`,
|
|
30
|
+
}),
|
|
31
|
+
...(value[k].fontWeight && {
|
|
32
|
+
fontWeight: `var(--${toKebabCase(key)}-${k}-font-weight`,
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
]
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
13
41
|
if (value !== null && typeof value === 'object') {
|
|
14
42
|
const formattedPath = path ? `--${path}-${key}` : `--${key}`
|
|
15
43
|
flatten(value, toKebabCase(formattedPath.replace(/-{3,}/, '--')))
|
|
@@ -19,13 +47,14 @@ function toTailwindConfig(theme) {
|
|
|
19
47
|
|
|
20
48
|
/* eslint-disable */
|
|
21
49
|
if (isStringOrNumber(value)) {
|
|
22
|
-
const
|
|
23
|
-
/--colors/.test(path || '') && isHex(value)
|
|
24
|
-
|
|
25
|
-
|
|
50
|
+
const formattedValue = (() => {
|
|
51
|
+
if (/--colors/.test(path || '') && isHex(value))
|
|
52
|
+
return `rgb(var(${path}-${toKebabCase(key)}) / <alpha-value>)`
|
|
53
|
+
if (/--screens/.test(path || '')) return value
|
|
54
|
+
return `var(${path}-${toKebabCase(key)})`
|
|
55
|
+
})()
|
|
26
56
|
|
|
27
|
-
|
|
28
|
-
obj[key] = formattedPath
|
|
57
|
+
obj[key] = formattedValue
|
|
29
58
|
/* eslint-enable */
|
|
30
59
|
}
|
|
31
60
|
})
|
package/src/utils.js
CHANGED
|
@@ -16,12 +16,21 @@ function isStringOrNumber(value) {
|
|
|
16
16
|
return typeof value === 'string' || typeof value === 'number'
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
20
19
|
function toKebabCaseKeys(obj, level = 1) {
|
|
21
20
|
const result = {}
|
|
22
|
-
for (const key
|
|
23
|
-
const
|
|
24
|
-
|
|
21
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
22
|
+
const transformedKey =
|
|
23
|
+
level > 1 ? key.replace(/([a-z])([A-Z0-9])/g, '$1-$2').toLowerCase() : key
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
result[transformedKey] = value.map(v =>
|
|
27
|
+
typeof v === 'object' ? toKebabCaseKeys(v, level + 1) : v
|
|
28
|
+
)
|
|
29
|
+
} else if (typeof value === 'object') {
|
|
30
|
+
result[transformedKey] = toKebabCaseKeys(value, level + 1)
|
|
31
|
+
} else {
|
|
32
|
+
result[transformedKey] = value
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
return result
|