-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 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
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
32 changes: 32 additions & 0 deletions
32
packages/react-native-tailwind.macro/src/macro/resolve-tailwind-config.ts
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,32 @@ | ||
import resolveConfig from "tailwindcss/resolveConfig" | ||
import path from "path" | ||
import fs from "fs" | ||
|
||
const findConfigFilePath = (currentDir: string): string | null => { | ||
const files = fs.readdirSync(currentDir) | ||
|
||
const configFile = files.find((file) => file === "tailwind.config.js") | ||
|
||
if (configFile) return path.resolve(currentDir, configFile) | ||
|
||
// Check if package.json exists on this level, in which case we conclude that there is no config file | ||
const packageJson = files.find((file) => file === "package.json") | ||
if (packageJson) return null | ||
|
||
// Otherwise, recursively move upwards | ||
return findConfigFilePath(path.resolve(currentDir, "..")) | ||
} | ||
|
||
export const resolveTailwindConfig = (filePath: string | undefined | null) => { | ||
if (!filePath) return resolveConfig({ theme: {}, darkMode: "media" }) | ||
|
||
const configFilePath = fs.lstatSync(filePath).isDirectory() | ||
? findConfigFilePath(filePath) | ||
: findConfigFilePath(path.dirname(filePath)) | ||
|
||
const config = configFilePath | ||
? require(configFilePath) | ||
: { theme: {}, darkMode: "media" } | ||
|
||
return resolveConfig(config) | ||
} |