Skip to content

Commit d99e161

Browse files
refractor: use script syntax in execa
1 parent 46b7989 commit d99e161

File tree

5 files changed

+26
-37
lines changed

5 files changed

+26
-37
lines changed

.changeset/clean-pandas-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-better-t-stack": patch
3+
---
4+
5+
use script syntax in execa

apps/cli/src/create-project.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22
import { confirm, select } from "@inquirer/prompts";
3-
import { execa } from "execa";
3+
import { $ } from "execa";
44
import fs from "fs-extra";
55
import ora from "ora";
66
import { setupTurso } from "./helpers/db-setup";
@@ -17,11 +17,7 @@ export async function createProject(options: ProjectConfig) {
1717
spinner.succeed();
1818

1919
spinner.start("Cloning template repository...");
20-
await execa("npx", [
21-
"degit",
22-
"https://github.com/AmanVarshney01/Better-T-Stack.git",
23-
projectDir,
24-
]);
20+
await $`npx degit https://github.com/AmanVarshney01/Better-T-Stack.git ${projectDir}`;
2521
spinner.succeed();
2622

2723
const initGit = await confirm({
@@ -31,7 +27,7 @@ export async function createProject(options: ProjectConfig) {
3127

3228
if (initGit) {
3329
spinner.start("Initializing git repository...");
34-
await execa("git", ["init"], { cwd: projectDir });
30+
await $`git init ${projectDir}`;
3531
spinner.succeed();
3632
}
3733

@@ -69,16 +65,16 @@ export async function createProject(options: ProjectConfig) {
6965
spinner.start(`Installing dependencies using ${packageManager}...`);
7066
switch (packageManager) {
7167
case "npm":
72-
await execa("npm", ["install"], { cwd: projectDir });
68+
await $`npm install ${projectDir}`;
7369
break;
7470
case "yarn":
75-
await execa("yarn", ["install"], { cwd: projectDir });
71+
await $`yarn install ${projectDir}`;
7672
break;
7773
case "pnpm":
78-
await execa("pnpm", ["install"], { cwd: projectDir });
74+
await $`pnpm install ${projectDir}`;
7975
break;
8076
case "bun":
81-
await execa("bun", ["install"], { cwd: projectDir });
77+
await $`bun install ${projectDir}`;
8278
break;
8379
default:
8480
throw new Error("Unsupported package manager");

apps/cli/src/helpers/db-setup.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os from "node:os";
22
import path from "node:path";
33
import { confirm, input } from "@inquirer/prompts";
4-
import { execa } from "execa";
4+
import { $ } from "execa";
55
import fs from "fs-extra";
66
import ora, { type Ora } from "ora";
77
import { logger } from "../utils/logger";
@@ -15,7 +15,7 @@ interface TursoConfig {
1515
async function loginToTurso(spinner: Ora) {
1616
try {
1717
spinner.start("Logging in to Turso...");
18-
await execa("turso", ["auth", "login"]);
18+
await $`turso auth login`;
1919
spinner.succeed("Logged in to Turso successfully!");
2020
} catch (error) {
2121
spinner.fail("Failed to log in to Turso");
@@ -28,13 +28,11 @@ async function installTursoCLI(isMac: boolean, spinner: Ora) {
2828
spinner.start("Installing Turso CLI...");
2929

3030
if (isMac) {
31-
await execa("brew", ["install", "tursodatabase/tap/turso"]);
31+
await $`brew install tursodatabase/tap/turso`;
3232
} else {
33-
const { stdout: installScript } = await execa("curl", [
34-
"-sSfL",
35-
"https://get.tur.so/install.sh",
36-
]);
37-
await execa("bash", [], { input: installScript });
33+
const { stdout: installScript } =
34+
await $`curl -sSfL https://get.tur.so/install.sh`;
35+
await $`bash -c '${installScript}'`;
3836
}
3937

4038
spinner.succeed("Turso CLI installed successfully!");
@@ -51,27 +49,17 @@ async function installTursoCLI(isMac: boolean, spinner: Ora) {
5149

5250
async function createTursoDatabase(dbName: string): Promise<TursoConfig> {
5351
try {
54-
await execa("turso", ["db", "create", dbName]);
52+
await $`turso db create ${dbName}`;
5553
} catch (error) {
5654
if (error instanceof Error && error.message.includes("already exists")) {
5755
throw new Error("DATABASE_EXISTS");
5856
}
5957
throw error;
6058
}
6159

62-
const { stdout: dbUrl } = await execa("turso", [
63-
"db",
64-
"show",
65-
dbName,
66-
"--url",
67-
]);
68-
69-
const { stdout: authToken } = await execa("turso", [
70-
"db",
71-
"tokens",
72-
"create",
73-
dbName,
74-
]);
60+
const { stdout: dbUrl } = await $`turso db show ${dbName} --url`;
61+
62+
const { stdout: authToken } = await $`turso db tokens create ${dbName}`;
7563

7664
return {
7765
dbUrl: dbUrl.trim(),

apps/cli/src/utils/turso-cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { execa } from "execa";
1+
import { $ } from "execa";
22

33
export async function isTursoInstalled() {
44
try {
5-
await execa("turso", ["--version"]);
5+
await $`turso --version`;
66
return true;
77
} catch {
88
return false;
@@ -11,7 +11,7 @@ export async function isTursoInstalled() {
1111

1212
export async function isTursoLoggedIn() {
1313
try {
14-
const output = await execa("turso", ["auth", "whoami"]);
14+
const output = await $`turso auth whoami`;
1515
return !output.stdout.includes("You are not logged in");
1616
} catch {
1717
return false;

bun.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"apps/cli": {
1616
"name": "create-better-t-stack",
17-
"version": "0.3.0",
17+
"version": "0.3.1",
1818
"bin": {
1919
"create-better-t-stack": "dist/index.js"
2020
},

0 commit comments

Comments
 (0)