From 60c8e3ed00fa879c87b5a975538a66473e2268c8 Mon Sep 17 00:00:00 2001 From: "Irsyad A. Panjaitan" Date: Fri, 1 Nov 2024 20:34:07 +0700 Subject: [PATCH] fix: fix theme switcher --- src/commands/theme.ts | 11 +++++++---- src/utils/helpers.ts | 2 ++ src/utils/index.ts | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/commands/theme.ts b/src/commands/theme.ts index 952ae69..6426834 100644 --- a/src/commands/theme.ts +++ b/src/commands/theme.ts @@ -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 { const themes = [ @@ -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 @@ -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" }) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 7e25f06..eeb798b 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -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") diff --git a/src/utils/index.ts b/src/utils/index.ts index bd038c7..c7dc1b3 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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) { @@ -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.")