Skip to content

Commit

Permalink
fix(wb): retry command
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Nov 9, 2023
1 parent 757f936 commit 728c414
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 11 deletions.
5 changes: 4 additions & 1 deletion packages/wb/src/commands/buildIfNeeded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export async function buildIfNeeded(
projectPathForTesting?: string
): Promise<boolean | undefined> {
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);
Expand Down
6 changes: 5 additions & 1 deletion packages/wb/src/commands/optimizeForDockerBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -23,7 +24,10 @@ export const optimizeForDockerBuildCommand: CommandModule<unknown, InferredOptio
builder,
async handler(argv) {
const projects = await findAllProjects(argv);
if (!projects) return;
if (!projects) {
console.error(chalk.red('No project found.'));
process.exit(1);
}

for (const project of prepareForRunningCommand('optimizeForDockerBuild', projects.all)) {
const packageJson: PackageJson = project.packageJson;
Expand Down
6 changes: 5 additions & 1 deletion packages/wb/src/commands/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EnvReaderOptions } from '@willbooster/shared-lib-node/src';
import chalk from 'chalk';
import type { CommandModule, InferredOptionTypes } from 'yargs';

import type { Project } from '../project.js';
Expand Down Expand Up @@ -192,7 +193,10 @@ const studioCommand: CommandModule<unknown, InferredOptionTypes<typeof studioBui

async function findPrismaProjects(argv: EnvReaderOptions): Promise<Project[]> {
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']
Expand Down
27 changes: 23 additions & 4 deletions packages/wb/src/commands/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,34 @@ const builder = {
},
} as const;

export const retryCommand: CommandModule<unknown, InferredOptionTypes<typeof builder & typeof sharedOptionsBuilder>> = {
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<typeof builder & typeof sharedOptionsBuilder & typeof argumentsBuilder>
> = {
command: 'retry <command> [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) {
Expand Down
6 changes: 5 additions & 1 deletion packages/wb/src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,7 +28,10 @@ export async function setup(
projectPathForTesting?: string
): Promise<void> {
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 });
Expand Down
6 changes: 5 additions & 1 deletion packages/wb/src/commands/start.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import type { CommandModule, InferredOptionTypes } from 'yargs';

import { findAllProjects } from '../project.js';
Expand Down Expand Up @@ -28,7 +29,10 @@ export const startCommand: CommandModule<unknown, InferredOptionTypes<typeof bui
normalizeArgs(argv);

const projects = await findAllProjects(argv);
if (!projects) return;
if (!projects) {
console.error(chalk.red('No project found.'));
process.exit(1);
}

for (const project of projects.all) {
const deps = project.packageJson.dependencies || {};
Expand Down
6 changes: 5 additions & 1 deletion packages/wb/src/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'node:path';

import { existsAsync } from '@willbooster/shared-lib-node/src';
import chalk from 'chalk';
import type { ArgumentsCamelCase, CommandModule, InferredOptionTypes } from 'yargs';

import type { Project } from '../project.js';
Expand Down Expand Up @@ -53,7 +54,10 @@ export async function test(
argv: ArgumentsCamelCase<InferredOptionTypes<typeof builder & typeof sharedOptionsBuilder>>
): Promise<void> {
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
Expand Down
5 changes: 4 additions & 1 deletion packages/wb/src/commands/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down

0 comments on commit 728c414

Please sign in to comment.