7c661f47fd
# Introduction Defining very first basis of the twenty-cli e2e testing env. Dynamically generating tests cases based on a list of applications names that will be matched to stored twenty-apps and run install delete and reinstall with their configuration on the same instance We could use a glob pattern with a specific e2e configuration in every apps but right now overkill ## Notes - We should define typescript path aliasing to ease import devxp - parse the config using a zod object ## Some vision on test granularity Right now we only check that the server sent back success or failure on below operation. In the future the synchronize will return a report of what has been installed per entity exactly. We will be able to snapshot everything in order to detect regressions We should also be testing the cli directly for init and other stuff in the end, we could get some inspiration from what's done in preconstruct e2e tests with an on heap virtual file system ## Conclusion Any suggestions are more than welcomed ! close https://github.com/twentyhq/core-team-issues/issues/1721
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import chalk from 'chalk';
|
|
import inquirer from 'inquirer';
|
|
import { CURRENT_EXECUTION_DIRECTORY } from '../constants/current-execution-directory';
|
|
import { ApiService } from '../services/api.service';
|
|
import { ApiResponse } from '../types/config.types';
|
|
import { loadManifest } from '../utils/app-manifest-loader';
|
|
|
|
export class AppDeleteCommand {
|
|
private apiService = new ApiService();
|
|
|
|
async execute({
|
|
appPath = CURRENT_EXECUTION_DIRECTORY,
|
|
askForConfirmation,
|
|
}: {
|
|
appPath?: string;
|
|
askForConfirmation: boolean;
|
|
}): Promise<ApiResponse<any>> {
|
|
try {
|
|
console.log(chalk.blue('🚀 Deleting Twenty Application'));
|
|
console.log(chalk.gray(`📁 App Path: ${appPath}`));
|
|
console.log('');
|
|
|
|
if (askForConfirmation && !(await this.confirmationPrompt())) {
|
|
console.error(chalk.red('⛔️ Aborting deletion'));
|
|
process.exit(1);
|
|
}
|
|
|
|
const { packageJson } = await loadManifest(appPath);
|
|
|
|
const result = await this.apiService.deleteApplication(packageJson);
|
|
|
|
if (!result.success) {
|
|
console.error(chalk.red('❌ Deletion failed:'), result.error);
|
|
} else {
|
|
console.log(chalk.green('✅ Application deleted successfully'));
|
|
}
|
|
|
|
return result;
|
|
} catch (error) {
|
|
console.error(
|
|
chalk.red('Deletion failed:'),
|
|
error instanceof Error ? error.message : error,
|
|
);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
private async confirmationPrompt(): Promise<boolean> {
|
|
const { confirmation } = await inquirer.prompt([
|
|
{
|
|
type: 'confirm',
|
|
name: 'confirmation',
|
|
message: 'Are you sure you want to delete this application?',
|
|
default: false,
|
|
},
|
|
]);
|
|
|
|
return confirmation;
|
|
}
|
|
}
|