replace chalk with picocolors

This commit is contained in:
Aman Varshney
2025-02-15 03:29:32 +05:30
parent 75d6255d21
commit f98216e642
8 changed files with 76 additions and 80 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": minor
---
replace chalk with picocolors

View File

@@ -19,12 +19,12 @@
"files": ["dist", "templates"], "files": ["dist", "templates"],
"dependencies": { "dependencies": {
"@clack/prompts": "^0.10.0", "@clack/prompts": "^0.10.0",
"chalk": "^5.3.0",
"commander": "^13.1.0", "commander": "^13.1.0",
"degit": "^2.8.4", "degit": "^2.8.4",
"execa": "^8.0.1", "execa": "^8.0.1",
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",
"gradient-string": "^3.0.0" "gradient-string": "^3.0.0",
"picocolors": "^1.1.1"
}, },
"devDependencies": { "devDependencies": {
"@types/degit": "^2.8.6", "@types/degit": "^2.8.6",

View File

@@ -1,9 +1,9 @@
import path from "node:path"; import path from "node:path";
import { cancel, confirm, isCancel, log, spinner, tasks } from "@clack/prompts"; import { cancel, confirm, isCancel, log, spinner, tasks } from "@clack/prompts";
import chalk from "chalk";
import degit from "degit"; import degit from "degit";
import { $ } from "execa"; import { $ } from "execa";
import fs from "fs-extra"; import fs from "fs-extra";
import pc from "picocolors";
import type { ProjectConfig } from "../types"; import type { ProjectConfig } from "../types";
import { setupTurso } from "./db-setup"; import { setupTurso } from "./db-setup";
@@ -29,9 +29,9 @@ export async function createProject(options: ProjectConfig) {
}); });
await emitter.clone(projectDir); await emitter.clone(projectDir);
} catch (error) { } catch (error) {
log.error("Failed to clone template repository"); log.error(pc.red("Failed to clone template repository"));
if (error instanceof Error) { if (error instanceof Error) {
log.error(error.message); log.error(pc.red(error.message));
} }
throw error; throw error;
} }
@@ -57,39 +57,41 @@ export async function createProject(options: ProjectConfig) {
} }
const installDepsResponse = await confirm({ const installDepsResponse = await confirm({
message: `📦 Install dependencies with ${options.packageManager}?`, message: `📦 Install dependencies with ${pc.magenta(options.packageManager)}?`,
}); });
if (isCancel(installDepsResponse)) { if (isCancel(installDepsResponse)) {
cancel("Operation cancelled"); cancel(pc.red("Operation cancelled"));
process.exit(0); process.exit(0);
} }
shouldInstallDeps = installDepsResponse; shouldInstallDeps = installDepsResponse;
if (shouldInstallDeps) { if (shouldInstallDeps) {
s.start(`📦 Installing dependencies using ${options.packageManager}...`); s.start(
`📦 Installing dependencies using ${pc.magenta(options.packageManager)}...`,
);
try { try {
await $({ await $({
cwd: projectDir, cwd: projectDir,
})`${options.packageManager} install`; })`${options.packageManager} install`;
s.stop("✅ Dependencies installed successfully"); s.stop("✅ Dependencies installed successfully");
} catch (error) { } catch (error) {
s.stop("Failed to install dependencies"); s.stop(pc.red("Failed to install dependencies"));
if (error instanceof Error) { if (error instanceof Error) {
log.error(`Installation error: ${error.message}`); log.error(pc.red(`Installation error: ${error.message}`));
} }
throw error; throw error;
} }
} }
log.info(`${chalk.dim("Next steps:")} log.info(`${pc.dim("Next steps:")}
cd ${options.projectName}${!shouldInstallDeps ? `\n${options.packageManager} install` : ""} ${pc.cyan("cd")} ${options.projectName}${!shouldInstallDeps ? `\n${pc.cyan(options.packageManager)} install` : ""}
${options.packageManager === "npm" ? "npm run" : options.packageManager} dev`); ${pc.cyan(options.packageManager === "npm" ? "npm run" : options.packageManager)} ${"dev"}`);
} catch (error) { } catch (error) {
s.stop("Failed"); s.stop(pc.red("Failed"));
if (error instanceof Error) { if (error instanceof Error) {
log.error(`Error during project creation: ${error.message}`); log.error(pc.red(`Error during project creation: ${error.message}`));
process.exit(1); process.exit(1);
} }
} }

View File

