refractor: use script syntax in execa

This commit is contained in:
Aman Varshney
2025-02-13 11:34:49 +05:30
parent 46b798971e
commit d99e161e40
5 changed files with 25 additions and 36 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": patch
---
use script syntax in execa

View File

@@ -1,6 +1,6 @@
import path from "node:path";
import { confirm, select } from "@inquirer/prompts";
import { execa } from "execa";
import { $ } from "execa";
import fs from "fs-extra";
import ora from "ora";
import { setupTurso } from "./helpers/db-setup";
@@ -17,11 +17,7 @@ export async function createProject(options: ProjectConfig) {
spinner.succeed();
spinner.start("Cloning template repository...");
await execa("npx", [
"degit",
"https://github.com/AmanVarshney01/Better-T-Stack.git",
projectDir,
]);
await $`npx degit https://github.com/AmanVarshney01/Better-T-Stack.git ${projectDir}`;
spinner.succeed();
const initGit = await confirm({
@@ -31,7 +27,7 @@ export async function createProject(options: ProjectConfig) {
if (initGit) {
spinner.start("Initializing git repository...");
await execa("git", ["init"], { cwd: projectDir });
await $`git init ${projectDir}`;
spinner.succeed();
}
@@ -69,16 +65,16 @@ export async function createProject(options: ProjectConfig) {
spinner.start(`Installing dependencies using ${packageManager}...`);
switch (packageManager) {
case "npm":
await execa("npm", ["install"], { cwd: projectDir });
await $`npm install ${projectDir}`;
break;
case "yarn":
await execa("yarn", ["install"], { cwd: projectDir });
await $`yarn install ${projectDir}`;
break;
case "pnpm":
await execa("pnpm", ["install"], { cwd: projectDir });
await $`pnpm install ${projectDir}`;
break;
case "bun":
await execa("bun", ["install"], { cwd: projectDir });
await $`bun install ${projectDir}`;
break;
default:
throw new Error("Unsupported package manager");

View File

@@ -1,7 +1,7 @@
import os from "node:os";
import path from "node:path";
import { confirm, input } from "@inquirer/prompts";
import { execa } from "execa";
import { $ } from "execa";
import fs from "fs-extra";
import ora, { type Ora } from "ora";
import { logger } from "../utils/logger";
@@ -15,7 +15,7 @@ interface TursoConfig {
async function loginToTurso(spinner: Ora) {
try {
spinner.start("Logging in to Turso...");
await execa("turso", ["auth", "login"]);
await $`turso auth login`;
spinner.succeed("Logged in to Turso successfully!");
} catch (error) {
spinner.fail("Failed to log in to Turso");
@@ -28,13 +28,11 @@ async function installTursoCLI(isMac: boolean, spinner: Ora) {
spinner.start("Installing Turso CLI...");
if (isMac) {
await execa("brew", ["install", "tursodatabase/tap/turso"]);
await $`brew install tursodatabase/tap/turso`;
} else {
const { stdout: installScript } = await execa("curl", [
"-sSfL",
"https://get.tur.so/install.sh",
]);
await execa("bash", [], { input: installScript });
const { stdout: installScript } =
await $`curl -sSfL https://get.tur.so/install.sh`;
await $`bash -c '${installScript}'`;
}
spinner.succeed("Turso CLI installed successfully!");
@@ -51,7 +49,7 @@ async function installTursoCLI(isMac: boolean, spinner: Ora) {
async function createTursoDatabase(dbName: string): Promise<TursoConfig> {
try {
await execa("turso", ["db", "create", dbName]);
await $`turso db create ${dbName}`;
} catch (error) {
if (error instanceof Error && error.message.includes("already exists")) {
throw new Error("DATABASE_EXISTS");
@@ -59,19 +57,9 @@ async function createTursoDatabase(dbName: string): Promise<TursoConfig> {
throw error;
}
const { stdout: dbUrl } = await execa("turso", [
"db",
"show",
dbName,
"--url",
]);
const { stdout: dbUrl } = await $`turso db show ${dbName} --url`;
const { stdout: authToken } = await execa("turso", [
"db",
"tokens",
"create",
dbName,
]);
const { stdout: authToken } = await $`turso db tokens create ${dbName}`;
return {
dbUrl: dbUrl.trim(),

View File

@@ -1,8 +1,8 @@
import { execa } from "execa";
import { $ } from "execa";
export async function isTursoInstalled() {
try {
await execa("turso", ["--version"]);
await $`turso --version`;
return true;
} catch {
return false;
@@ -11,7 +11,7 @@ export async function isTursoInstalled() {
export async function isTursoLoggedIn() {
try {
const output = await execa("turso", ["auth", "whoami"]);
const output = await $`turso auth whoami`;
return !output.stdout.includes("You are not logged in");
} catch {
return false;

View File

@@ -14,7 +14,7 @@
},
"apps/cli": {
"name": "create-better-t-stack",
"version": "0.3.0",
"version": "0.3.1",
"bin": {
"create-better-t-stack": "dist/index.js"
},