@spark-ui/cli-utils 2.4.4 → 2.5.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.5.0](https://github.com/adevinta/spark/compare/@spark-ui/cli-utils@2.4.4...@spark-ui/cli-utils@2.5.0) (2023-03-09)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **cli-utils:** implement support for various base font sizes in theme building process ([7734203](https://github.com/adevinta/spark/commit/7734203330a411ba9c6898c6c1b4a84f6c168537)), closes [#385](https://github.com/adevinta/spark/issues/385)
|
|
11
|
+
|
|
6
12
|
## [2.4.4](https://github.com/adevinta/spark/compare/@spark-ui/cli-utils@2.4.3...@spark-ui/cli-utils@2.4.4) (2023-03-07)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @spark-ui/cli-utils
|
|
@@ -45,10 +45,10 @@ if (!configFileIsMJS) writeFileSync(jsFilePath, jsFileContents)
|
|
|
45
45
|
|
|
46
46
|
import(jsFilePath)
|
|
47
47
|
.then(module => {
|
|
48
|
-
const { tailwindThemeConfigPath, tailwindCSSPath, themes } = module.default
|
|
48
|
+
const { tailwindThemeConfigPath, tailwindCSSPath, themes, htmlFontSize = 16 } = module.default
|
|
49
49
|
|
|
50
50
|
createTailwindThemeConfigFile(tailwindThemeConfigPath)
|
|
51
|
-
createCSSTokensFile(tailwindCSSPath, themes)
|
|
51
|
+
createCSSTokensFile(tailwindCSSPath, themes, htmlFontSize)
|
|
52
52
|
|
|
53
53
|
const child = spawn(process.execPath, [jsFilePath], {
|
|
54
54
|
stdio: 'inherit',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-ui/cli-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Spark CLI utils",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@clack/prompts": "0.6.2",
|
|
16
|
-
"@spark-ui/theme-utils": "^2.
|
|
16
|
+
"@spark-ui/theme-utils": "^2.7.0",
|
|
17
17
|
"camel-case": "4.1.2",
|
|
18
18
|
"chalk": "5.2.0",
|
|
19
19
|
"commander": "10.0.0",
|
|
@@ -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": "62c4c8020794ee3ea0ffd34f30cf673a92f55570"
|
|
33
33
|
}
|
|
@@ -4,9 +4,16 @@ import { join } from 'node:path'
|
|
|
4
4
|
import hexRgb from 'hex-rgb'
|
|
5
5
|
|
|
6
6
|
import { DEFAULT_KEY } from './constants.js'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
doubleHyphensRegex,
|
|
9
|
+
getRemEquivalentValue,
|
|
10
|
+
isHex,
|
|
11
|
+
isObject,
|
|
12
|
+
isStringOrNumber,
|
|
13
|
+
toKebabCase,
|
|
14
|
+
} from './utils.js'
|
|
8
15
|
|
|
9
|
-
function toCSSVars(_theme, className) {
|
|
16
|
+
function toCSSVars(_theme, className, htmlFontSize) {
|
|
10
17
|
const flattenedTheme = {}
|
|
11
18
|
|
|
12
19
|
function flatten(theme, paths = []) {
|
|
@@ -23,6 +30,10 @@ function toCSSVars(_theme, className) {
|
|
|
23
30
|
return `${red} ${green} ${blue}`
|
|
24
31
|
}
|
|
25
32
|
|
|
33
|
+
if (/rem$/gi.test(value)) {
|
|
34
|
+
return getRemEquivalentValue(value, htmlFontSize)
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
return value
|
|
27
38
|
}
|
|
28
39
|
|
|
@@ -49,9 +60,9 @@ const toStringifiedTheme = theme =>
|
|
|
49
60
|
.map(([k, v]) => `${k}:${v}`)
|
|
50
61
|
.join(';')
|
|
51
62
|
|
|
52
|
-
const getStringifiedThemes = themeRecord =>
|
|
63
|
+
const getStringifiedThemes = (themeRecord, htmlFontSize) =>
|
|
53
64
|
Object.keys(themeRecord).map(key => {
|
|
54
|
-
const { className, ...rest } = toCSSVars(themeRecord[key], key)
|
|
65
|
+
const { className, ...rest } = toCSSVars(themeRecord[key], key, htmlFontSize)
|
|
55
66
|
|
|
56
67
|
return key === 'default'
|
|
57
68
|
? `:root{${toStringifiedTheme(rest)}}`
|
|
@@ -78,7 +89,7 @@ const getStringifiedThemes = themeRecord =>
|
|
|
78
89
|
*
|
|
79
90
|
* createCSSTokensFile('somePath.css', themes) // will generate a "somePath.css" file in the relative location from which it was called
|
|
80
91
|
*/
|
|
81
|
-
export function createCSSTokensFile(path, themeRecord) {
|
|
92
|
+
export function createCSSTokensFile(path, themeRecord, htmlFontSize) {
|
|
82
93
|
try {
|
|
83
94
|
appendFileSync(
|
|
84
95
|
join(process.cwd(), path),
|
|
@@ -86,7 +97,7 @@ export function createCSSTokensFile(path, themeRecord) {
|
|
|
86
97
|
@tailwind base;
|
|
87
98
|
@tailwind components;
|
|
88
99
|
@tailwind utilities;
|
|
89
|
-
@layer base {${getStringifiedThemes(themeRecord).join('')}}
|
|
100
|
+
@layer base {${getStringifiedThemes(themeRecord, htmlFontSize).join('')}}
|
|
90
101
|
`,
|
|
91
102
|
{
|
|
92
103
|
flag: 'w',
|
|
@@ -28,6 +28,13 @@ function hasNumber(value) {
|
|
|
28
28
|
return /\d/.test(value)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
function getRemEquivalentValue(remValue, htmlFontSize) {
|
|
32
|
+
const defaultBrowserBase = 16
|
|
33
|
+
const pxValue = parseFloat(remValue) * defaultBrowserBase
|
|
34
|
+
|
|
35
|
+
return `${pxValue / htmlFontSize}rem`
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
const doubleHyphensRegex = /(?<!var\()--+/g
|
|
32
39
|
|
|
33
40
|
export {
|
|
@@ -37,5 +44,6 @@ export {
|
|
|
37
44
|
isObject,
|
|
38
45
|
isCamelCase,
|
|
39
46
|
hasNumber,
|
|
47
|
+
getRemEquivalentValue,
|
|
40
48
|
doubleHyphensRegex,
|
|
41
49
|
}
|