Skip to content

Commit

Permalink
[feature] Generate typed chakra ui theme config file in Typescript pr…
Browse files Browse the repository at this point in the history
…ojects
  • Loading branch information
Philzen committed Dec 29, 2024
1 parent a99bde0 commit 28de96e
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/cli/src/commands/setup/ui/libraries/chakra-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getPaths, writeFile } from '../../../../lib'
import c from '../../../../lib/colors'
import extendStorybookConfiguration from '../../../../lib/configureStorybook.js'
import { extendJSXFile, fileIncludes } from '../../../../lib/extendFile'
import { isTypeScriptProject } from '../../../../lib/project'

export const command = 'chakra-ui'
export const description = 'Set up Chakra UI'
Expand All @@ -29,9 +30,11 @@ export function builder(yargs) {
}

const CHAKRA_THEME_AND_COMMENTS = `\
import type { ChakraTheme, DeepPartial } from '@chakra-ui/react'
// This object will be used to override Chakra-UI theme defaults.
// See https://chakra-ui.com/docs/styled-system/theming/theme for theming options
const theme = {}
const theme: DeepPartial<ChakraTheme> = {}
export default theme
`

Expand Down Expand Up @@ -90,12 +93,22 @@ export async function handler({ force, install }) {
},
{
title: `Creating Theme File...`,
task: () => {
writeFile(
path.join(rwPaths.web.config, 'chakra.config.js'),
CHAKRA_THEME_AND_COMMENTS,
{ overwriteExisting: force },
task: async () => {
const ts = isTypeScriptProject()
const themeFilePath = path.join(
rwPaths.web.config,
`chakra.config.${ts ? 'ts' : 'js'}`,
)
writeFile(themeFilePath, CHAKRA_THEME_AND_COMMENTS, {
overwriteExisting: force,
})
if (ts === false) {
writeFile(
themeFilePath,
await transformTSToJS(themeFilePath, templateContent),
{ overwriteExisting: force },
)
}
},
},
{
Expand Down

0 comments on commit 28de96e

Please sign in to comment.