From b447f7d0ca77c9f8b0821be8a0c150197858802e Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:59:00 -0800 Subject: [PATCH] better error messages --- src/cli/commands/manage.ts | 18 ++++++++++++++++-- src/cli/commands/sync.ts | 25 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/cli/commands/manage.ts b/src/cli/commands/manage.ts index 1f41cc2..257a9c7 100644 --- a/src/cli/commands/manage.ts +++ b/src/cli/commands/manage.ts @@ -1,7 +1,7 @@ import type { App } from '@types' import { generateTemplates, type TemplateType } from '%templates' import color from 'kleur' -import { existsSync, mkdirSync, writeFileSync } from 'fs' +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs' import { basename, join } from 'path' import { del, get, getManifest, HOST, makeAppUrl, post } from '../http' import { confirm, prompt } from '../prompts' @@ -121,12 +121,26 @@ export async function newApp(name: string | undefined, options: NewAppOptions) { if (options.bare) template = 'bare' else if (options.spa) template = 'spa' + const pkgPath = join(appPath, 'package.json') + + // If package.json exists, ensure it has scripts.toes and bail + if (existsSync(pkgPath)) { + const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) + if (!pkg.scripts?.toes) { + pkg.scripts = pkg.scripts ?? {} + pkg.scripts.toes = 'bun start' + writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') + console.log(color.green('✓ Added scripts.toes to package.json')) + } + return + } + if (name && existsSync(appPath)) { console.error(`Directory already exists: ${name}`) return } - const filesToCheck = ['index.tsx', 'package.json', 'tsconfig.json'] + const filesToCheck = ['index.tsx', 'tsconfig.json'] const existing = filesToCheck.filter((f) => existsSync(join(appPath, f))) if (existing.length > 0) { console.error(`Files already exist: ${existing.join(', ')}`) diff --git a/src/cli/commands/sync.ts b/src/cli/commands/sync.ts index 122381e..dcc829b 100644 --- a/src/cli/commands/sync.ts +++ b/src/cli/commands/sync.ts @@ -7,7 +7,14 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, unl import { dirname, join } from 'path' import { del, download, get, getManifest, handleError, makeUrl, post, put } from '../http' import { confirm, prompt } from '../prompts' -import { getAppName, isApp, resolveAppName } from '../name' +import { getAppName, getAppPackage, isApp, resolveAppName } from '../name' + +function notAppError(): string { + const pkg = getAppPackage() + if (!pkg) return 'No package.json found. Use `toes get ` to grab one.' + if (!pkg.scripts?.toes) return 'Missing scripts.toes in package.json. Use `toes new` to add it.' + return 'Not a toes app' +} interface ManifestDiff { changed: string[] @@ -59,7 +66,7 @@ export async function getApp(name: string) { export async function pushApp() { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return } @@ -147,7 +154,7 @@ export async function pushApp() { export async function pullApp(options: { force?: boolean } = {}) { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return } @@ -222,7 +229,7 @@ export async function pullApp(options: { force?: boolean } = {}) { export async function diffApp() { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return } @@ -309,7 +316,7 @@ export async function diffApp() { export async function statusApp() { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return } @@ -367,7 +374,7 @@ export async function statusApp() { export async function syncApp() { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return } @@ -581,7 +588,7 @@ const STASH_BASE = '/tmp/toes-stash' export async function stashApp() { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return } @@ -690,7 +697,7 @@ export async function stashListApp() { export async function stashPopApp() { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return } @@ -747,7 +754,7 @@ export async function stashPopApp() { export async function cleanApp(options: { force?: boolean, dryRun?: boolean } = {}) { if (!isApp()) { - console.error('Not a toes app. Use `toes get ` to grab one.') + console.error(notAppError()) return }