Skip to content

Commit

Permalink
fix: fix theme command
Browse files Browse the repository at this point in the history
  • Loading branch information
irsyadadl committed Oct 14, 2024
1 parent 8da0408 commit 363f321
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'
import { checkbox } from '@inquirer/prompts'
import { components, namespaces } from '../resources/components'
import { getUtilsFolderPath, getWriteComponentPath, writeFile } from '../utils'
import { getUtilsFolderPath, getWriteComponentPath } from '../utils'
import chalk from 'chalk'
import { getPackageManager } from '../utils/get-package-manager'
import { additionalDeps } from '../utils/additional-deps'
Expand Down
8 changes: 6 additions & 2 deletions src/commands/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export async function theme(cssLocation: string): Promise<string | undefined> {
spinner.succeed(`CSS file copied to ${cssLocation}`)
return selectedTheme
} catch (error) {
// @ts-ignore
spinner.fail(`Failed to write CSS file to ${cssLocation}: ${error.message}`)
spinner.fail(`Failed to write CSS file to ${cssLocation}`)
}
} else {
spinner.warn(`Source CSS file does not exist at ${cssSourcePath}`)
Expand Down Expand Up @@ -89,6 +88,11 @@ export async function setTheme(overrideConfirmation: boolean, selectedTheme?: st
if (_newTheme) {
const newTheme = capitalize(_newTheme.replace('.css', ''))
userConfig.theme = newTheme

const cssSourcePath = path.join(resourceDir, `themes/${_newTheme}.css`)
const cssContent = readFileSync(cssSourcePath, 'utf8')
writeFileSync(cssPath, cssContent, { flag: 'w' })

userConfig.css = cssPath
writeFileSync(userConfigPath, JSON.stringify(userConfig, null, 2))
console.log(`Theme changed to '${newTheme}'`)
Expand Down
2 changes: 1 addition & 1 deletion src/resources/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const namespaces = [
'surfaces',
'media',
'colors',
'layouts'
'layouts',
]

const components: any[] = [
Expand Down
10 changes: 0 additions & 10 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,3 @@ export async function getCSSPath() {

return cssPath
}

export async function writeFile(description: string, url: string, writePath: string) {
try {
const response = await fetch(url)
const content = await response.text()
fs.writeFileSync(writePath, content)
} catch (error: any) {
console.error(chalk.red(`Error writing component to ${writePath}: ${error.message}`))
}
}

0 comments on commit 363f321

Please sign in to comment.