The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
use spawn instead of exec for script execution
Steven Tey6912d7da5971
diff --git a/apps/web/scripts/partners/merge-payouts.ts b/apps/web/scripts/partners/merge-payouts.tsdeleted file mode 100644index 7e5e0eaf2f..0000000000--- a/apps/web/scripts/partners/merge-payouts.ts+++ /dev/null@@ -1,68 +0,0 @@-import { prisma } from "@dub/prisma";-import { endOfMonth } from "date-fns";-import "dotenv-flow/config";--const payoutToMergeFrom = "po_1JZ3EXF4BDFGY9N6KF7BD4W38";-const payoutToMergeTo = "po_1JT0FW1SBKW7R88FKDENC9N9N";--async function main() {- const commissions = await prisma.commission.findMany({- where: {- payoutId: payoutToMergeFrom,- },- });-- console.log(`Found ${commissions.length} commissions`);-- const latestCommission = endOfMonth(- commissions.sort((a, b) => {- return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();- })[0].createdAt,- );-- console.log(`Latest commission: ${latestCommission}`);-- const updatedCommisions = await prisma.commission.updateMany({- where: {- payoutId: payoutToMergeFrom,- },- data: {- payoutId: payoutToMergeTo,- },- });-- console.log(`Updated ${updatedCommisions.count} commissions`);-- const result = await prisma.commission.aggregate({- where: {- payoutId: payoutToMergeTo,- },- _sum: {- earnings: true,- },- });-- console.log(`Sum of commissions: ${result._sum.earnings}`);-- const updatedPayout = await prisma.payout.update({- where: {- id: payoutToMergeTo,- },- data: {- amount: result._sum.earnings ?? 0,- periodEnd: latestCommission,- },- });-- console.log(`Updated payout: ${JSON.stringify(updatedPayout, null, 2)}`);-- const deletedPayout = await prisma.payout.delete({- where: {- id: payoutToMergeFrom,- },- });-- console.log(`Deleted payout: ${deletedPayout.id}`);-}--main();diff --git a/apps/web/scripts/run.ts b/apps/web/scripts/run.tsindex 06f285c37c..26a9653b0d 100644--- a/apps/web/scripts/run.ts+++ b/apps/web/scripts/run.ts@@ -1,5 +1,5 @@// runner.ts-import { exec } from "child_process";+import { spawn } from "child_process";const command: string = process.argv[2];@@ -12,15 +12,16 @@ const scriptPath = `./scripts/${command}.${command === "send-emails" ? "tsx" : "ts"}`;-exec(- `tsx --stack-size=5120000 ${scriptPath}`,- { maxBuffer: 1024 * 5000 },- (error, stdout, stderr) => {- if (error) {- console.error(`Error executing script: ${error.message}`);- return;- }- console.log(stdout);- console.error(stderr);- },-);+const child = spawn("tsx", ["--stack-size=5120000", scriptPath], {+ stdio: "inherit", // This pipes stdout/stderr directly to the parent process+ shell: true, // Allows running commands as if in a shell+});++child.on("error", (error) => {+ console.error(`Error executing script: ${error.message}`);+ process.exit(1);+});++child.on("exit", (code) => {+ process.exit(code ?? 0);+});