|
| 1 | +import * as FS from "node:fs/promises" |
| 2 | +import * as Path from "node:path" |
| 3 | + |
| 4 | +async function exists(p: string): Promise<boolean> { |
| 5 | + try { |
| 6 | + await FS.stat(p) |
| 7 | + return true |
| 8 | + } catch { |
| 9 | + return false |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +export async function isNextWithSrc(dir: string): Promise<boolean> { |
| 14 | + const srcDir = Path.join(dir, "src") |
| 15 | + if (!(await exists(srcDir))) return false |
| 16 | + const hasPages = await exists(Path.join(srcDir, "pages")) |
| 17 | + const hasApp = await exists(Path.join(srcDir, "app")) |
| 18 | + return hasPages || hasApp |
| 19 | +} |
| 20 | + |
| 21 | +export async function isNextWithoutSrc(dir: string): Promise<boolean> { |
| 22 | + if (await exists(Path.join(dir, "src"))) return false |
| 23 | + const hasPages = await exists(Path.join(dir, "pages")) |
| 24 | + const hasApp = await exists(Path.join(dir, "app")) |
| 25 | + return hasPages || hasApp |
| 26 | +} |
| 27 | + |
| 28 | +export async function isRemix(dir: string): Promise<boolean> { |
| 29 | + const pkgPath = Path.join(dir, "package.json") |
| 30 | + if (!(await exists(pkgPath))) return false |
| 31 | + const pkg = JSON.parse(await FS.readFile(pkgPath, "utf-8")) |
| 32 | + const deps = { ...pkg.dependencies, ...pkg.devDependencies } |
| 33 | + if (!deps || !("remix" in deps)) return false |
| 34 | + return await exists(Path.join(dir, "app")) |
| 35 | +} |
| 36 | + |
| 37 | +export async function isLaravel(dir: string): Promise<boolean> { |
| 38 | + const hasArtisan = await exists(Path.join(dir, "artisan")) |
| 39 | + const hasComposer = await exists(Path.join(dir, "composer.json")) |
| 40 | + return hasArtisan && hasComposer |
| 41 | +} |
0 commit comments