Skip to content

Commit 50716f5

Browse files
Copilotadmdly
andauthored
Deduplicate init-db wrangler command
Agent-Logs-Url: https://github.com/FOSSBilling/api/sessions/2136da7d-e27a-461b-8edb-bc4f0c3c1118 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
1 parent 97bceae commit 50716f5

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

‎src/services/central-alerts/v1/scripts/init-db.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ import { fileURLToPath } from "url";
66

77
const __filename = fileURLToPath(import.meta.url);
88
const __dirname = dirname(__filename);
9+
const WRANGLER_D1_COMMAND = [
10+
"wrangler",
11+
"d1",
12+
"execute",
13+
"api_central-alerts",
14+
"--local"
15+
];
916

1017
function runWranglerCommand(args: string[]): void {
11-
const result = spawnSync(
12-
"npx",
13-
["wrangler", "d1", "execute", "api_central-alerts", "--local", ...args],
14-
{
15-
encoding: "utf8",
16-
stdio: "pipe"
17-
}
18-
);
18+
const command = [...WRANGLER_D1_COMMAND, ...args];
19+
const result = spawnSync("npx", command, {
20+
encoding: "utf8",
21+
stdio: "pipe"
22+
});
1923

2024
if (result.error) {
2125
throw result.error;
@@ -24,7 +28,7 @@ function runWranglerCommand(args: string[]): void {
2428
if (result.status !== 0) {
2529
throw new Error(
2630
[
27-
`Wrangler command failed: npx ${["wrangler", "d1", "execute", "api_central-alerts", "--local", ...args].join(" ")}`,
31+
`Wrangler command failed: npx ${command.join(" ")}`,
2832
result.stderr.trim() ? `stderr: ${result.stderr.trim()}` : "",
2933
result.stdout.trim() ? `stdout: ${result.stdout.trim()}` : ""
3034
]

0 commit comments

Comments
 (0)