@lenne.tech/cli
Version:
lenne.Tech CLI: lt
130 lines (129 loc) • 5.39 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
/**
* Remove a Directus Docker instance
*/
const NewCommand = {
alias: ['rm'],
description: 'Remove Directus instance',
hidden: false,
name: 'remove',
run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c;
const { config, filesystem, parameters, print: { error, info, spin, success, warning }, prompt, system, } = toolbox;
// Load configuration
const ltConfig = config.loadConfig();
// Determine noConfirm
const noConfirm = config.getNoConfirm({
cliValue: parameters.options.noConfirm,
commandConfig: (_b = (_a = ltConfig === null || ltConfig === void 0 ? void 0 : ltConfig.commands) === null || _a === void 0 ? void 0 : _a.directus) === null || _b === void 0 ? void 0 : _b.remove,
config: ltConfig,
});
// Get instance name from argument or prompt
const cliName = parameters.first;
let instanceName;
const directusBaseDir = (0, path_1.join)(filesystem.homedir(), '.lt', 'directus');
// Check if directus directory exists
if (!filesystem.exists(directusBaseDir)) {
error('No Directus instances found.');
return;
}
// Get list of existing instances
const instances = ((_c = filesystem.list(directusBaseDir)) === null || _c === void 0 ? void 0 : _c.filter((item) => filesystem.isDirectory((0, path_1.join)(directusBaseDir, item)))) || [];
if (instances.length === 0) {
error('No Directus instances found.');
return;
}
if (cliName) {
instanceName = cliName;
}
else if (noConfirm) {
error('Instance name is required (provide as first argument)');
return;
}
else {
// Show available instances for selection
info('Available instances:');
instances.forEach((instance) => {
info(` - ${instance}`);
});
info('');
const nameResponse = yield prompt.ask({
message: 'Enter instance name to remove:',
name: 'name',
type: 'input',
});
instanceName = nameResponse.name;
}
if (!instanceName) {
error('Instance name is required!');
return;
}
const instanceDir = (0, path_1.join)(directusBaseDir, instanceName);
// Check if instance exists
if (!filesystem.exists(instanceDir)) {
error(`Instance "${instanceName}" not found.`);
info('Available instances:');
instances.forEach((instance) => {
info(` - ${instance}`);
});
return;
}
// Confirm deletion
if (!noConfirm) {
warning(`This will permanently delete instance "${instanceName}" and all its data!`);
const shouldDelete = yield prompt.confirm('Are you sure you want to continue?');
if (!shouldDelete) {
info('Operation cancelled.');
return;
}
}
// Stop and remove containers
const composePath = (0, path_1.join)(instanceDir, 'docker-compose.yml');
if (filesystem.exists(composePath)) {
const stopSpin = spin('Stopping and removing containers');
try {
yield system.run(`cd ${instanceDir} && docker-compose down -v`);
stopSpin.succeed();
}
catch (stopError) {
stopSpin.fail('Failed to stop containers');
if (stopError instanceof Error) {
warning(stopError.message);
}
warning('Continuing with directory removal...');
}
}
// Remove instance directory
const removeSpin = spin('Removing instance directory');
try {
filesystem.remove(instanceDir);
removeSpin.succeed();
}
catch (removeError) {
removeSpin.fail('Failed to remove instance directory');
if (removeError instanceof Error) {
error(removeError.message);
}
return;
}
success(`Instance "${instanceName}" removed successfully!`);
// Exit if not running from menu
if (!toolbox.parameters.options.fromGluegunMenu) {
process.exit();
}
// For tests
return `removed directus instance ${instanceName}`;
}),
};
exports.default = NewCommand;