diff --git a/packages/wb/src/commands/buildIfNeeded.ts b/packages/wb/src/commands/buildIfNeeded.ts index 0fa20f70..78a78707 100644 --- a/packages/wb/src/commands/buildIfNeeded.ts +++ b/packages/wb/src/commands/buildIfNeeded.ts @@ -53,7 +53,10 @@ export async function buildIfNeeded( projectPathForTesting?: string ): Promise { const project = await findSelfProject(argv, true, projectPathForTesting); - if (!project) return true; + if (!project) { + console.error(chalk.red('No project found.')); + return true; + } if (!fs.existsSync(path.join(project.rootDirPath, '.git'))) { build(project, argv); diff --git a/packages/wb/src/commands/optimizeForDockerBuild.ts b/packages/wb/src/commands/optimizeForDockerBuild.ts index 8c0165fe..9f377f71 100644 --- a/packages/wb/src/commands/optimizeForDockerBuild.ts +++ b/packages/wb/src/commands/optimizeForDockerBuild.ts @@ -2,6 +2,7 @@ import child_process from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; +import chalk from 'chalk'; import type { PackageJson } from 'type-fest'; import type { CommandModule, InferredOptionTypes } from 'yargs'; @@ -23,7 +24,10 @@ export const optimizeForDockerBuildCommand: CommandModule { const projects = await findAllProjects(argv); - if (!projects) return []; + if (!projects) { + console.error(chalk.red('No project found.')); + process.exit(1); + } return projects.all.filter( (project) => project.packageJson.dependencies?.['prisma'] || project.packageJson.devDependencies?.['prisma'] diff --git a/packages/wb/src/commands/retry.ts b/packages/wb/src/commands/retry.ts index 2c4b60c8..20f30e61 100644 --- a/packages/wb/src/commands/retry.ts +++ b/packages/wb/src/commands/retry.ts @@ -14,15 +14,34 @@ const builder = { }, } as const; -export const retryCommand: CommandModule> = { - command: 'retry', +const argumentsBuilder = { + command: { + description: 'A command to retry', + type: 'string', + demand: true, + }, + args: { + description: 'Arguments for the command', + type: 'array', + default: [], + }, +} as const; + +export const retryCommand: CommandModule< + unknown, + InferredOptionTypes +> = { + command: 'retry [args...]', describe: 'Retry the given command until it succeeds', builder, async handler(argv) { const project = findSelfProject(argv); - if (!project) return; + if (!project) { + console.error(chalk.red('No project found.')); + process.exit(1); + } - const cmdAndArgs = argv._.slice(1); + const cmdAndArgs = [argv.command, ...argv.args]; let lastStatus = 0; for (let i = 0; i < argv.retry; i++) { if (i > 0) { diff --git a/packages/wb/src/commands/setup.ts b/packages/wb/src/commands/setup.ts index 993a8d82..fab5550f 100644 --- a/packages/wb/src/commands/setup.ts +++ b/packages/wb/src/commands/setup.ts @@ -2,6 +2,7 @@ import child_process from 'node:child_process'; import fs from 'node:fs/promises'; import os from 'node:os'; +import chalk from 'chalk'; import type { ArgumentsCamelCase, CommandModule, InferredOptionTypes } from 'yargs'; import { findAllProjects } from '../project.js'; @@ -27,7 +28,10 @@ export async function setup( projectPathForTesting?: string ): Promise { const projects = await findAllProjects(argv, false, projectPathForTesting); - if (!projects) return; + if (!projects) { + console.error(chalk.red('No project found.')); + process.exit(1); + } for (const project of prepareForRunningCommand('setup', projects.all)) { const dirents = await fs.readdir(project.dirPath, { withFileTypes: true }); diff --git a/packages/wb/src/commands/start.ts b/packages/wb/src/commands/start.ts index 0f5b5c49..fda5f15a 100644 --- a/packages/wb/src/commands/start.ts +++ b/packages/wb/src/commands/start.ts @@ -1,3 +1,4 @@ +import chalk from 'chalk'; import type { CommandModule, InferredOptionTypes } from 'yargs'; import { findAllProjects } from '../project.js'; @@ -28,7 +29,10 @@ export const startCommand: CommandModule> ): Promise { const projects = await findAllProjects(argv); - if (!projects) return; + if (!projects) { + console.error(chalk.red('No project found.')); + process.exit(1); + } if (projects.all.length > 1) { // Disable interactive mode diff --git a/packages/wb/src/commands/typecheck.ts b/packages/wb/src/commands/typecheck.ts index 3bd68e27..d8772270 100644 --- a/packages/wb/src/commands/typecheck.ts +++ b/packages/wb/src/commands/typecheck.ts @@ -19,7 +19,10 @@ export const typeCheckCommand: CommandModule< builder, async handler(argv) { const projects = await findAllProjects(argv, false); - if (!projects) return; + if (!projects) { + console.error(chalk.red('No project found.')); + process.exit(1); + } for (const project of projects.all) { const commands: string[] = [];