mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
bug fixes
This commit is contained in:
5
.changeset/tasty-points-kneel.md
Normal file
5
.changeset/tasty-points-kneel.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"create-better-t-stack": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
bug fixes
|
||||||
@@ -1,3 +1,12 @@
|
|||||||
{
|
{
|
||||||
"language_servers": ["typescript-language-server", "!vtsls", "biome", "..."]
|
"language_servers": ["typescript-language-server", "!vtsls", "biome", "..."],
|
||||||
|
"formatter": {
|
||||||
|
"language_server": {
|
||||||
|
"name": "biome"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"code_actions_on_format": {
|
||||||
|
"source.fixAll.biome": true,
|
||||||
|
"source.organizeImports.biome": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export async function createProject(options: ProjectConfig) {
|
|||||||
let shouldInstallDeps = false;
|
let shouldInstallDeps = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await tasks([
|
const tasksList = [
|
||||||
{
|
{
|
||||||
title: "Creating project directory",
|
title: "Creating project directory",
|
||||||
task: async () => {
|
task: async () => {
|
||||||
@@ -33,15 +33,22 @@ export async function createProject(options: ProjectConfig) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
];
|
||||||
|
|
||||||
|
if (options.git) {
|
||||||
|
tasksList.push({
|
||||||
title: "Initializing git repository",
|
title: "Initializing git repository",
|
||||||
task: async () => {
|
task: async () => {
|
||||||
if (options.git) {
|
|
||||||
await $`git init ${projectDir}`;
|
await $`git init ${projectDir}`;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await tasks(tasksList);
|
||||||
|
|
||||||
|
if (options.database === "libsql") {
|
||||||
|
await setupTurso(projectDir);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const installDepsResponse = await confirm({
|
const installDepsResponse = await confirm({
|
||||||
message: `📦 Install dependencies using ${options.packageManager}?`,
|
message: `📦 Install dependencies using ${options.packageManager}?`,
|
||||||
@@ -71,10 +78,6 @@ export async function createProject(options: ProjectConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.database === "libsql") {
|
|
||||||
await setupTurso(projectDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.success("✨ Project created successfully!\n");
|
log.success("✨ Project created successfully!\n");
|
||||||
log.info(chalk.dim("Next steps:"));
|
log.info(chalk.dim("Next steps:"));
|
||||||
log.info(` cd ${options.projectName}`);
|
log.info(` cd ${options.projectName}`);
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import * as p from "@clack/prompts";
|
import {
|
||||||
|
cancel,
|
||||||
|
confirm,
|
||||||
|
group,
|
||||||
|
intro,
|
||||||
|
isCancel,
|
||||||
|
log,
|
||||||
|
multiselect,
|
||||||
|
outro,
|
||||||
|
select,
|
||||||
|
spinner,
|
||||||
|
tasks,
|
||||||
|
text,
|
||||||
|
} from "@clack/prompts";
|
||||||
import { $ } from "execa";
|
import { $ } from "execa";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import { isTursoInstalled, isTursoLoggedIn } from "../utils/turso-cli";
|
import { isTursoInstalled, isTursoLoggedIn } from "../utils/turso-cli";
|
||||||
@@ -11,21 +24,21 @@ interface TursoConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loginToTurso() {
|
async function loginToTurso() {
|
||||||
const spinner = p.spinner();
|
const s = spinner();
|
||||||
try {
|
try {
|
||||||
spinner.start("Logging in to Turso...");
|
s.start("Logging in to Turso...");
|
||||||
await $`turso auth login`;
|
await $`turso auth login`;
|
||||||
spinner.stop("Logged in to Turso successfully!");
|
s.stop("Logged in to Turso successfully!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.stop("Failed to log in to Turso");
|
s.stop("Failed to log in to Turso");
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installTursoCLI(isMac: boolean) {
|
async function installTursoCLI(isMac: boolean) {
|
||||||
const spinner = p.spinner();
|
const s = spinner();
|
||||||
try {
|
try {
|
||||||
spinner.start("Installing Turso CLI...");
|
s.start("Installing Turso CLI...");
|
||||||
|
|
||||||
if (isMac) {
|
if (isMac) {
|
||||||
await $`brew install tursodatabase/tap/turso`;
|
await $`brew install tursodatabase/tap/turso`;
|
||||||
@@ -35,14 +48,14 @@ async function installTursoCLI(isMac: boolean) {
|
|||||||
await $`bash -c '${installScript}'`;
|
await $`bash -c '${installScript}'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
spinner.stop("Turso CLI installed successfully!");
|
s.stop("Turso CLI installed successfully!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error && error.message.includes("User force closed")) {
|
if (error instanceof Error && error.message.includes("User force closed")) {
|
||||||
spinner.stop();
|
s.stop();
|
||||||
p.log.warn("Turso CLI installation cancelled by user");
|
log.warn("Turso CLI installation cancelled by user");
|
||||||
throw new Error("Installation cancelled");
|
throw new Error("Installation cancelled");
|
||||||
}
|
}
|
||||||
spinner.stop("Failed to install Turso CLI");
|
s.stop("Failed to install Turso CLI");
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,42 +91,38 @@ TURSO_AUTH_TOKEN=`;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function displayManualSetupInstructions() {
|
function displayManualSetupInstructions() {
|
||||||
p.log.info("📝 Manual Turso Setup Instructions:");
|
log.info("📝 Manual Turso Setup Instructions:");
|
||||||
p.log.info("1. Visit https://turso.tech and create an account");
|
log.info("1. Visit https://turso.tech and create an account");
|
||||||
p.log.info("2. Create a new database from the dashboard");
|
log.info("2. Create a new database from the dashboard");
|
||||||
p.log.info("3. Get your database URL and authentication token");
|
log.info("3. Get your database URL and authentication token");
|
||||||
p.log.info(
|
log.info("4. Add these credentials to the .env file in packages/server/.env");
|
||||||
"4. Add these credentials to the .env file in packages/server/.env",
|
log.info("\nThe .env file has been created with placeholder variables:");
|
||||||
);
|
log.info("TURSO_DATABASE_URL=your_database_url");
|
||||||
p.log.info("\nThe .env file has been created with placeholder variables:");
|
log.info("TURSO_AUTH_TOKEN=your_auth_token");
|
||||||
p.log.info("TURSO_DATABASE_URL=your_database_url");
|
|
||||||
p.log.info("TURSO_AUTH_TOKEN=your_auth_token");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupTurso(projectDir: string) {
|
export async function setupTurso(projectDir: string) {
|
||||||
p.intro("Setting up Turso...");
|
|
||||||
|
|
||||||
const platform = os.platform();
|
const platform = os.platform();
|
||||||
const isMac = platform === "darwin";
|
const isMac = platform === "darwin";
|
||||||
const canInstallCLI = platform !== "win32";
|
const canInstallCLI = platform !== "win32";
|
||||||
|
|
||||||
try {
|
|
||||||
if (!canInstallCLI) {
|
if (!canInstallCLI) {
|
||||||
p.log.warn("Automatic Turso setup is not supported on Windows.");
|
log.warn("Automatic Turso setup is not supported on Windows.");
|
||||||
await writeEnvFile(projectDir);
|
await writeEnvFile(projectDir);
|
||||||
displayManualSetupInstructions();
|
displayManualSetupInstructions();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const isCliInstalled = await isTursoInstalled();
|
const isCliInstalled = await isTursoInstalled();
|
||||||
|
|
||||||
if (!isCliInstalled) {
|
if (!isCliInstalled) {
|
||||||
const shouldInstall = await p.confirm({
|
const shouldInstall = await confirm({
|
||||||
message: "Would you like to install Turso CLI?",
|
message: "Would you like to install Turso CLI?",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (p.isCancel(shouldInstall)) {
|
if (isCancel(shouldInstall)) {
|
||||||
p.cancel("Operation cancelled");
|
cancel("Operation cancelled");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,12 +132,34 @@ export async function setupTurso(projectDir: string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await installTursoCLI(isMac);
|
const s = spinner();
|
||||||
|
s.start("Installing Turso CLI...");
|
||||||
|
try {
|
||||||
|
if (isMac) {
|
||||||
|
await $`brew install tursodatabase/tap/turso`;
|
||||||
|
} else {
|
||||||
|
const { stdout: installScript } =
|
||||||
|
await $`curl -sSfL https://get.tur.so/install.sh`;
|
||||||
|
await $`bash -c '${installScript}'`;
|
||||||
|
}
|
||||||
|
s.stop("Turso CLI installed successfully!");
|
||||||
|
} catch (error) {
|
||||||
|
s.stop("Failed to install Turso CLI");
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLoggedIn = await isTursoLoggedIn();
|
const isLoggedIn = await isTursoLoggedIn();
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
await loginToTurso();
|
const s = spinner();
|
||||||
|
s.start("Logging in to Turso...");
|
||||||
|
try {
|
||||||
|
await $`turso auth login`;
|
||||||
|
s.stop("Logged in to Turso successfully!");
|
||||||
|
} catch (error) {
|
||||||
|
s.stop("Failed to log in to Turso");
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let success = false;
|
let success = false;
|
||||||
@@ -136,40 +167,38 @@ export async function setupTurso(projectDir: string) {
|
|||||||
let suggestedName = path.basename(projectDir);
|
let suggestedName = path.basename(projectDir);
|
||||||
|
|
||||||
while (!success) {
|
while (!success) {
|
||||||
const dbNameResponse = await p.text({
|
const dbNameResponse = await text({
|
||||||
message: "Enter database name:",
|
message: "Enter database name:",
|
||||||
defaultValue: suggestedName,
|
defaultValue: suggestedName,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (p.isCancel(dbNameResponse)) {
|
if (isCancel(dbNameResponse)) {
|
||||||
p.cancel("Operation cancelled");
|
cancel("Operation cancelled");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbName = dbNameResponse as string;
|
dbName = dbNameResponse as string;
|
||||||
const spinner = p.spinner();
|
const s = spinner();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
spinner.start(`Creating Turso database "${dbName}"...`);
|
s.start(`Creating Turso database "${dbName}"...`);
|
||||||
const config = await createTursoDatabase(dbName);
|
const config = await createTursoDatabase(dbName);
|
||||||
await writeEnvFile(projectDir, config);
|
await writeEnvFile(projectDir, config);
|
||||||
spinner.stop("Turso database configured successfully!");
|
s.stop("Turso database configured successfully!");
|
||||||
success = true;
|
success = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error && error.message === "DATABASE_EXISTS") {
|
if (error instanceof Error && error.message === "DATABASE_EXISTS") {
|
||||||
spinner.stop(`Database "${dbName}" already exists`);
|
s.stop(`Database "${dbName}" already exists`);
|
||||||
suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`;
|
suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`;
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.outro("Turso setup completed successfully!");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
p.log.error(`Error during Turso setup: ${error}`);
|
log.error(`Error during Turso setup: ${error}`);
|
||||||
await writeEnvFile(projectDir);
|
await writeEnvFile(projectDir);
|
||||||
displayManualSetupInstructions();
|
displayManualSetupInstructions();
|
||||||
p.outro("Setup completed with manual configuration required.");
|
outro("Setup completed with manual configuration required.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
confirm,
|
confirm,
|
||||||
group,
|
group,
|
||||||
intro,
|
intro,
|
||||||
|
log,
|
||||||
multiselect,
|
multiselect,
|
||||||
outro,
|
outro,
|
||||||
select,
|
select,
|
||||||
@@ -25,8 +26,7 @@ import { getUserPkgManager } from "./utils/get-package-manager";
|
|||||||
import { getVersion } from "./utils/get-version";
|
import { getVersion } from "./utils/get-version";
|
||||||
|
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
console.log("\n");
|
log.error("Operation cancelled");
|
||||||
chalk.red("Operation cancelled");
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -35,12 +35,15 @@ const program = new Command();
|
|||||||
async function gatherConfig(
|
async function gatherConfig(
|
||||||
flags: Partial<ProjectConfig>,
|
flags: Partial<ProjectConfig>,
|
||||||
): Promise<ProjectConfig> {
|
): Promise<ProjectConfig> {
|
||||||
const result = await group({
|
const shouldAskGit = flags.git !== false;
|
||||||
|
|
||||||
|
const result = await group(
|
||||||
|
{
|
||||||
projectName: () =>
|
projectName: () =>
|
||||||
text({
|
text({
|
||||||
message: "📝 Project name",
|
message: "📝 Project name",
|
||||||
placeholder: "my-better-t-app",
|
placeholder: "my-better-t-app",
|
||||||
defaultValue: flags.projectName || "my-better-t-app",
|
initialValue: flags.projectName,
|
||||||
validate: (value) => {
|
validate: (value) => {
|
||||||
if (!value) return "Project name is required";
|
if (!value) return "Project name is required";
|
||||||
},
|
},
|
||||||
@@ -92,6 +95,13 @@ async function gatherConfig(
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
: Promise.resolve(flags.features),
|
: Promise.resolve(flags.features),
|
||||||
|
git: () =>
|
||||||
|
shouldAskGit
|
||||||
|
? confirm({
|
||||||
|
message: "🗃️ Initialize Git repository?",
|
||||||
|
initialValue: true,
|
||||||
|
})
|
||||||
|
: Promise.resolve(false),
|
||||||
packageManager: async () => {
|
packageManager: async () => {
|
||||||
const detectedPackageManager = getUserPkgManager();
|
const detectedPackageManager = getUserPkgManager();
|
||||||
|
|
||||||
@@ -106,9 +116,9 @@ async function gatherConfig(
|
|||||||
options: [
|
options: [
|
||||||
{ value: "npm", label: "npm", hint: "Node Package Manager" },
|
{ value: "npm", label: "npm", hint: "Node Package Manager" },
|
||||||
{
|
{
|
||||||
value: "yarn",
|
value: "bun",
|
||||||
label: "yarn",
|
label: "bun",
|
||||||
hint: "Fast, reliable, and secure dependency management",
|
hint: "All-in-one JavaScript runtime & toolkit (recommended)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "pnpm",
|
value: "pnpm",
|
||||||
@@ -116,21 +126,28 @@ async function gatherConfig(
|
|||||||
hint: "Fast, disk space efficient package manager",
|
hint: "Fast, disk space efficient package manager",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "bun",
|
value: "yarn",
|
||||||
label: "bun",
|
label: "yarn",
|
||||||
hint: "All-in-one JavaScript runtime & toolkit",
|
hint: "Fast, reliable, and secure dependency management",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
onCancel: () => {
|
||||||
|
cancel("Operation cancelled.");
|
||||||
|
process.exit(0);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
projectName: result.projectName as string,
|
projectName: result.projectName as string,
|
||||||
database: (result.database as ProjectDatabase) ?? "libsql",
|
database: (result.database as ProjectDatabase) ?? "libsql",
|
||||||
auth: (result.auth as boolean) ?? true,
|
auth: (result.auth as boolean) ?? true,
|
||||||
features: (result.features as ProjectFeature[]) ?? [],
|
features: (result.features as ProjectFeature[]) ?? [],
|
||||||
git: flags.git ?? true,
|
git: (result.git as boolean) ?? true,
|
||||||
packageManager: (result.packageManager as PackageManager) ?? "npm",
|
packageManager: (result.packageManager as PackageManager) ?? "npm",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -203,43 +220,27 @@ async function main() {
|
|||||||
git: chalk.cyan(config.git),
|
git: chalk.cyan(config.git),
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log();
|
log.message(
|
||||||
console.log(
|
`${chalk.blue("Project Name: ")}${
|
||||||
chalk.dim("├─") +
|
colorizedConfig.projectName
|
||||||
chalk.blue(" Project Name: ") +
|
}\n${chalk.blue("Database: ")}${colorizedConfig.database}\n${chalk.blue(
|
||||||
colorizedConfig.projectName,
|
"Authentication: ",
|
||||||
);
|
)}${colorizedConfig.auth}\n${chalk.blue("Features: ")}${
|
||||||
console.log(
|
colorizedConfig.features.length
|
||||||
chalk.dim("├─") + chalk.blue(" Database: ") + colorizedConfig.database,
|
|
||||||
);
|
|
||||||
console.log(
|
|
||||||
chalk.dim("├─") +
|
|
||||||
chalk.blue(" Authentication: ") +
|
|
||||||
colorizedConfig.auth,
|
|
||||||
);
|
|
||||||
console.log(
|
|
||||||
chalk.dim("├─") +
|
|
||||||
chalk.blue(" Features: ") +
|
|
||||||
(colorizedConfig.features.length
|
|
||||||
? colorizedConfig.features.join(", ")
|
? colorizedConfig.features.join(", ")
|
||||||
: chalk.gray("none")),
|
: chalk.gray("none")
|
||||||
|
}\n${chalk.blue("Git Init: ")}${colorizedConfig.git}\n`,
|
||||||
);
|
);
|
||||||
console.log(
|
|
||||||
chalk.dim("└─") + chalk.blue(" Git Init: ") + colorizedConfig.git,
|
|
||||||
);
|
|
||||||
console.log();
|
|
||||||
s.stop("Configuration loaded");
|
s.stop("Configuration loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
await createProject(config);
|
await createProject(config);
|
||||||
|
|
||||||
console.log();
|
log.message("You can reproduce this setup with the following command:", {
|
||||||
console.log(
|
symbol: chalk.cyan("🔄"),
|
||||||
chalk.dim("🔄 You can reproduce this setup with the following command:"),
|
});
|
||||||
);
|
log.info(generateReproducibleCommand(config));
|
||||||
console.log();
|
|
||||||
console.log(chalk.dim(" ") + generateReproducibleCommand(config));
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
outro("Project created successfully! 🎉");
|
outro("Project created successfully! 🎉");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user