Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dokploy/cli",
"description": "A CLI to manage dokploy server remotely",
"version": "v0.2.4",
"version": "v0.2.6",
"author": "Mauricio Siu",
"licenses": [{
"type": "MIT",
Expand Down
131 changes: 89 additions & 42 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,112 @@ export default class AppCreate extends Command {
description: "ID of the project",
required: false,
}),
name: Flags.string({
char: "n",
description: "Application name",
required: false,
}),
description: Flags.string({
char: "d",
description: "Application description",
required: false,
}),
appName: Flags.string({
description: "Docker app name",
required: false,
}),
skipConfirm: Flags.boolean({
char: "y",
description: "Skip confirmation prompt",
default: false,
}),
};

public async run(): Promise<void> {
const auth = await readAuthConfig(this);

const { flags } = await this.parse(AppCreate);
let { projectId, name, description, appName } = flags;

let { projectId } = flags;

if (!projectId) {
// Modo interactivo si no se proporcionan los flags necesarios
if (!projectId || !name || !appName) {
console.log(chalk.blue.bold("\n Listing all Projects \n"));

const projects = await getProjects(auth, this);

const { project } = await inquirer.prompt<Answers>([
{
choices: projects.map((project) => ({
name: project.name,
value: project,
})),
message: "Select a project to create the application in:",
name: "project",
type: "list",
},
]);
if (!projectId) {
const { project } = await inquirer.prompt<Answers>([
{
choices: projects.map((project) => ({
name: project.name,
value: project,
})),
message: "Select a project to create the application in:",
name: "project",
type: "list",
},
]);
projectId = project.projectId;
}

projectId = project.projectId;
if (!name || !appName) {
const appDetails = await inquirer.prompt([
{
message: "Enter the application name:",
name: "name",
type: "input",
validate: (input) => (input ? true : "Application name is required"),
default: name,
},
{
message: "Enter the application description (optional):",
name: "appDescription",
type: "input",
default: description,
},
]);

name = appDetails.name;
description = appDetails.appDescription;

const appNamePrompt = await inquirer.prompt([
{
default: appName || `${slugify(name)}`,
message: "Enter the App name:",
name: "appName",
type: "input",
validate: (input) => (input ? true : "App name is required"),
},
]);

const appDetails = await inquirer.prompt([
{
message: "Enter the application name:",
name: "name",
type: "input",
validate: (input) => (input ? true : "Application name is required"),
},
{
message: "Enter the application description (optional):",
name: "appDescription",
type: "input",
},
]);
appName = appNamePrompt.appName;
}
}

const appName = await inquirer.prompt([
// Confirmar si no se especifica --skipConfirm
if (!flags.skipConfirm) {
const confirm = await inquirer.prompt([
{
default: `${slugify(project.name)}-${appDetails.name}`,
message: "Enter the App name: (optional):",
name: "appName",
type: "input",
validate: (input) => (input ? true : "App name is required"),
type: 'confirm',
name: 'proceed',
message: 'Do you want to create this application?',
default: false,
},
]);

if (!confirm.proceed) {
this.error(chalk.yellow("Application creation cancelled."));
return;
}
}

try {
const response = await axios.post(
`${auth.url}/api/trpc/application.create`,
{
json: {
...appDetails,
appName: appName.appName,
projectId: project.projectId,
name,
appDescription: description,
appName,
projectId,
},
},
{
Expand All @@ -95,9 +142,9 @@ export default class AppCreate extends Command {
this.error(chalk.red("Error creating application"));
}

this.log(
chalk.green(`Application '${appDetails.name}' created successfully.`),
);
this.log(chalk.green(`Application '${name}' created successfully.`));
} catch (error: any) {
this.error(chalk.red(`Error creating application: ${error.message}`));
}
}
}
81 changes: 49 additions & 32 deletions src/commands/app/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,68 @@ export default class AppDelete extends Command {
description: "ID of the project",
required: false,
}),
applicationId: Flags.string({
char: 'a',
description: 'ID of the application to delete',
required: false,
}),
skipConfirm: Flags.boolean({
char: 'y',
description: 'Skip confirmation prompt',
default: false,
})
};

public async run(): Promise<void> {
const auth = await readAuthConfig(this);

const { flags } = await this.parse(AppDelete);
let { projectId, applicationId } = flags;

let { projectId } = flags;

if (!projectId) {
// Modo interactivo si no se proporcionan los flags necesarios
if (!projectId || !applicationId) {
console.log(chalk.blue.bold("\n Listing all Projects \n"));

const projects = await getProjects(auth, this);

const { project } = await inquirer.prompt<Answers>([
{
choices: projects.map((project) => ({
name: project.name,
value: project,
})),
message: "Select a project to create the application in:",
name: "project",
type: "list",
},
]);
if (!projectId) {
const { project } = await inquirer.prompt<Answers>([
{
choices: projects.map((project) => ({
name: project.name,
value: project,
})),
message: "Select a project to delete the application from:",
name: "project",
type: "list",
},
]);
projectId = project.projectId;
}

projectId = project.projectId;
const projectSelected = await getProject(projectId, auth, this);

if (projectSelected.applications.length === 0) {
this.error(chalk.yellow("No applications found in this project."));
}

const appAnswers = await inquirer.prompt([
{
// @ts-ignore
choices: projectSelected.applications.map((app) => ({
name: app.name,
value: app.applicationId,
})),
message: "Select the application to delete:",
name: "selectedApp",
type: "list",
},
]);

const applicationId = appAnswers.selectedApp;
if (!applicationId) {
const appAnswers = await inquirer.prompt([
{
// @ts-ignore
choices: projectSelected.applications.map((app) => ({
name: app.name,
value: app.applicationId,
})),
message: "Select the application to delete:",
name: "selectedApp",
type: "list",
},
]);
applicationId = appAnswers.selectedApp;
}
}

// // Confirmar eliminación
// Confirmar si no se especifica --skipConfirm
if (!flags.skipConfirm) {
const confirmAnswers = await inquirer.prompt([
{
default: false,
Expand All @@ -82,7 +95,9 @@ export default class AppDelete extends Command {
if (!confirmAnswers.confirmDelete) {
this.error(chalk.yellow("Application deletion cancelled."));
}
}

try {
const deleteResponse = await axios.post(
`${auth.url}/api/trpc/application.delete`,
{
Expand All @@ -103,6 +118,8 @@ export default class AppDelete extends Command {
}

this.log(chalk.green("Application deleted successfully."));
} catch (error: any) {
this.error(chalk.red(`Failed to delete application: ${error.message}`));
}
}
}
Loading
Loading