diff --git a/src/commands/init.command.ts b/src/commands/init.command.ts index b967fbd..c292001 100644 --- a/src/commands/init.command.ts +++ b/src/commands/init.command.ts @@ -1,7 +1,7 @@ import { Command } from "@effect/cli" -import { Console, Effect } from "effect" -import { Command as RawCommand, FileSystem } from "@effect/platform" +import { FileSystem, Command as RawCommand } from "@effect/platform" import { NodeFileSystem } from "@effect/platform-node" +import { Console, Effect } from "effect" import { REGISTRY_URL } from "~/consts" @@ -61,7 +61,6 @@ export const initCommand = Command.make("init", {}, () => const patched = lines.join("\n") yield* fileSytem.writeFileString(cssPath, patched) - }).pipe( Effect.scoped, Effect.provide(NodeCommandExecutor.layer), diff --git a/src/commands/login.command.ts b/src/commands/login.command.ts index d297692..95d3519 100644 --- a/src/commands/login.command.ts +++ b/src/commands/login.command.ts @@ -44,11 +44,7 @@ const generateNanoid = Effect.sync(() => nanoid()) const openUrl = (urlToOpen: string) => { const openCommand = - process.platform === "darwin" - ? "open" - : process.platform === "win32" - ? "start" - : "xdg-open" + process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open" return Effect.try({ try: () => diff --git a/src/lib/app.ts b/src/lib/app.ts new file mode 100644 index 0000000..3560ea0 --- /dev/null +++ b/src/lib/app.ts @@ -0,0 +1,9 @@ +export const app = { + repo: { + base: "irsyadadl/intentui", + branch: "2.x", + get ui() { + return `https://raw.githubusercontent.com/${this.base}/${this.branch}/components/ui` + }, + }, +} diff --git a/src/lib/check-current-user-project.ts b/src/lib/check-current-user-project.ts new file mode 100644 index 0000000..b2b3fbc --- /dev/null +++ b/src/lib/check-current-user-project.ts @@ -0,0 +1,41 @@ +import * as FS from "node:fs/promises" +import * as Path from "node:path" + +async function exists(p: string): Promise { + try { + await FS.stat(p) + return true + } catch { + return false + } +} + +export async function isNextWithSrc(dir: string): Promise { + const srcDir = Path.join(dir, "src") + if (!(await exists(srcDir))) return false + const hasPages = await exists(Path.join(srcDir, "pages")) + const hasApp = await exists(Path.join(srcDir, "app")) + return hasPages || hasApp +} + +export async function isNextWithoutSrc(dir: string): Promise { + if (await exists(Path.join(dir, "src"))) return false + const hasPages = await exists(Path.join(dir, "pages")) + const hasApp = await exists(Path.join(dir, "app")) + return hasPages || hasApp +} + +export async function isRemix(dir: string): Promise { + const pkgPath = Path.join(dir, "package.json") + if (!(await exists(pkgPath))) return false + const pkg = JSON.parse(await FS.readFile(pkgPath, "utf-8")) + const deps = { ...pkg.dependencies, ...pkg.devDependencies } + if (!deps || !("remix" in deps)) return false + return await exists(Path.join(dir, "app")) +} + +export async function isLaravel(dir: string): Promise { + const hasArtisan = await exists(Path.join(dir, "artisan")) + const hasComposer = await exists(Path.join(dir, "composer.json")) + return hasArtisan && hasComposer +}