mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
refractor: use script syntax in execa
This commit is contained in:
5
.changeset/clean-pandas-double.md
Normal file
5
.changeset/clean-pandas-double.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"create-better-t-stack": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
use script syntax in execa
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { confirm, select } from "@inquirer/prompts";
|
import { confirm, select } from "@inquirer/prompts";
|
||||||
import { execa } from "execa";
|
import { $ } from "execa";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import ora from "ora";
|
import ora from "ora";
|
||||||
import { setupTurso } from "./helpers/db-setup";
|
import { setupTurso } from "./helpers/db-setup";
|
||||||
@@ -17,11 +17,7 @@ export async function createProject(options: ProjectConfig) {
|
|||||||
spinner.succeed();
|
spinner.succeed();
|
||||||
|
|
||||||
spinner.start("Cloning template repository...");
|
spinner.start("Cloning template repository...");
|
||||||
await execa("npx", [
|
await $`npx degit https://github.com/AmanVarshney01/Better-T-Stack.git ${projectDir}`;
|
||||||
"degit",
|
|
||||||
"https://github.com/AmanVarshney01/Better-T-Stack.git",
|
|
||||||
projectDir,
|
|
||||||
]);
|
|
||||||
spinner.succeed();
|
spinner.succeed();
|
||||||
|
|
||||||
const initGit = await confirm({
|
const initGit = await confirm({
|
||||||
@@ -31,7 +27,7 @@ export async function createProject(options: ProjectConfig) {
|
|||||||
|
|
||||||
if (initGit) {
|
if (initGit) {
|
||||||
spinner.start("Initializing git repository...");
|
spinner.start("Initializing git repository...");
|
||||||
await execa("git", ["init"], { cwd: projectDir });
|
await $`git init ${projectDir}`;
|
||||||
spinner.succeed();
|
spinner.succeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,16 +65,16 @@ export async function createProject(options: ProjectConfig) {
|
|||||||
spinner.start(`Installing dependencies using ${packageManager}...`);
|
spinner.start(`Installing dependencies using ${packageManager}...`);
|
||||||
switch (packageManager) {
|
switch (packageManager) {
|
||||||
case "npm":
|
case "npm":
|
||||||
await execa("npm", ["install"], { cwd: projectDir });
|
await $`npm install ${projectDir}`;
|
||||||
break;
|
break;
|
||||||
case "yarn":
|
case "yarn":
|
||||||
await execa("yarn", ["install"], { cwd: projectDir });
|
await $`yarn install ${projectDir}`;
|
||||||
break;
|
break;
|
||||||
case "pnpm":
|
case "pnpm":
|
||||||
await execa("pnpm", ["install"], { cwd: projectDir });
|
await $`pnpm install ${projectDir}`;
|
||||||
break;
|
break;
|
||||||
case "bun":
|
case "bun":
|
||||||
await execa("bun", ["install"], { cwd: projectDir });
|
await $`bun install ${projectDir}`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("Unsupported package manager");
|
throw new Error("Unsupported package manager");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { confirm, input } from "@inquirer/prompts";
|
import { confirm, input } from "@inquirer/prompts";
|
||||||
import { execa } from "execa";
|
import { $ } from "execa";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import ora, { type Ora } from "ora";
|
import ora, { type Ora } from "ora";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
@@ -15,7 +15,7 @@ interface TursoConfig {
|
|||||||
async function loginToTurso(spinner: Ora) {
|
async function loginToTurso(spinner: Ora) {
|
||||||
try {
|
try {
|
||||||
spinner.start("Logging in to Turso...");
|
spinner.start("Logging in to Turso...");
|
||||||
await execa("turso", ["auth", "login"]);
|
await $`turso auth login`;
|
||||||
spinner.succeed("Logged in to Turso successfully!");
|
spinner.succeed("Logged in to Turso successfully!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail("Failed to log in to Turso");
|
spinner.fail("Failed to log in to Turso");
|
||||||
@@ -28,13 +28,11 @@ async function installTursoCLI(isMac: boolean, spinner: Ora) {
|
|||||||
spinner.start("Installing Turso CLI...");
|
spinner.start("Installing Turso CLI...");
|
||||||
|
|
||||||
if (isMac) {
|
if (isMac) {
|
||||||
await execa("brew", ["install", "tursodatabase/tap/turso"]);
|
await $`brew install tursodatabase/tap/turso`;
|
||||||
} else {
|
} else {
|
||||||
const { stdout: installScript } = await execa("curl", [
|
const { stdout: installScript } =
|
||||||
"-sSfL",
|
await $`curl -sSfL https://get.tur.so/install.sh`;
|
||||||
"https://get.tur.so/install.sh",
|
await $`bash -c '${installScript}'`;
|
||||||
]);
|
|
||||||
await execa("bash", [], { input: installScript });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spinner.succeed("Turso CLI installed successfully!");
|
spinner.succeed("Turso CLI installed successfully!");
|
||||||
@@ -51,7 +49,7 @@ async function installTursoCLI(isMac: boolean, spinner: Ora) {
|
|||||||
|
|
||||||
async function createTursoDatabase(dbName: string): Promise<TursoConfig> {
|
async function createTursoDatabase(dbName: string): Promise<TursoConfig> {
|
||||||
try {
|
try {
|
||||||
await execa("turso", ["db", "create", dbName]);
|
await $`turso db create ${dbName}`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error && error.message.includes("already exists")) {
|
if (error instanceof Error && error.message.includes("already exists")) {
|
||||||
throw new Error("DATABASE_EXISTS");
|
throw new Error("DATABASE_EXISTS");
|
||||||
@@ -59,19 +57,9 @@ async function createTursoDatabase(dbName: string): Promise<TursoConfig> {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { stdout: dbUrl } = await execa("turso", [
|
const { stdout: dbUrl } = await $`turso db show ${dbName} --url`;
|
||||||
"db",
|
|
||||||
"show",
|
|
||||||
dbName,
|
|
||||||
"--url",
|
|
||||||
]);
|
|
||||||
|
|
||||||
const { stdout: authToken } = await execa("turso", [
|
const { stdout: authToken } = await $`turso db tokens create ${dbName}`;
|
||||||
"db",
|
|
||||||
"tokens",
|
|
||||||
"create",
|
|
||||||
dbName,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dbUrl: dbUrl.trim(),
|
dbUrl: dbUrl.trim(),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { execa } from "execa";
|
import { $ } from "execa";
|
||||||
|
|
||||||
export async function isTursoInstalled() {
|
export async function isTursoInstalled() {
|
||||||
try {
|
try {
|
||||||
await execa("turso", ["--version"]);
|
await $`turso --version`;
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
@@ -11,7 +11,7 @@ export async function isTursoInstalled() {
|
|||||||
|
|
||||||
export async function isTursoLoggedIn() {
|
export async function isTursoLoggedIn() {
|
||||||
try {
|
try {
|
||||||
const output = await execa("turso", ["auth", "whoami"]);
|
const output = await $`turso auth whoami`;
|
||||||
return !output.stdout.includes("You are not logged in");
|
return !output.stdout.includes("You are not logged in");
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user