@spark-ui/cli-utils
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -6,2 +6,8 @@ # Change Log | ||
# [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) | ||
### Features | ||
- **cli-utils:** update cli setup-themes functions ([8723891](https://github.com/adevinta/spark/commit/8723891243a11a81176a3cdefe7fadf2951ce613)) | ||
# [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) | ||
@@ -8,0 +14,0 @@ |
{ | ||
"name": "@spark-ui/cli-utils", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Spark CLI utils", | ||
@@ -32,3 +32,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "f21e13f33295a0f0c73726c2f46732993bdf9d72" | ||
"gitHead": "53849c741f5ef573d7ef83218e1274145a22f8c8" | ||
} |
@@ -11,4 +11,32 @@ import { writeFileSync } from 'node:fs' | ||
/* eslint-disable complexity */ | ||
function flatten(obj, path) { | ||
Object.entries(obj).forEach(([key, value]) => { | ||
if (value !== null && typeof value === 'object' && !path && key === 'fontSize') { | ||
Object.keys(value).forEach(k => { | ||
if (isStringOrNumber(value[k])) { | ||
obj[key][k] = `var(--${toKebabCase(key)}-${k})` | ||
return | ||
} | ||
obj[key][k] = [ | ||
`var(--${toKebabCase(key)}-${k}-font-size`, | ||
{ | ||
...(value[k].lineHeight && { | ||
lineHeight: `var(--${toKebabCase(key)}-${k}-line-height`, | ||
}), | ||
...(value[k].letterSpacing && { | ||
letterSpacing: `var(--${toKebabCase(key)}-${k}-letter-spacing`, | ||
}), | ||
...(value[k].fontWeight && { | ||
fontWeight: `var(--${toKebabCase(key)}-${k}-font-weight`, | ||
}), | ||
}, | ||
] | ||
}) | ||
return | ||
} | ||
if (value !== null && typeof value === 'object') { | ||
@@ -23,9 +51,10 @@ const formattedPath = path ? `--${path}-${key}` : `--${key}` | ||
if (isStringOrNumber(value)) { | ||
const formattedPath = | ||
/--colors/.test(path || '') && isHex(value) | ||
? `rgb(var(${path}-${toKebabCase(key)}) / <alpha-value>)` | ||
: `var(${path}-${toKebabCase(key)})` | ||
const formattedValue = (() => { | ||
if (/--colors/.test(path || '') && isHex(value)) | ||
return `rgb(var(${path}-${toKebabCase(key)}) / <alpha-value>)` | ||
if (/--screens/.test(path || '')) return value | ||
return `var(${path}-${toKebabCase(key)})` | ||
})() | ||
/* @ts-ignore */ | ||
obj[key] = formattedPath | ||
obj[key] = formattedValue | ||
/* eslint-enable */ | ||
@@ -32,0 +61,0 @@ } |
@@ -19,8 +19,17 @@ function toKebabCase(v) { | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
function toKebabCaseKeys(obj, level = 1) { | ||
const result = {} | ||
for (const key in obj) { | ||
const value = typeof obj[key] === 'object' ? toKebabCaseKeys(obj[key], level + 1) : obj[key] | ||
result[level > 1 ? key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() : key] = value | ||
for (const [key, value] of Object.entries(obj)) { | ||
const transformedKey = | ||
level > 1 ? key.replace(/([a-z])([A-Z0-9])/g, '$1-$2').toLowerCase() : key | ||
if (Array.isArray(value)) { | ||
result[transformedKey] = value.map(v => | ||
typeof v === 'object' ? toKebabCaseKeys(v, level + 1) : v | ||
) | ||
} else if (typeof value === 'object') { | ||
result[transformedKey] = toKebabCaseKeys(value, level + 1) | ||
} else { | ||
result[transformedKey] = value | ||
} | ||
} | ||
@@ -27,0 +36,0 @@ |
31429
679