mirror of
https://github.com/Dokploy/cli.git
synced 2026-06-15 20:25:22 +02:00
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.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import axios, { type AxiosInstance } from "axios";
|
|
||||||
import chalk from "chalk";
|
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
|
import axios, { type AxiosInstance } from "axios";
|
||||||
|
import chalk from "chalk";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
@@ -14,7 +14,8 @@ export interface AuthConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function readAuthConfig(): AuthConfig {
|
export function readAuthConfig(): AuthConfig {
|
||||||
const envToken = process.env.DOKPLOY_AUTH_TOKEN;
|
const envToken =
|
||||||
|
process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN;
|
||||||
const envUrl = process.env.DOKPLOY_URL;
|
const envUrl = process.env.DOKPLOY_URL;
|
||||||
|
|
||||||
if (envToken && envUrl) {
|
if (envToken && envUrl) {
|
||||||
@@ -60,13 +61,22 @@ export function createClient(): AxiosInstance {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apiPost(endpoint: string, data?: Record<string, unknown>) {
|
export async function apiPost(
|
||||||
|
endpoint: string,
|
||||||
|
data?: Record<string, unknown>,
|
||||||
|
) {
|
||||||
const client = createClient();
|
const client = createClient();
|
||||||
const response = await client.post(`/trpc/${endpoint}`, data ? { json: data } : undefined);
|
const response = await client.post(
|
||||||
|
`/trpc/${endpoint}`,
|
||||||
|
data ? { json: data } : undefined,
|
||||||
|
);
|
||||||
return response.data?.result?.data?.json ?? response.data;
|
return response.data?.result?.data?.json ?? response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apiGet(endpoint: string, params?: Record<string, unknown>) {
|
export async function apiGet(
|
||||||
|
endpoint: string,
|
||||||
|
params?: Record<string, unknown>,
|
||||||
|
) {
|
||||||
const client = createClient();
|
const client = createClient();
|
||||||
const query = params
|
const query = params
|
||||||
? `?input=${encodeURIComponent(JSON.stringify(params))}`
|
? `?input=${encodeURIComponent(JSON.stringify(params))}`
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
import type { Command } from "commander";
|
|
||||||
import chalk from "chalk";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import chalk from "chalk";
|
||||||
|
import type { Command } from "commander";
|
||||||
import { saveAuthConfig } from "../client.js";
|
import { saveAuthConfig } from "../client.js";
|
||||||
|
|
||||||
export function registerAuthCommand(program: Command) {
|
export function registerAuthCommand(program: Command) {
|
||||||
program
|
program
|
||||||
.command("auth")
|
.command("auth")
|
||||||
.description("Authenticate with your Dokploy server")
|
.description("Authenticate with your Dokploy server")
|
||||||
.requiredOption("-u, --url <url>", "Server URL (e.g., https://panel.dokploy.com)")
|
.requiredOption(
|
||||||
.requiredOption("-t, --token <token>", "API key from your Dokploy dashboard")
|
"-u, --url <url>",
|
||||||
|
"Server URL (e.g., https://panel.dokploy.com)",
|
||||||
|
)
|
||||||
|
.requiredOption(
|
||||||
|
"-t, --token <token>",
|
||||||
|
"API key from your Dokploy dashboard",
|
||||||
|
)
|
||||||
.action(async (opts: { url: string; token: string }) => {
|
.action(async (opts: { url: string; token: string }) => {
|
||||||
const url = opts.url.replace(/\/+$/, "");
|
const url = opts.url.replace(/\/+$/, "");
|
||||||
|
|
||||||
|
|||||||
13
src/index.ts
13
src/index.ts
@@ -1,16 +1,23 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { program } from "commander";
|
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
import { program } from "commander";
|
||||||
import { registerAuthCommand } from "./commands/auth.js";
|
import { registerAuthCommand } from "./commands/auth.js";
|
||||||
import { registerGeneratedCommands } from "./generated/commands.js";
|
import { registerGeneratedCommands } from "./generated/commands.js";
|
||||||
|
|
||||||
const pkg = { name: "dokploy", version: "0.3.0", description: "Dokploy CLI - Manage your Dokploy server" };
|
const pkg = {
|
||||||
|
name: "dokploy",
|
||||||
|
version: "0.3.0",
|
||||||
|
description: "Dokploy CLI - Manage your Dokploy server",
|
||||||
|
};
|
||||||
|
|
||||||
program
|
program
|
||||||
.name(pkg.name)
|
.name(pkg.name)
|
||||||
.version(pkg.version)
|
.version(pkg.version)
|
||||||
.description(pkg.description);
|
.description(pkg.description)
|
||||||
|
.action(() => {
|
||||||
|
program.help();
|
||||||
|
});
|
||||||
|
|
||||||
registerAuthCommand(program);
|
registerAuthCommand(program);
|
||||||
registerGeneratedCommands(program);
|
registerGeneratedCommands(program);
|
||||||
|
|||||||
Reference in New Issue
Block a user