@graphteon/juricode
Version:
We are forging the future with lines of digital steel
107 lines • 3.82 kB
JavaScript
import prompts from 'prompts';
import chalk from 'chalk';
import ora from 'ora';
import boxen from 'boxen';
import { FileService } from '../api/file';
import fs from 'fs';
import path from 'path';
export const listFiles = async () => {
const answer = await prompts([
{
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 = ora('Fetching files...').start();
try {
const fileService = new FileService();
const files = await fileService.getFiles(answer.conversationId, answer.path);
spinner.succeed('Files fetched successfully!');
if (files.length === 0) {
console.log(chalk.yellow('No files found'));
return;
}
console.log(boxen(chalk.white(`Found ${files.length} file(s)${answer.path ? ` in ${answer.path}` : ''}`), { padding: 1, margin: { top: 1 }, borderColor: 'blue' }));
files.forEach(file => {
console.log(boxen(chalk.white(file), {
padding: 1,
margin: { top: 0, bottom: 1 },
borderColor: 'blue'
}));
});
}
catch (error) {
spinner.fail('Failed to fetch files');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
export const viewFile = async () => {
const answer = await prompts([
{
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 = ora('Fetching file content...').start();
try {
const fileService = new FileService();
const content = await fileService.getFile(answer.conversationId, answer.path);
spinner.succeed('File content fetched successfully!');
console.log(boxen(chalk.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.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
export const downloadWorkspace = async () => {
const answer = await prompts([
{
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 = ora('Downloading workspace...').start();
try {
const fileService = new FileService();
const blob = await fileService.getWorkspaceZip(answer.conversationId);
const buffer = Buffer.from(await blob.arrayBuffer());
const outputPath = path.resolve(answer.outputPath);
fs.writeFileSync(outputPath, buffer);
spinner.succeed(`Workspace downloaded successfully to ${outputPath}!`);
}
catch (error) {
spinner.fail('Failed to download workspace');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
//# sourceMappingURL=file.js.map