diff --git a/src/commands/add.ts b/src/commands/add.ts index 18cf212..a8d69d3 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -165,7 +165,7 @@ export async function add(options: any) { const responseClasses = await fetch(getUtilsFolder("classes.ts")) const fileContentClasses = await responseClasses.text() - writeCodeFile(config, { + await writeCodeFile(config, { ogFilename: "classes.ts", writePath: classesFile, content: fileContentClasses, @@ -191,7 +191,7 @@ export async function add(options: any) { const responseMediaQuery = await fetch(getUtilsFolder("use-media-query.ts")) const fileContentMediaQuery = await responseMediaQuery.text() - writeCodeFile(config, { + await writeCodeFile(config, { ogFilename: "use-media-query.ts", writePath: mediaQueryFile, content: fileContentMediaQuery, @@ -371,7 +371,7 @@ async function createComponent(config: Config, componentName: string) { const content = await response.text() - writeCodeFile(config, { writePath, ogFilename: `${componentName}.tsx`, content }) + await writeCodeFile(config, { writePath, ogFilename: `${componentName}.tsx`, content }) } catch (err) { console.log(err) error(`Error writing component: ${componentName}`) diff --git a/src/commands/init.ts b/src/commands/init.ts index 2eb3f41..6836be4 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -297,7 +297,7 @@ export async function init(flags: { force?: boolean; yes?: boolean }) { const fileContent = await response.text() - writeCodeFile(createdConfig, { + await writeCodeFile(createdConfig, { writePath: path.join(uiFolder, "primitive.tsx"), ogFilename: "primitive.tsx", content: fileContent, @@ -312,7 +312,7 @@ export async function init(flags: { force?: boolean; yes?: boolean }) { const responseClasses = await fetch(getUtilsFolder("classes.ts")) const fileContentClasses = await responseClasses.text() - writeCodeFile(createdConfig, { + await writeCodeFile(createdConfig, { writePath: path.join(utilsFolder, "classes.ts"), ogFilename: "classes.ts", content: fileContentClasses, @@ -321,7 +321,7 @@ export async function init(flags: { force?: boolean; yes?: boolean }) { if (themeProvider) { const themeProviderContent = fs.readFileSync(themeProvider, "utf8") - writeCodeFile(createdConfig, { + await writeCodeFile(createdConfig, { ogFilename: "theme-provider.tsx", writePath: path.join(componentFolder, "theme-provider.tsx"), content: themeProviderContent, @@ -330,7 +330,7 @@ export async function init(flags: { force?: boolean; yes?: boolean }) { if (providers) { const providersContent = fs.readFileSync(providers, "utf8") - writeCodeFile(createdConfig, { + await writeCodeFile(createdConfig, { ogFilename: "providers.tsx", writePath: path.join(componentFolder, "providers.tsx"), content: providersContent, diff --git a/src/utils/index.ts b/src/utils/index.ts index 447e392..432e51b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -12,8 +12,6 @@ import { confirm, input } from "@inquirer/prompts" import stripJsonComments from "strip-json-comments" import { type Config, configManager } from "./config" -import oxc from "oxc-transform" - // Get the path to the CSS file from the justd.json file export async function getCSSPath() { const doesConfigExist = configManager.doesConfigExist() @@ -82,7 +80,7 @@ export async function addUiPathToTsConfig() { } } -export const writeCodeFile = ( +export const writeCodeFile = async ( config: Config, options: { writePath: string; ogFilename: string; content: string }, ) => { @@ -107,6 +105,8 @@ export const writeCodeFile = ( parsedContent = parsedContent.replace(/@\/utils\/classes/g, `@/${utils}/classes`) if (config.language === "javascript") { + const oxc = await import("oxc-transform") + const { code: transformedCode } = oxc.transform(options.ogFilename, parsedContent, { sourcemap: false, jsx: "preserve",