-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileManager.js
More file actions
55 lines (40 loc) · 1.79 KB
/
fileManager.js
File metadata and controls
55 lines (40 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// File management - upload, parsing, and tree building
import { defaultExclusions, formatFileSize, isTextFile } from './utils.js';
import { buildFolderTree, resetExclusions, loadGitignore } from './exclusionManager.js';
import { packCode, updateTotalLines } from './outputFormatter.js';
import { updateStatistics, showStatus, updateTabVisibility, switchTab } from './uiController.js';
import { saveRecentProject } from './uxEnhancements.js';
// Global state
export let projectFiles = [];
export let totalSize = 0;
// Set project files (used by other modules)
export function setProjectFiles(files) {
projectFiles = files;
}
// Function to handle folder selection and automatic packing
export async function handleFolderSelection(event) {
projectFiles = Array.from(event.target.files);
totalSize = projectFiles.reduce((acc, file) => acc + file.size, 0);
// Reset exclusions
resetExclusions();
// Update statistics
updateStatistics(projectFiles.length, formatFileSize(totalSize), 0);
showStatus(`Processing ${projectFiles.length} files...`, 'processing');
// Get project name from first file's path
const projectName = projectFiles[0].webkitRelativePath.split('/')[0];
const projectPath = projectFiles[0].webkitRelativePath.split('/')[0]; // Browser limitation
// Save to recent projects
saveRecentProject(projectName, projectPath, projectFiles.length);
// Load .gitignore if present
await loadGitignore(projectFiles);
// Build folder tree
buildFolderTree(projectFiles);
// Start packing immediately
await packCode(projectFiles);
// Update lines count
await updateTotalLines(projectFiles);
// Update UI visibility and switch to filter tab
updateTabVisibility();
switchTab('filter');
showStatus(`Successfully loaded ${projectFiles.length} files. Review exclusions in the Filter tab.`, 'success');
}