feat: add list and create project

This commit is contained in:
Mauricio Siu
2024-06-05 01:43:19 -06:00
parent 9f033de1b2
commit bec0dfa57f
12 changed files with 249 additions and 16 deletions

4
src/utils/http.ts Normal file
View File

@@ -0,0 +1,4 @@
export const headers = {
"Content-Type": "application/json",
"User-Agent": "Dokploy CLI",
};

36
src/utils/utils.ts Normal file
View File

@@ -0,0 +1,36 @@
import type { Command } from "@oclif/core";
import chalk from "chalk";
import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const configPath = path.join(__dirname, "..", "..", "config.json");
export const readAuthConfig = async (
command: Command,
): Promise<{ token: string; url: string }> => {
if (!fs.existsSync(configPath)) {
command.error(
chalk.red(
"No configuration file found. Please authenticate first using the 'authenticate' command.",
),
);
}
const configFileContent = fs.readFileSync(configPath, "utf8");
const config = JSON.parse(configFileContent);
const { token, url } = config;
if (!url || !token) {
command.error(
chalk.red(
"Incomplete authentication details. Please authenticate again using the 'authenticate' command.",
),
);
}
return { token, url };
};