-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathverify-checklist.ts
More file actions
167 lines (134 loc) · 5.47 KB
/
verify-checklist.ts
File metadata and controls
167 lines (134 loc) · 5.47 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env ts-node
import * as fs from 'fs';
import * as path from 'path';
interface FileMove {
originalPath: string;
newPath: string;
isCompleted: boolean;
lineNumber: number;
fullLine: string;
}
class ChecklistVerifier {
private srcDir = path.join(__dirname, 'src');
private checklistPath = path.join(__dirname, 'REORGANIZATION_CHECKLIST.md');
async verifyChecklist(): Promise<void> {
console.log('🔍 Verifying REORGANIZATION_CHECKLIST.md against actual file locations...\n');
const moves = this.parseChecklist();
let correctionsMade = 0;
let totalFiles = 0;
let completedFiles = 0;
const updatedLines: string[] = [];
const checklistContent = fs.readFileSync(this.checklistPath, 'utf-8');
const lines = checklistContent.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const move = moves.find(m => m.lineNumber === i);
if (move) {
totalFiles++;
const actualStatus = this.checkFileLocation(move);
if (actualStatus !== move.isCompleted) {
correctionsMade++;
const newLine = this.updateLineStatus(line, actualStatus);
updatedLines.push(newLine);
console.log(`${actualStatus ? '✅ CORRECTED' : '❌ CORRECTED'}: ${move.originalPath} → ${move.newPath}`);
console.log(` Was marked: ${move.isCompleted ? 'completed' : 'pending'}`);
console.log(` Actually is: ${actualStatus ? 'completed' : 'pending'}`);
console.log('');
} else {
updatedLines.push(line);
if (actualStatus) completedFiles++;
}
} else {
updatedLines.push(line);
}
}
// Update progress counts
const progressPercentage = totalFiles > 0 ? ((completedFiles / totalFiles) * 100).toFixed(1) : '0.0';
const remainingFiles = totalFiles - completedFiles;
for (let i = 0; i < updatedLines.length; i++) {
if (updatedLines[i].includes('**Completed:**') && updatedLines[i].includes('files ✅')) {
updatedLines[i] = `**Completed:** ${completedFiles} files ✅ (${progressPercentage}%)`;
}
if (updatedLines[i].includes('**Remaining:**') && updatedLines[i].includes('files')) {
updatedLines[i] = `**Remaining:** ${remainingFiles} files`;
}
}
if (correctionsMade > 0) {
fs.writeFileSync(this.checklistPath, updatedLines.join('\n'));
console.log(`📝 Made ${correctionsMade} corrections to the checklist`);
} else {
console.log('✅ Checklist is accurate - no corrections needed');
}
console.log(`\n📊 Summary:`);
console.log(` Total files: ${totalFiles}`);
console.log(` Completed: ${completedFiles} (${progressPercentage}%)`);
console.log(` Remaining: ${remainingFiles}`);
console.log(` Corrections made: ${correctionsMade}`);
}
private parseChecklist(): FileMove[] {
const content = fs.readFileSync(this.checklistPath, 'utf-8');
const lines = content.split('\n');
const moves: FileMove[] = [];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const match = line.match(/^- \[([ x])\] `([^`]+)` → `([^`]+)`/);
if (match) {
const [, checkbox, originalPath, newPath] = match;
moves.push({
originalPath: originalPath.trim(),
newPath: newPath.trim(),
isCompleted: checkbox === 'x',
lineNumber: i,
fullLine: line
});
}
}
return moves;
}
private checkFileLocation(move: FileMove): boolean {
const originalFullPath = path.join(this.srcDir, move.originalPath);
const newFullPath = path.join(this.srcDir, move.newPath);
const originalExists = fs.existsSync(originalFullPath);
const newExists = fs.existsSync(newFullPath);
// File is considered "completed" if it exists in the new location and not in the old location
// OR if it exists in both locations (might be a copy scenario)
// It's "pending" if it only exists in the original location
if (newExists && !originalExists) {
return true; // Moved successfully
}
if (newExists && originalExists) {
// Both exist - check modification times to see which is more recent
const originalStat = fs.statSync(originalFullPath);
const newStat = fs.statSync(newFullPath);
// If new file is more recent, consider it moved
return newStat.mtime >= originalStat.mtime;
}
if (!newExists && originalExists) {
return false; // Not moved yet
}
if (!newExists && !originalExists) {
// Neither exists - this might be a deleted file or wrong path
console.log(`⚠️ WARNING: Neither ${move.originalPath} nor ${move.newPath} exists`);
return false;
}
return false;
}
private updateLineStatus(line: string, isCompleted: boolean): string {
const checkbox = isCompleted ? 'x' : ' ';
const suffix = isCompleted ? ' ✅' : '';
// Remove existing checkmark if present
let updatedLine = line.replace(/ ✅$/, '');
// Update checkbox
updatedLine = updatedLine.replace(/^- \[([ x])\]/, `- [${checkbox}]`);
// Add checkmark if completed
if (isCompleted && !updatedLine.includes('✅')) {
updatedLine += suffix;
}
return updatedLine;
}
}
// Run the verifier
if (require.main === module) {
const verifier = new ChecklistVerifier();
verifier.verifyChecklist().catch(console.error);
}