diff --git a/.gitignore b/.gitignore index 57a8bbf..162c52b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ yarn.lock package-lock.json +tsconfig.tsbuildinfo diff --git a/src/commands/app/create.ts b/src/commands/app/create.ts index 40b77c7..800e71c 100644 --- a/src/commands/app/create.ts +++ b/src/commands/app/create.ts @@ -14,6 +14,8 @@ export interface Answers { export default class AppCreate extends Command { static description = "Create a new application within a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> app create"]; static flags = { @@ -48,14 +50,14 @@ export default class AppCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(AppCreate); let { projectId, environmentId, name, description, appName } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !name || !appName) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -175,6 +177,8 @@ export default class AppCreate extends Command { } this.log(chalk.green(`Application '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating application: ${error.message}`)); } diff --git a/src/commands/app/delete.ts b/src/commands/app/delete.ts index af2a87b..53c4ba3 100644 --- a/src/commands/app/delete.ts +++ b/src/commands/app/delete.ts @@ -10,6 +10,8 @@ import type { Answers } from "./create.js"; export default class AppDelete extends Command { static description = "Delete an application from a project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> app delete", "$ <%= config.bin %> app delete -p ", @@ -38,14 +40,14 @@ export default class AppDelete extends Command { }) }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(AppDelete); let { projectId, environmentId, applicationId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !applicationId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -151,6 +153,8 @@ export default class AppDelete extends Command { } this.log(chalk.green("Application deleted successfully.")); + + return deleteResponse.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Failed to delete application: ${error.message}`)); } diff --git a/src/commands/app/deploy.ts b/src/commands/app/deploy.ts index 479f7f0..642ebbc 100644 --- a/src/commands/app/deploy.ts +++ b/src/commands/app/deploy.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class AppDeploy extends Command { static description = "Deploy an application to a project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> app deploy", "$ <%= config.bin %> app deploy --applicationId myAppId", @@ -38,14 +40,14 @@ export default class AppDeploy extends Command { }) }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(AppDeploy); let { projectId, applicationId, environmentId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !applicationId || !environmentId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -150,6 +152,8 @@ export default class AppDeploy extends Command { this.error(chalk.red("Error deploying application")); } this.log(chalk.green("Application deploy successful.")); + + return { applicationId }; } catch (error: any) { this.error(chalk.red(`Error deploying application: ${error.message}`)); } diff --git a/src/commands/app/stop.ts b/src/commands/app/stop.ts index b642e24..d9b471f 100644 --- a/src/commands/app/stop.ts +++ b/src/commands/app/stop.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class AppStop extends Command { static description = "Stop an application from a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> app stop"]; static flags = { @@ -34,14 +36,14 @@ export default class AppStop extends Command { }) }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(AppStop); let { projectId, environmentId, applicationId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !applicationId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -146,6 +148,8 @@ export default class AppStop extends Command { this.error(chalk.red("Error stopping application")); } this.log(chalk.green("Application stop successful.")); + + return { applicationId }; } catch (error: any) { this.error(chalk.red(`Error stopping application: ${error.message}`)); } diff --git a/src/commands/authenticate.ts b/src/commands/authenticate.ts index c57eb49..311f20b 100644 --- a/src/commands/authenticate.ts +++ b/src/commands/authenticate.ts @@ -29,7 +29,7 @@ export default class Authenticate extends Command { }; async run() { - console.log( + this.log( chalk.blue.bold("\n Welcome to Dokploy CLI Authentication \n"), ); @@ -81,7 +81,7 @@ export default class Authenticate extends Command { config.url = url; try { - console.log(`\n${chalk.blue("Validating server...")}`); + this.log(`\n${chalk.blue("Validating server...")}`); await axios.get( `${url}/api/trpc/user.get`, diff --git a/src/commands/database/mariadb/create.ts b/src/commands/database/mariadb/create.ts index d2c4811..725e192 100644 --- a/src/commands/database/mariadb/create.ts +++ b/src/commands/database/mariadb/create.ts @@ -10,6 +10,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabaseMariadbCreate extends Command { static description = "Create a new MariaDB database within a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> mariadb create"]; static flags = { @@ -64,7 +66,7 @@ export default class DatabaseMariadbCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMariadbCreate); let { @@ -82,7 +84,7 @@ export default class DatabaseMariadbCreate extends Command { // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !name || !databaseName || !appName) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -243,6 +245,8 @@ export default class DatabaseMariadbCreate extends Command { } this.log(chalk.green(`MariaDB instance '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating MariaDB instance: ${error.message}`)); } diff --git a/src/commands/database/mariadb/delete.ts b/src/commands/database/mariadb/delete.ts index 87c9ba6..05ee307 100644 --- a/src/commands/database/mariadb/delete.ts +++ b/src/commands/database/mariadb/delete.ts @@ -8,6 +8,8 @@ import { readAuthConfig } from "../../../utils/utils.js"; export default class DatabaseMariadbDelete extends Command { static description = "Delete a MariaDB database from a project."; + + static enableJsonFlag = true; static examples = [ "$ <%= config.bin %> mariadb delete", "$ <%= config.bin %> mariadb delete -p ", @@ -35,13 +37,13 @@ export default class DatabaseMariadbDelete extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMariadbDelete); let { projectId, environmentId, mariadbId } = flags; if (!projectId || !environmentId || !mariadbId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -145,6 +147,8 @@ export default class DatabaseMariadbDelete extends Command { this.error(chalk.red("Error deleting MariaDB instance")); } this.log(chalk.green("MariaDB instance deleted successfully.")); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error deleting MariaDB instance: ${error.message}`)); } diff --git a/src/commands/database/mariadb/deploy.ts b/src/commands/database/mariadb/deploy.ts index bc54751..fa3c3be 100644 --- a/src/commands/database/mariadb/deploy.ts +++ b/src/commands/database/mariadb/deploy.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabaseMariadbDeploy extends Command { static description = "Deploy an mariadb to a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> app deploy"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseMariadbDeploy extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMariadbDeploy); let { projectId, environmentId, mariadbId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mariadbId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/mariadb/stop.ts b/src/commands/database/mariadb/stop.ts index f5c9d7e..a64af58 100644 --- a/src/commands/database/mariadb/stop.ts +++ b/src/commands/database/mariadb/stop.ts @@ -9,6 +9,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabaseMariadbStop extends Command { static description = "Stop an mariadb from a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> mariadb stop"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseMariadbStop extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMariadbStop); let { projectId, environmentId, mariadbId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mariadbId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/mongo/create.ts b/src/commands/database/mongo/create.ts index 30ebd1b..b46e0b1 100644 --- a/src/commands/database/mongo/create.ts +++ b/src/commands/database/mongo/create.ts @@ -10,6 +10,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabaseMongoCreate extends Command { static description = "Create a new MongoDB database within a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> mongo create"]; static flags = { @@ -60,7 +62,7 @@ export default class DatabaseMongoCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMongoCreate); let { @@ -77,7 +79,7 @@ export default class DatabaseMongoCreate extends Command { // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !name || !databaseName || !appName || !databasePassword) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -230,6 +232,8 @@ export default class DatabaseMongoCreate extends Command { } this.log(chalk.green(`MongoDB instance '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating MongoDB instance: ${error.message}`)); } diff --git a/src/commands/database/mongo/delete.ts b/src/commands/database/mongo/delete.ts index 1fe34eb..a293295 100644 --- a/src/commands/database/mongo/delete.ts +++ b/src/commands/database/mongo/delete.ts @@ -9,6 +9,8 @@ import { getProject, getProjects, type Database } from "../../../utils/shared.js export default class DatabaseMongoDelete extends Command { static description = "Delete a MongoDB database from a project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> mongo delete", "$ <%= config.bin %> mongo delete -p ", @@ -37,14 +39,14 @@ export default class DatabaseMongoDelete extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMongoDelete); let { projectId, environmentId, mongoId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mongoId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -149,6 +151,8 @@ export default class DatabaseMongoDelete extends Command { this.error(chalk.red("Error deleting MongoDB instance")); } this.log(chalk.green("MongoDB instance deleted successfully.")); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error deleting MongoDB instance: ${error.message}`)); } diff --git a/src/commands/database/mongo/deploy.ts b/src/commands/database/mongo/deploy.ts index 7353d7a..a637073 100644 --- a/src/commands/database/mongo/deploy.ts +++ b/src/commands/database/mongo/deploy.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabaseMongoDeploy extends Command { static description = "Deploy an mongo to a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> app deploy"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseMongoDeploy extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMongoDeploy); let { projectId, environmentId, mongoId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mongoId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/mongo/stop.ts b/src/commands/database/mongo/stop.ts index e26f9ce..945391f 100644 --- a/src/commands/database/mongo/stop.ts +++ b/src/commands/database/mongo/stop.ts @@ -9,6 +9,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabaseMongoStop extends Command { static description = "Stop an mongo from a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> mongo stop"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseMongoStop extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMongoStop); let { projectId, environmentId, mongoId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mongoId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/mysql/create.ts b/src/commands/database/mysql/create.ts index 402e8cb..0456223 100644 --- a/src/commands/database/mysql/create.ts +++ b/src/commands/database/mysql/create.ts @@ -11,6 +11,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabaseMysqlCreate extends Command { static description = "Create a new MySQL database within a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> mysql create"]; static flags = { @@ -65,7 +67,7 @@ export default class DatabaseMysqlCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMysqlCreate); let { @@ -83,7 +85,7 @@ export default class DatabaseMysqlCreate extends Command { // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !name || !databaseName || !appName || !databasePassword || !databaseRootPassword) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -245,6 +247,8 @@ export default class DatabaseMysqlCreate extends Command { } this.log(chalk.green(`MySQL instance '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating MySQL instance: ${error.message}`)); } diff --git a/src/commands/database/mysql/delete.ts b/src/commands/database/mysql/delete.ts index c05c442..90957ec 100644 --- a/src/commands/database/mysql/delete.ts +++ b/src/commands/database/mysql/delete.ts @@ -9,6 +9,8 @@ import { getProject, getProjects, type Database } from "../../../utils/shared.js export default class DatabaseMysqlDelete extends Command { static description = "Delete a MySQL database from a project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> mysql delete", "$ <%= config.bin %> mysql delete -p ", @@ -37,14 +39,14 @@ export default class DatabaseMysqlDelete extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMysqlDelete); let { projectId, environmentId, mysqlId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mysqlId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -149,6 +151,8 @@ export default class DatabaseMysqlDelete extends Command { this.error(chalk.red("Error deleting MySQL instance")); } this.log(chalk.green("MySQL instance deleted successfully.")); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error deleting MySQL instance: ${error.message}`)); } diff --git a/src/commands/database/mysql/deploy.ts b/src/commands/database/mysql/deploy.ts index 747027b..44da354 100644 --- a/src/commands/database/mysql/deploy.ts +++ b/src/commands/database/mysql/deploy.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabaseMysqlDeploy extends Command { static description = "Deploy an mysql to a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> app deploy"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseMysqlDeploy extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMysqlDeploy); let { projectId, environmentId, mysqlId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mysqlId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/mysql/stop.ts b/src/commands/database/mysql/stop.ts index 50ca2f6..8d951c9 100644 --- a/src/commands/database/mysql/stop.ts +++ b/src/commands/database/mysql/stop.ts @@ -9,6 +9,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabaseMysqlStop extends Command { static description = "Stop an mysql from a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> mysql stop"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseMysqlStop extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseMysqlStop); let { projectId, environmentId, mysqlId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !mysqlId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/postgres/create.ts b/src/commands/database/postgres/create.ts index 55db1b7..04288ce 100644 --- a/src/commands/database/postgres/create.ts +++ b/src/commands/database/postgres/create.ts @@ -9,6 +9,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabasePostgresCreate extends Command { static description = "Create a new PostgreSQL database within a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> postgres create"]; static flags = { @@ -59,7 +61,7 @@ export default class DatabasePostgresCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabasePostgresCreate); let { @@ -76,7 +78,7 @@ export default class DatabasePostgresCreate extends Command { // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !name || !databaseName || !appName || !databasePassword) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -230,6 +232,8 @@ export default class DatabasePostgresCreate extends Command { } this.log(chalk.green(`PostgreSQL instance '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating PostgreSQL instance: ${error.message}`)); } diff --git a/src/commands/database/postgres/delete.ts b/src/commands/database/postgres/delete.ts index 339d66c..b35e8fa 100644 --- a/src/commands/database/postgres/delete.ts +++ b/src/commands/database/postgres/delete.ts @@ -9,6 +9,8 @@ import { getProject, getProjects, type Database } from "../../../utils/shared.js export default class DatabasePostgresDelete extends Command { static description = "Delete a PostgreSQL database from a project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> postgres delete", "$ <%= config.bin %> postgres delete -p ", @@ -37,14 +39,14 @@ export default class DatabasePostgresDelete extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabasePostgresDelete); let { projectId, environmentId, postgresId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !postgresId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -149,6 +151,8 @@ export default class DatabasePostgresDelete extends Command { this.error(chalk.red("Error deleting PostgreSQL instance")); } this.log(chalk.green("PostgreSQL instance deleted successfully.")); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error deleting PostgreSQL instance: ${error.message}`)); } diff --git a/src/commands/database/postgres/deploy.ts b/src/commands/database/postgres/deploy.ts index 490994d..eccde4e 100644 --- a/src/commands/database/postgres/deploy.ts +++ b/src/commands/database/postgres/deploy.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabasePostgresDeploy extends Command { static description = "Deploy a PostgreSQL instance to a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> postgres deploy"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabasePostgresDeploy extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabasePostgresDeploy); let { projectId, environmentId, postgresId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !postgresId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/postgres/stop.ts b/src/commands/database/postgres/stop.ts index 920c56b..8d7dde8 100644 --- a/src/commands/database/postgres/stop.ts +++ b/src/commands/database/postgres/stop.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabasePostgresStop extends Command { static description = "Stop a PostgreSQL instance in a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> postgres stop"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabasePostgresStop extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabasePostgresStop); let { projectId, environmentId, postgresId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !postgresId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/redis/create.ts b/src/commands/database/redis/create.ts index 4376b10..7f11a7a 100644 --- a/src/commands/database/redis/create.ts +++ b/src/commands/database/redis/create.ts @@ -10,6 +10,8 @@ import type { Answers } from "../../app/create.js"; export default class DatabaseRedisCreate extends Command { static description = "Create a new Redis instance within a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> redis create"]; static flags = { @@ -52,11 +54,12 @@ export default class DatabaseRedisCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseRedisCreate); let { projectId, + environmentId, name, description, databasePassword, @@ -66,7 +69,7 @@ export default class DatabaseRedisCreate extends Command { // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !name || !appName || !databasePassword) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -202,6 +205,8 @@ export default class DatabaseRedisCreate extends Command { } this.log(chalk.green(`Redis instance '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating Redis instance: ${error.message}`)); } diff --git a/src/commands/database/redis/delete.ts b/src/commands/database/redis/delete.ts index c1bba51..9251eb4 100644 --- a/src/commands/database/redis/delete.ts +++ b/src/commands/database/redis/delete.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabaseRedisDelete extends Command { static description = "Delete a Redis instance from a project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> redis delete", "$ <%= config.bin %> redis delete -p ", @@ -37,14 +39,14 @@ export default class DatabaseRedisDelete extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseRedisDelete); let { projectId, environmentId, redisId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !redisId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -149,6 +151,8 @@ export default class DatabaseRedisDelete extends Command { this.error(chalk.red("Error deleting Redis instance")); } this.log(chalk.green("Redis instance deleted successfully.")); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error deleting Redis instance: ${error.message}`)); } diff --git a/src/commands/database/redis/deploy.ts b/src/commands/database/redis/deploy.ts index 5cd7d7b..c047d36 100644 --- a/src/commands/database/redis/deploy.ts +++ b/src/commands/database/redis/deploy.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabaseRedisDeploy extends Command { static description = "Deploy a Redis instance to a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> redis deploy"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseRedisDeploy extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseRedisDeploy); let { projectId, environmentId, redisId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !redisId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/database/redis/stop.ts b/src/commands/database/redis/stop.ts index a71a2b5..352e95c 100644 --- a/src/commands/database/redis/stop.ts +++ b/src/commands/database/redis/stop.ts @@ -9,6 +9,8 @@ import axios from "axios"; export default class DatabaseRedisStop extends Command { static description = "Stop a Redis instance in a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> redis stop"]; static flags = { @@ -34,14 +36,14 @@ export default class DatabaseRedisStop extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(DatabaseRedisStop); let { projectId, environmentId, redisId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId || !redisId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; diff --git a/src/commands/env/pull.ts b/src/commands/env/pull.ts index c89793e..6709acd 100644 --- a/src/commands/env/pull.ts +++ b/src/commands/env/pull.ts @@ -11,6 +11,9 @@ export default class EnvPull extends Command { file: Args.string({description: 'write to file', required: true}), } + + static enableJsonFlag = true; + static override description = 'Store remote environment variables in local' static override examples = [ @@ -36,7 +39,7 @@ export default class EnvPull extends Command { } } const auth = await readAuthConfig(this); - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); const {project} = await inquirer.prompt([ diff --git a/src/commands/env/push.ts b/src/commands/env/push.ts index c3f2809..bffbdcb 100644 --- a/src/commands/env/push.ts +++ b/src/commands/env/push.ts @@ -12,6 +12,9 @@ export default class EnvPush extends Command { file: Args.string({description: '.env file to push', required: true}), } + + static enableJsonFlag = true; + static override description = 'Push dotenv file to remote service' static override examples = [ @@ -24,7 +27,7 @@ export default class EnvPush extends Command { const {args, flags} = await this.parse(EnvPush) if (!fs.existsSync(args.file)) { - console.log(chalk.red.bold(`\n File ${args.file} doesn't exists \n`)); + this.log(chalk.red.bold(`\n File ${args.file} doesn't exists \n`)); return; } @@ -42,7 +45,7 @@ export default class EnvPush extends Command { const fileContent = fs.readFileSync(args.file, 'utf-8'); const auth = await readAuthConfig(this); - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); const {project} = await inquirer.prompt([ diff --git a/src/commands/environment/create.ts b/src/commands/environment/create.ts index 761008d..521396e 100644 --- a/src/commands/environment/create.ts +++ b/src/commands/environment/create.ts @@ -10,6 +10,8 @@ import type { Answers } from "../app/create.js"; export default class EnvironmentCreate extends Command { static description = "Create a new environment within a project."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> environment create"]; static flags = { @@ -35,14 +37,14 @@ export default class EnvironmentCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(EnvironmentCreate); let { projectId, name, description } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !name) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); // 1. Seleccionar proyecto @@ -124,6 +126,8 @@ export default class EnvironmentCreate extends Command { } this.log(chalk.green(`Environment '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating environment: ${error.message}`)); } diff --git a/src/commands/environment/delete.ts b/src/commands/environment/delete.ts index 8417ac1..fd02631 100644 --- a/src/commands/environment/delete.ts +++ b/src/commands/environment/delete.ts @@ -10,6 +10,8 @@ import type { Answers } from "../app/create.js"; export default class EnvironmentDelete extends Command { static description = "Delete an environment from a project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> environment delete", "$ <%= config.bin %> environment delete -p ", @@ -33,14 +35,14 @@ export default class EnvironmentDelete extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(EnvironmentDelete); let { projectId, environmentId } = flags; // Modo interactivo si no se proporcionan los flags necesarios if (!projectId || !environmentId) { - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); let selectedProject; @@ -122,6 +124,8 @@ export default class EnvironmentDelete extends Command { } this.log(chalk.green("Environment deleted successfully.")); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error deleting environment: ${error.message}`)); } diff --git a/src/commands/project/create.ts b/src/commands/project/create.ts index da57ac7..cd90ae8 100644 --- a/src/commands/project/create.ts +++ b/src/commands/project/create.ts @@ -7,6 +7,8 @@ import { readAuthConfig } from "../../utils/utils.js"; export default class ProjectCreate extends Command { static description = "Create a new project."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> project create", "$ <%= config.bin %> project create -n MyProject -d 'Project description'", @@ -31,7 +33,7 @@ export default class ProjectCreate extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(ProjectCreate); let { name, description } = flags; @@ -97,6 +99,8 @@ export default class ProjectCreate extends Command { } this.log(chalk.green(`Project '${name}' created successfully.`)); + + return response.data.result.data.json; } catch (error: any) { this.error(chalk.red(`Error creating project: ${error.message}`)); } diff --git a/src/commands/project/info.ts b/src/commands/project/info.ts index b461953..5075aac 100644 --- a/src/commands/project/info.ts +++ b/src/commands/project/info.ts @@ -9,6 +9,8 @@ export default class ProjectInfo extends Command { static description = "Get detailed information about a project, including the number of applications and databases."; + static enableJsonFlag = true; + static examples = [ "$ <%= config.bin %> project info", "$ <%= config.bin %> project info -p ", @@ -22,43 +24,43 @@ export default class ProjectInfo extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(ProjectInfo); if (flags.projectId) { - await this.showProjectInfo(auth, flags.projectId); - } else { - console.log(chalk.blue.bold("\n Listing all Projects \n")); - - try { - const projects = await getProjects(auth, this); - - if (projects.length === 0) { - this.log(chalk.yellow("No projects found.")); - return; - } - - const answers = await inquirer.prompt([ - { - choices: projects.map((project) => ({ - name: project.name, - value: project.projectId, - })), - message: "Select a project to view details:", - name: "selectedProject", - type: "list", - }, - ]); - - const selectedProjectId = answers.selectedProject; - - await this.showProjectInfo(auth, selectedProjectId); - } catch (error) { - // @ts-expect-error hola - this.error(chalk.red(`Failed to fetch project list: ${error.message}`)); + return this.showProjectInfo(auth, flags.projectId); + } + + this.log(chalk.blue.bold("\n Listing all Projects \n")); + + try { + const projects = await getProjects(auth, this); + + if (projects.length === 0) { + this.log(chalk.yellow("No projects found.")); + return; } + + const answers = await inquirer.prompt([ + { + choices: projects.map((project) => ({ + name: project.name, + value: project.projectId, + })), + message: "Select a project to view details:", + name: "selectedProject", + type: "list", + }, + ]); + + const selectedProjectId = answers.selectedProject; + + return this.showProjectInfo(auth, selectedProjectId); + } catch (error) { + // @ts-expect-error hola + this.error(chalk.red(`Failed to fetch project list: ${error.message}`)); } } @@ -66,7 +68,7 @@ export default class ProjectInfo extends Command { auth: { token: string; url: string }, projectId: string, ) { - console.log( + this.log( chalk.blue.bold(`\n Information for Project ID: ${projectId} \n`), ); @@ -185,6 +187,7 @@ export default class ProjectInfo extends Command { this.log(chalk.green(`Total PostgreSQL Databases: ${totalPostgreSQL}`)); this.log(chalk.green(`Total Redis Databases: ${totalRedis}`)); + return projectInfo; } catch (error) { this.error( // @ts-expect-error diff --git a/src/commands/project/list.ts b/src/commands/project/list.ts index 91242b6..1c18999 100644 --- a/src/commands/project/list.ts +++ b/src/commands/project/list.ts @@ -8,39 +8,44 @@ import { getProjects } from "../../utils/shared.js"; export default class ProjectList extends Command { static description = "List all projects."; + static enableJsonFlag = true; + static examples = ["$ <%= config.bin %> project list"]; - public async run(): Promise { + public async run(): Promise { const auth = await readAuthConfig(this); - console.log(chalk.blue.bold("\n Listing all Projects \n")); + this.log(chalk.blue.bold("\n Listing all Projects \n")); try { const projects = await getProjects(auth, this); if (projects.length === 0) { this.log(chalk.yellow("No projects found.")); - } else { - this.log(chalk.green("Projects:")); - const table = new Table({ - colWidths: [10, 30, 50], - head: [ - chalk.cyan("Index"), - chalk.cyan("Name"), - chalk.cyan("Description"), - ], - }); - const index = 1; - for (const project of projects) { - table.push([ - chalk.white(index + 1), - chalk.white(project.name), - chalk.gray(project.description || "No description"), - ]); - } - - this.log(table.toString()); + return []; + } + + this.log(chalk.green("Projects:")); + const table = new Table({ + colWidths: [10, 30, 50], + head: [ + chalk.cyan("Index"), + chalk.cyan("Name"), + chalk.cyan("Description"), + ], + }); + const index = 1; + for (const project of projects) { + table.push([ + chalk.white(index + 1), + chalk.white(project.name), + chalk.gray(project.description || "No description"), + ]); } + + this.log(table.toString()); + + return projects; } catch (error) { // @ts-expect-error error is not defined this.error(chalk.red(`Failed to list projects: ${error?.message}`)); diff --git a/src/commands/verify.ts b/src/commands/verify.ts index f9b6475..8534d52 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -15,7 +15,7 @@ export default class Verify extends Command { static examples = ["$ <%= config.bin %> <%= command.id %>"]; async run() { - console.log(chalk.blue.bold("\nVerifying Authentication Token")); + this.log(chalk.blue.bold("\nVerifying Authentication Token")); let token: string; let url: string; @@ -56,7 +56,7 @@ export default class Verify extends Command { // Validar el token contra el servidor try { - console.log(chalk.blue("Validating token with server...")); + this.log(chalk.blue("Validating token with server...")); const response = await axios.get( `${url}/api/trpc/user.get`,