UNPKG

@graphteon/juricode

Version:

We are forging the future with lines of digital steel

116 lines 4.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.downloadWorkspace = exports.viewFile = exports.listFiles = void 0; const prompts_1 = __importDefault(require("prompts")); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const boxen_1 = __importDefault(require("boxen")); const file_1 = require("../api/file"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const listFiles = async () => { const answer = await (0, prompts_1.default)([ { type: 'text', name: 'conversationId', message: 'Enter conversation ID:', validate: (input) => input.length > 0 || 'Conversation ID is required' }, { type: 'text', name: 'path', message: 'Enter path (optional):', } ]); const spinner = (0, ora_1.default)('Fetching files...').start(); try { const fileService = new file_1.FileService(); const files = await fileService.getFiles(answer.conversationId, answer.path); spinner.succeed('Files fetched successfully!'); if (files.length === 0) { console.log(chalk_1.default.yellow('No files found')); return; } console.log((0, boxen_1.default)(chalk_1.default.white(`Found ${files.length} file(s)${answer.path ? ` in ${answer.path}` : ''}`), { padding: 1, margin: { top: 1 }, borderColor: 'blue' })); files.forEach(file => { console.log((0, boxen_1.default)(chalk_1.default.white(file), { padding: 1, margin: { top: 0, bottom: 1 }, borderColor: 'blue' })); }); } catch (error) { spinner.fail('Failed to fetch files'); console.error(chalk_1.default.red(error instanceof Error ? error.message : 'Unknown error')); } }; exports.listFiles = listFiles; const viewFile = async () => { const answer = await (0, prompts_1.default)([ { type: 'text', name: 'conversationId', message: 'Enter conversation ID:', validate: (input) => input.length > 0 || 'Conversation ID is required' }, { type: 'text', name: 'path', message: 'Enter file path:', validate: (input) => input.length > 0 || 'File path is required' } ]); const spinner = (0, ora_1.default)('Fetching file content...').start(); try { const fileService = new file_1.FileService(); const content = await fileService.getFile(answer.conversationId, answer.path); spinner.succeed('File content fetched successfully!'); console.log((0, boxen_1.default)(chalk_1.default.white(content), { padding: 1, margin: 1, borderColor: 'cyan', title: answer.path, titleAlignment: 'center' })); } catch (error) { spinner.fail('Failed to fetch file content'); console.error(chalk_1.default.red(error instanceof Error ? error.message : 'Unknown error')); } }; exports.viewFile = viewFile; const downloadWorkspace = async () => { const answer = await (0, prompts_1.default)([ { type: 'text', name: 'conversationId', message: 'Enter conversation ID:', validate: (input) => input.length > 0 || 'Conversation ID is required' }, { type: 'text', name: 'outputPath', message: 'Enter output path:', initial: './workspace.zip' } ]); const spinner = (0, ora_1.default)('Downloading workspace...').start(); try { const fileService = new file_1.FileService(); const blob = await fileService.getWorkspaceZip(answer.conversationId); const buffer = Buffer.from(await blob.arrayBuffer()); const outputPath = path_1.default.resolve(answer.outputPath); fs_1.default.writeFileSync(outputPath, buffer); spinner.succeed(`Workspace downloaded successfully to ${outputPath}!`); } catch (error) { spinner.fail('Failed to download workspace'); console.error(chalk_1.default.red(error instanceof Error ? error.message : 'Unknown error')); } }; exports.downloadWorkspace = downloadWorkspace; //# sourceMappingURL=file.js.map