Skip to content

Commit 70f5429

Browse files
committed
refactor: clean up imports and improve function formatting
- Reordered and grouped import statements for better readability in client.ts, index.ts, and auth.ts. - Updated the readAuthConfig function to prioritize DOKPLOY_API_KEY over DOKPLOY_AUTH_TOKEN. - Enhanced formatting of apiPost and apiGet functions for improved clarity and consistency.
1 parent 5b02a22 commit 70f5429

3 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/client.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import axios, { type AxiosInstance } from "axios";
2-
import chalk from "chalk";
31
import * as fs from "node:fs";
42
import * as path from "node:path";
53
import { fileURLToPath } from "node:url";
4+
import axios, { type AxiosInstance } from "axios";
5+
import chalk from "chalk";
66

77
const __filename = fileURLToPath(import.meta.url);
88
const __dirname = path.dirname(__filename);
@@ -14,7 +14,8 @@ export interface AuthConfig {
1414
}
1515

1616
export function readAuthConfig(): AuthConfig {
17-
const envToken = process.env.DOKPLOY_AUTH_TOKEN;
17+
const envToken =
18+
process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN;
1819
const envUrl = process.env.DOKPLOY_URL;
1920

2021
if (envToken && envUrl) {
@@ -60,13 +61,22 @@ export function createClient(): AxiosInstance {
6061
});
6162
}
6263

63-
export async function apiPost(endpoint: string, data?: Record<string, unknown>) {
64+
export async function apiPost(
65+
endpoint: string,
66+
data?: Record<string, unknown>,
67+
) {
6468
const client = createClient();
65-
const response = await client.post(`/trpc/${endpoint}`, data ? { json: data } : undefined);
69+
const response = await client.post(
70+
`/trpc/${endpoint}`,
71+
data ? { json: data } : undefined,
72+
);
6673
return response.data?.result?.data?.json ?? response.data;
6774
}
6875

69-
export async function apiGet(endpoint: string, params?: Record<string, unknown>) {
76+
export async function apiGet(
77+
endpoint: string,
78+
params?: Record<string, unknown>,
79+
) {
7080
const client = createClient();
7181
const query = params
7282
? `?input=${encodeURIComponent(JSON.stringify(params))}`

src/commands/auth.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import type { Command } from "commander";
2-
import chalk from "chalk";
31
import axios from "axios";
2+
import chalk from "chalk";
3+
import type { Command } from "commander";
44
import { saveAuthConfig } from "../client.js";
55

66
export function registerAuthCommand(program: Command) {
77
program
88
.command("auth")
99
.description("Authenticate with your Dokploy server")
10-
.requiredOption("-u, --url <url>", "Server URL (e.g., https://panel.dokploy.com)")
11-
.requiredOption("-t, --token <token>", "API key from your Dokploy dashboard")
10+
.requiredOption(
11+
"-u, --url <url>",
12+
"Server URL (e.g., https://panel.dokploy.com)",
13+
)
14+
.requiredOption(
15+
"-t, --token <token>",
16+
"API key from your Dokploy dashboard",
17+
)
1218
.action(async (opts: { url: string; token: string }) => {
1319
const url = opts.url.replace(/\/+$/, "");
1420

src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
#!/usr/bin/env node
22

3-
import { program } from "commander";
43
import chalk from "chalk";
4+
import { program } from "commander";
55
import { registerAuthCommand } from "./commands/auth.js";
66
import { registerGeneratedCommands } from "./generated/commands.js";
77

8-
const pkg = { name: "dokploy", version: "0.3.0", description: "Dokploy CLI - Manage your Dokploy server" };
8+
const pkg = {
9+
name: "dokploy",
10+
version: "0.3.0",
11+
description: "Dokploy CLI - Manage your Dokploy server",
12+
};
913

1014
program
1115
.name(pkg.name)
1216
.version(pkg.version)
13-
.description(pkg.description);
17+
.description(pkg.description)
18+
.action(() => {
19+
program.help();
20+
});
1421

1522
registerAuthCommand(program);
1623
registerGeneratedCommands(program);

0 commit comments

Comments
 (0)