forked from wattanx/nuxt-pandacss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wattanx#8 from Shimpei-GANGAN/feat/add-csspath-nux…
…t-options feat: add 'cssPath' options for Nuxt module & add resolver
- Loading branch information
Showing
5 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@layer reset, base, tokens, recipes, utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { createResolver, useNuxt, resolvePath, addTemplate } from "nuxt/kit"; | ||
import type { ModuleOptions } from "./module"; | ||
import { existsSync } from "node:fs"; | ||
import { relative } from "node:path"; | ||
|
||
/** | ||
* | ||
* @param cssPath - ModuleOptions.cssPath | ||
* @param nuxt | ||
* @returns resolvedCSSPath | ||
* @returns loggerMessage | ||
* @example | ||
* ```ts | ||
* const { resolvedCSSPath, loggerMessage } = await resolveCSSPath('@/assets/css/global.css', nuxt); | ||
* ``` | ||
*/ | ||
export async function resolveCSSPath( | ||
cssPath: ModuleOptions["cssPath"], | ||
nuxt = useNuxt() | ||
): Promise<{ | ||
resolvedCSSPath: NonNullable<ModuleOptions["cssPath"]>; | ||
loggerMessage: string; | ||
}> { | ||
// if cssPath is string, find args.cssPath | ||
// else find cssPath from '@/assets/css/global.css' | ||
const resolvedCSSPath = | ||
typeof cssPath === "string" | ||
? await resolvePath(cssPath, { extensions: [".css"] }) | ||
: await resolvePath(`${nuxt.options.dir.assets}/css/global.css`, { | ||
extensions: [".css"], | ||
}); | ||
|
||
return existsSync(resolvedCSSPath) | ||
? { | ||
resolvedCSSPath, | ||
loggerMessage: `🐼 [info] Using Panda CSS file from @/${relative( | ||
nuxt.options.srcDir, | ||
resolvedCSSPath | ||
)}`, | ||
} | ||
: { | ||
resolvedCSSPath: createResolver(import.meta.url).resolve( | ||
addTemplate({ | ||
filename: "panda.css", | ||
write: true, | ||
getContents: () => | ||
"@layer reset, base, tokens, recipes, utilities;", | ||
}).dst | ||
), | ||
loggerMessage: "🐼 [info] Using default Panda CSS file.", | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters