@spark-ui/cli-utils 2.0.7 → 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,18 @@
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
+
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)
13
+
14
+ ### Features
15
+
16
+ - **cli-utils:** flattened cli args for theme config ([ccb13de](https://github.com/adevinta/spark/commit/ccb13de785f2d6d2f8893bdff83b032af6416a38))
17
+
6
18
  ## [2.0.7](https://github.com/adevinta/spark/compare/@spark-ui/cli-utils@2.0.6...@spark-ui/cli-utils@2.0.7) (2023-02-24)
7
19
 
8
20
  ### Bug Fixes
@@ -45,10 +45,10 @@ if (!configFileIsMJS) writeFileSync(jsFilePath, jsFileContents)
45
45
 
46
46
  import(jsFilePath)
47
47
  .then(module => {
48
- const { tailwindThemeConfigFilePath, CSSTokens } = module.default
48
+ const { tailwindThemeConfigPath, tailwindCSSPath, themes } = module.default
49
49
 
50
- createTailwindThemeConfigFile(tailwindThemeConfigFilePath)
51
- createCSSTokensFile(CSSTokens.filePath, CSSTokens.themes)
50
+ createTailwindThemeConfigFile(tailwindThemeConfigPath)
51
+ createCSSTokensFile(tailwindCSSPath, themes)
52
52
 
53
53
  const child = spawn(process.execPath, [jsFilePath], {
54
54
  stdio: 'inherit',
@@ -59,14 +59,14 @@ import(jsFilePath)
59
59
  logger.success(
60
60
  `✨ Your Spark Tailwind theme config file has been successfully created: ${join(
61
61
  process.cwd(),
62
- tailwindThemeConfigFilePath
62
+ tailwindThemeConfigPath
63
63
  )}`
64
64
  )
65
65
 
66
66
  logger.success(
67
67
  `✨ Your Spark Tailwind CSS Tokens file file has been successfully created: ${join(
68
68
  process.cwd(),
69
- CSSTokens.filePath
69
+ tailwindCSSPath
70
70
  )}`
71
71
  )
72
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/cli-utils",
3
- "version": "2.0.7",
3
+ "version": "2.2.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.2.2",
16
- "@spark-ui/theme-utils": "^2.3.2",
16
+ "@spark-ui/theme-utils": "^2.4.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": "28fc0d6e70e1f90286d5ddbb5544952da0e786ad"
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 formattedPath =
23
- /--colors/.test(path || '') && isHex(value)
24
- ? `rgb(var(${path}-${toKebabCase(key)}) / <alpha-value>)`
25
- : `var(${path}-${toKebabCase(key)})`
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
- /* @ts-ignore */
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 in obj) {
23
- const value = typeof obj[key] === 'object' ? toKebabCaseKeys(obj[key], level + 1) : obj[key]
24
- result[level > 1 ? key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() : key] = value
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