Files
create-better-t-stack/apps/cli/src/utils/package-runner.ts
2025-06-22 22:49:44 +05:30

24 lines
831 B
TypeScript

import type { PackageManager } from "../types";
/**
* Returns the appropriate command for running a package without installing it globally,
* based on the selected package manager.
*
* @param packageManager - The selected package manager (e.g., 'npm', 'yarn', 'pnpm', 'bun').
* @param commandWithArgs - The command to run, including arguments (e.g., "prisma generate --schema=./prisma/schema.prisma").
* @returns The full command string (e.g., "npx prisma generate --schema=./prisma/schema.prisma").
*/
export function getPackageExecutionCommand(
packageManager: PackageManager | null | undefined,
commandWithArgs: string,
): string {
switch (packageManager) {
case "pnpm":
return `pnpm dlx ${commandWithArgs}`;
case "bun":
return `bunx ${commandWithArgs}`;
default:
return `npx ${commandWithArgs}`;
}
}