@@ -3,19 +3,15 @@ import path from "node:path";
import { import {
cancel, cancel,
confirm, confirm,
group,
intro,
isCancel, isCancel,
log, log,
multiselect,
outro, outro,
select,
spinner, spinner,
tasks,
text, text,
} from "@clack/prompts"; } from "@clack/prompts";
import { $ } from "execa"; import { $ } from "execa";
import fs from "fs-extra"; import fs from "fs-extra";
import pc from "picocolors";
import { isTursoInstalled, isTursoLoggedIn } from "../utils/turso-cli"; import { isTursoInstalled, isTursoLoggedIn } from "../utils/turso-cli";
interface TursoConfig { interface TursoConfig {
@@ -30,7 +26,7 @@ async function loginToTurso() {
await $`turso auth login`; await $`turso auth login`;
s.stop("✅ Logged in to Turso successfully!"); s.stop("✅ Logged in to Turso successfully!");
} catch (error) { } catch (error) {
s.stop("Failed to log in to Turso"); s.stop(pc.red("Failed to log in to Turso"));
throw error; throw error;
} }
} }
@@ -52,10 +48,10 @@ async function installTursoCLI(isMac: boolean) {
} catch (error) { } catch (error) {
if (error instanceof Error && error.message.includes("User force closed")) { if (error instanceof Error && error.message.includes("User force closed")) {
s.stop(); s.stop();
log.warn("Turso CLI installation cancelled by user"); log.warn(pc.yellow("Turso CLI installation cancelled by user"));
throw new Error("Installation cancelled"); throw new Error("Installation cancelled");
} }
s.stop("Failed to install Turso CLI"); s.stop(pc.red("Failed to install Turso CLI"));
throw error; throw error;
} }
} }
@@ -91,14 +87,15 @@ TURSO_AUTH_TOKEN=`;
} }
function displayManualSetupInstructions() { function displayManualSetupInstructions() {
log.info("🔧 Manual Turso Setup Instructions:"); log.info(`🔧 Manual Turso Setup Instructions:
log.info("1. Visit https://turso.tech and create an account");
log.info("2. Create a new database from the dashboard"); 1. Visit https://turso.tech and create an account
log.info("3. Get your database URL and authentication token"); 2. Create a new database from the dashboard
log.info("4. Add these credentials to the .env file in packages/server/.env"); 3. Get your database URL and authentication token
log.info("\nThe .env file has been created with placeholder variables:"); 4. Add these credentials to the .env file in packages/server/.env
log.info("TURSO_DATABASE_URL=your_database_url");
log.info("TURSO_AUTH_TOKEN=your_auth_token"); TURSO_DATABASE_URL=your_database_url
TURSO_AUTH_TOKEN=your_auth_token`);
} }
export async function setupTurso(projectDir: string) { export async function setupTurso(projectDir: string) {
@@ -107,7 +104,7 @@ export async function setupTurso(projectDir: string) {
const canInstallCLI = platform !== "win32"; const canInstallCLI = platform !== "win32";
if (!canInstallCLI) { if (!canInstallCLI) {
log.warn("Automatic Turso setup is not supported on Windows."); log.warn(pc.yellow("Automatic Turso setup is not supported on Windows."));
await writeEnvFile(projectDir); await writeEnvFile(projectDir);
displayManualSetupInstructions(); displayManualSetupInstructions();
return; return;
@@ -122,7 +119,7 @@ export async function setupTurso(projectDir: string) {
}); });
if (isCancel(shouldInstall)) { if (isCancel(shouldInstall)) {
cancel("Operation cancelled"); cancel(pc.red("Operation cancelled"));
process.exit(0); process.exit(0);
} }
@@ -144,7 +141,7 @@ export async function setupTurso(projectDir: string) {
} }
s.stop("✅ Turso CLI installed successfully!"); s.stop("✅ Turso CLI installed successfully!");
} catch (error) { } catch (error) {
s.stop("Failed to install Turso CLI"); s.stop(pc.red("Failed to install Turso CLI"));
throw error; throw error;
} }
} }
@@ -157,7 +154,7 @@ export async function setupTurso(projectDir: string) {
await $`turso auth login`; await $`turso auth login`;
s.stop("✅ Logged in to Turso successfully!"); s.stop("✅ Logged in to Turso successfully!");
} catch (error) { } catch (error) {
s.stop("Failed to log in to Turso"); s.stop(pc.red("Failed to log in to Turso"));
throw error; throw error;
} }
} }
@@ -175,7 +172,7 @@ export async function setupTurso(projectDir: string) {
}); });
if (isCancel(dbNameResponse)) { if (isCancel(dbNameResponse)) {
cancel("Operation cancelled"); cancel(pc.red("Operation cancelled"));
process.exit(0); process.exit(0);
} }
@@ -190,7 +187,7 @@ export async function setupTurso(projectDir: string) {
success = true; success = true;
} catch (error) { } catch (error) {
if (error instanceof Error && error.message === "DATABASE_EXISTS") { if (error instanceof Error && error.message === "DATABASE_EXISTS") {
s.stop(`Database "${dbName}" already exists`); s.stop(pc.yellow(`Database "${pc.red(dbName)}" already exists`));
suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`; suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`;
} else { } else {
throw error; throw error;
@@ -198,9 +195,9 @@ export async function setupTurso(projectDir: string) {
} }
} }
} catch (error) { } catch (error) {
log.error(`Error during Turso setup: ${error}`); log.error(pc.red(`Error during Turso setup: ${error}`));
await writeEnvFile(projectDir); await writeEnvFile(projectDir);
displayManualSetupInstructions(); displayManualSetupInstructions();
outro("Setup completed with manual configuration required."); log.success("Setup completed with manual configuration required.");
} }
} }

View File

@@ -11,12 +11,11 @@ import {
spinner, spinner,
text, text,
} from "@clack/prompts"; } from "@clack/prompts";
import chalk from "chalk";
import { Command } from "commander"; import { Command } from "commander";
import fs from "fs-extra"; import fs from "fs-extra";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "./consts"; import { DEFAULT_CONFIG } from "./consts";
import { createProject } from "./helpers/create-project"; import { createProject } from "./helpers/create-project";
import { renderTitle } from "./render-title";
import type { import type {
PackageManager, PackageManager,
ProjectConfig, ProjectConfig,
@@ -26,9 +25,10 @@ import type {
import { generateReproducibleCommand } from "./utils/generate-reproducible-command"; import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
import { getUserPkgManager } from "./utils/get-package-manager"; import { getUserPkgManager } from "./utils/get-package-manager";
import { getVersion } from "./utils/get-version"; import { getVersion } from "./utils/get-version";
import { renderTitle } from "./utils/render-title";
process.on("SIGINT", () => { process.on("SIGINT", () => {
log.error("Operation cancelled"); log.error(pc.red("Operation cancelled"));
process.exit(0); process.exit(0);
}); });
@@ -74,7 +74,7 @@ async function gatherConfig(
}); });
if (typeof response === "symbol") { if (typeof response === "symbol") {
cancel("Operation cancelled."); cancel(pc.red("Operation cancelled."));
process.exit(0); process.exit(0);
} }
@@ -178,7 +178,7 @@ async function gatherConfig(
}, },
{ {
onCancel: () => { onCancel: () => {
cancel("Operation cancelled."); cancel(pc.red("Operation cancelled."));
process.exit(0); process.exit(0);
}, },
}, },
@@ -198,33 +198,25 @@ function displayConfig(config: Partial<ProjectConfig>) {
const configDisplay = []; const configDisplay = [];
if (config.projectName) { if (config.projectName) {
configDisplay.push( configDisplay.push(`${pc.blue("📝 Project Name:")} ${config.projectName}`);
`${chalk.blue("📝 Project Name: ")}${chalk.green(config.projectName)}`,
);
} }
if (config.database) { if (config.database) {
configDisplay.push( configDisplay.push(`${pc.blue("💾 Database:")} ${config.database}`);
`${chalk.blue("💾 Database: ")}${chalk.yellow(config.database)}`,
);
} }
if (config.auth !== undefined) { if (config.auth !== undefined) {
configDisplay.push( configDisplay.push(`${pc.blue("🔐 Authentication:")} ${config.auth}`);
`${chalk.blue("🔐 Authentication: ")}${chalk.cyan(config.auth)}`,
);
} }
if (config.features?.length) { if (config.features?.length) {
configDisplay.push( configDisplay.push(
`${chalk.blue("✨ Features: ")}${config.features.map((f) => chalk.magenta(f)).join(", ")}`, `${pc.blue("✨ Features:")} ${config.features.join(", ")}`,
); );
} }
if (config.git !== undefined) { if (config.git !== undefined) {
configDisplay.push( configDisplay.push(`${pc.blue("🗃️ Git Init:")} ${config.git}`);
`${chalk.blue("🗃️ Git Init: ")}${chalk.cyan(config.git)}`,
);
} }
if (config.packageManager) { if (config.packageManager) {
configDisplay.push( configDisplay.push(
`${chalk.blue("📦 Package Manager: ")}${chalk.yellow(config.packageManager)}`, `${pc.blue("📦 Package Manager:")} ${config.packageManager}`,
); );
} }
@@ -236,7 +228,7 @@ async function main() {
try { try {
process.stdout.write("\x1Bc"); process.stdout.write("\x1Bc");
renderTitle(); renderTitle();
intro(chalk.bold("✨ Creating a new Better-T-Stack project")); intro(pc.magenta("✨ Creating a new Better-T-Stack project"));
program program
.name("create-better-t-stack") .name("create-better-t-stack")
.description("Create a new Better-T Stack project") .description("Create a new Better-T Stack project")
@@ -288,7 +280,7 @@ async function main() {
!options.yes && !options.yes &&
Object.values(flagConfig).some((v) => v !== undefined) Object.values(flagConfig).some((v) => v !== undefined)
) { ) {
log.message(chalk.bold("\n🎯 Using these pre-selected options:")); log.info(pc.yellow("🎯 Using these pre-selected options:"));
log.message(displayConfig(flagConfig)); log.message(displayConfig(flagConfig));
log.message(""); log.message("");
} }
@@ -312,22 +304,26 @@ async function main() {
: await gatherConfig(flagConfig); : await gatherConfig(flagConfig);
if (options.yes) { if (options.yes) {
log.message(chalk.bold("\n🎯 Using these default options:")); log.info(pc.yellow("🎯 Using these default options:"));
log.message(displayConfig(config)); log.message(displayConfig(config));
log.message(""); log.message("");
} }
await createProject(config); await createProject(config);
log.info( log.success(
`You can reproduce this setup with the following command:\n${generateReproducibleCommand(config)}`, pc.blue(
`You can reproduce this setup with the following command:\n${pc.white(
generateReproducibleCommand(config),
)}`,
),
); );
outro("🎉 Project created successfully!"); outro(pc.magenta("🎉 Project created successfully!"));
} catch (error) { } catch (error) {
s.stop("Failed"); s.stop(pc.red("Failed"));
if (error instanceof Error) { if (error instanceof Error) {
cancel("An unexpected error occurred"); cancel(pc.red("An unexpected error occurred"));
process.exit(1); process.exit(1);
} }
} }

View File

@@ -1,4 +1,3 @@
import chalk from "chalk";
import { DEFAULT_CONFIG } from "../consts"; import { DEFAULT_CONFIG } from "../consts";
import type { ProjectConfig } from "../types"; import type { ProjectConfig } from "../types";
@@ -12,37 +11,34 @@ export function generateReproducibleCommand(config: ProjectConfig): string {
}); });
if (isMainlyDefault) { if (isMainlyDefault) {
flags.push(chalk.gray("-y")); flags.push("-y");
} }
if (config.database !== DEFAULT_CONFIG.database) { if (config.database !== DEFAULT_CONFIG.database) {
flags.push(chalk.cyan(`--database ${config.database}`)); flags.push(`--database ${config.database}`);
} }
if (config.auth !== DEFAULT_CONFIG.auth) { if (config.auth !== DEFAULT_CONFIG.auth) {
flags.push(chalk.yellow("--no-auth")); flags.push("--no-auth");
} }
if (!config.git) { if (!config.git) {
flags.push(chalk.red("--no-git")); flags.push("--no-git");
} }
// Updated package manager flag handling
if ( if (
config.packageManager && config.packageManager &&
config.packageManager !== DEFAULT_CONFIG.packageManager config.packageManager !== DEFAULT_CONFIG.packageManager
) { ) {
flags.push(chalk.magenta(`--${config.packageManager}`)); flags.push(`--${config.packageManager}`);
} }
for (const feature of config.features) { for (const feature of config.features) {
flags.push(chalk.green(`--${feature}`)); flags.push(`--${feature}`);
} }
const baseCommand = chalk.bold("npx create-better-t-stack"); const baseCommand = "npx create-better-t-stack";
const projectName = config.projectName const projectName = config.projectName ? ` ${config.projectName}` : "";
? chalk.blue(` ${config.projectName}`)
: "";
const flagString = flags.length > 0 ? ` ${flags.join(" ")}` : ""; const flagString = flags.length > 0 ? ` ${flags.join(" ")}` : "";
return `${baseCommand}${projectName}${flagString}`; return `${baseCommand}${projectName}${flagString}`;

View File

@@ -14,18 +14,18 @@
}, },
"apps/cli": { "apps/cli": {
"name": "create-better-t-stack", "name": "create-better-t-stack",
"version": "0.6.1", "version": "0.6.2",
"bin": { "bin": {
"create-better-t-stack": "dist/index.js" "create-better-t-stack": "dist/index.js"
}, },
"dependencies": { "dependencies": {
"@clack/prompts": "^0.10.0", "@clack/prompts": "^0.10.0",
"chalk": "^5.3.0",
"commander": "^13.1.0", "commander": "^13.1.0",
"degit": "^2.8.4", "degit": "^2.8.4",
"execa": "^8.0.1", "execa": "^8.0.1",
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",
"gradient-string": "^3.0.0", "gradient-string": "^3.0.0",
"picocolors": "^1.1.1",
}, },
"devDependencies": { "devDependencies": {
"@types/degit": "^2.8.6", "@types/degit": "^2.8.6",