Skip to content

Commit

Permalink
fix: fix theme switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
irsyadadl committed Nov 1, 2024
1 parent dc2cce6 commit 60c8e3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/commands/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ora from "ora"
import { confirm, select } from "@inquirer/prompts"
import { resourceDir } from "./init"
import { getCSSPath } from "@/utils"
import { capitalize } from "@/utils/helpers"
import { capitalize, justdConfigFile, possibilityCssPath } from "@/utils/helpers"

export async function theme(cssLocation: string): Promise<string | undefined> {
const themes = [
Expand Down Expand Up @@ -67,8 +67,11 @@ export async function setTheme(overrideConfirmation: boolean, selectedTheme?: st
const userConfig = JSON.parse(readFileSync(userConfigPath, "utf8"))

const currentTheme = userConfig.theme || "default"

const cssPath = await getCSSPath()
const config = JSON.parse(fs.readFileSync(justdConfigFile, "utf8"))
let cssPath = config.css || possibilityCssPath()
if (!overrideConfirmation) {
cssPath = await getCSSPath()
}

let confirmOverride = true

Expand All @@ -89,7 +92,7 @@ export async function setTheme(overrideConfirmation: boolean, selectedTheme?: st
const newTheme = capitalize(_newTheme.replace(".css", ""))
userConfig.theme = newTheme

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

Expand Down
2 changes: 2 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ export function getAliasFromConfig() {
const config = JSON.parse(fs.readFileSync(configFilePath, "utf-8"))
return config.alias
}

export const justdConfigFile = path.resolve(process.cwd(), "justd.json")
4 changes: 2 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { confirm, input } from "@inquirer/prompts"
import fs from "fs"
import path from "path"
import { possibilityCssPath, possibilityUtilsPath } from "@/utils/helpers"
import { justdConfigFile, possibilityCssPath, possibilityUtilsPath } from "@/utils/helpers"

// This function is used to get the write path for a component
export function getWriteComponentPath(componentName: string) {
Expand Down Expand Up @@ -40,7 +40,7 @@ export function getUtilsFolderPath() {

// Get the path to the CSS file from the justd.json file
export async function getCSSPath() {
const configFile = "justd.json"
const configFile = justdConfigFile

if (!fs.existsSync(configFile)) {
throw new Error("Configuration file justd.json not found. Please run the init command first.")
Expand Down

0 comments on commit 60c8e3e

Please sign in to comment.