@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
62 lines • 3.36 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 });
exports.containerOpenCommand = containerOpenCommand;
const node_child_process_1 = require("node:child_process");
const checkDockerAvailable_1 = require("../utils/docker/checkDockerAvailable");
const getContainerName_1 = require("../utils/docker/getContainerName");
const isContainerRunning_1 = require("../utils/docker/isContainerRunning");
const logger_1 = require("../utils/logger");
function containerOpenCommand(options) {
return __awaiter(this, void 0, void 0, function* () {
const { name } = options;
try {
// Check Docker availability
const docker = yield (0, checkDockerAvailable_1.checkDockerAvailable)();
if (!docker.available) {
(0, logger_1.log)(docker.error || 'Docker is not available', 'error');
throw new Error('Docker is required to open containers');
}
const containerName = (0, getContainerName_1.getContainerName)(name);
// Check if container is running
if (!(yield (0, isContainerRunning_1.isContainerRunning)(containerName))) {
(0, logger_1.log)(`Container ${containerName} is not running. Start it first with: aidev container start ${name}`, 'error');
throw new Error(`Container ${containerName} is not running`);
}
(0, logger_1.log)(`Opening bash shell in container ${containerName}...`, 'info');
(0, logger_1.log)(`Type 'exit' to leave the container`, 'info');
// Use spawn to create an interactive shell
const dockerProcess = (0, node_child_process_1.spawn)('docker', ['exec', '-it', containerName, '/bin/bash'], {
stdio: 'inherit',
shell: false
});
// Handle process exit
dockerProcess.on('exit', (code) => {
if (code === 0) {
(0, logger_1.log)(`Exited container ${containerName}`, 'success');
}
else if (code !== null) {
(0, logger_1.log)(`Docker exec exited with code ${code}`, 'error');
}
});
// Handle errors
dockerProcess.on('error', (err) => {
(0, logger_1.log)(`Failed to open container: ${err.message}`, 'error');
throw err;
});
}
catch (error) {
(0, logger_1.log)(`Failed to open container: ${error instanceof Error ? error.message : String(error)}`, 'error');
throw error;
}
});
}
//# sourceMappingURL=containerOpenCommand.js.map