96 lines
2.8 KiB
JavaScript
96 lines
2.8 KiB
JavaScript
|
|
#!/usr/bin/env node
|
||
|
|
|
||
|
|
const fs = require('fs');
|
||
|
|
|
||
|
|
// Create backup
|
||
|
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
|
||
|
|
const backupPath = `src/mocks/resumeInterviewMock.js.backup_${timestamp}_fully_remove`;
|
||
|
|
const mockContent = fs.readFileSync('src/mocks/resumeInterviewMock.js', 'utf-8');
|
||
|
|
fs.writeFileSync(backupPath, mockContent);
|
||
|
|
console.log(`✓ Backup created: ${backupPath}`);
|
||
|
|
|
||
|
|
// Function to fully remove all indentation from answers
|
||
|
|
function fullyRemoveIndentation(answer) {
|
||
|
|
// Split by newlines
|
||
|
|
const lines = answer.split('\\n');
|
||
|
|
const cleanedLines = [];
|
||
|
|
|
||
|
|
for (let line of lines) {
|
||
|
|
// Remove ALL leading whitespace from every line
|
||
|
|
const cleanedLine = line.trimStart();
|
||
|
|
|
||
|
|
// Only add non-empty lines or explicit empty lines
|
||
|
|
if (cleanedLine || line === '') {
|
||
|
|
cleanedLines.push(cleanedLine);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return cleanedLines.join('\\n');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Process the file
|
||
|
|
let updatedContent = mockContent;
|
||
|
|
let count = 0;
|
||
|
|
const processedAnswers = [];
|
||
|
|
|
||
|
|
// Pattern to match answer fields (handles escaped characters properly)
|
||
|
|
const answerRegex = /"answer":\s*"((?:[^"\\]|\\.)*)"/g;
|
||
|
|
|
||
|
|
updatedContent = updatedContent.replace(answerRegex, (match, answerContent) => {
|
||
|
|
// Unescape the answer content for processing
|
||
|
|
let unescaped = answerContent
|
||
|
|
.replace(/\\n/g, '\n')
|
||
|
|
.replace(/\\"/g, '"')
|
||
|
|
.replace(/\\\\/g, '\\');
|
||
|
|
|
||
|
|
// Fully remove all indentation
|
||
|
|
let cleaned = fullyRemoveIndentation(unescaped);
|
||
|
|
|
||
|
|
// Store first few for display
|
||
|
|
if (processedAnswers.length < 3) {
|
||
|
|
processedAnswers.push({
|
||
|
|
original: unescaped.substring(0, 200),
|
||
|
|
cleaned: cleaned.substring(0, 200)
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Re-escape for JSON
|
||
|
|
let escaped = cleaned
|
||
|
|
.replace(/\\/g, '\\\\')
|
||
|
|
.replace(/"/g, '\\"')
|
||
|
|
.replace(/\n/g, '\\n');
|
||
|
|
|
||
|
|
count++;
|
||
|
|
return `"answer": "${escaped}"`;
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log(`\n✅ Fully removed indentation from ${count} answer fields`);
|
||
|
|
|
||
|
|
// Save the file
|
||
|
|
fs.writeFileSync('src/mocks/resumeInterviewMock.js', updatedContent);
|
||
|
|
|
||
|
|
// Verify syntax
|
||
|
|
const { execSync } = require('child_process');
|
||
|
|
try {
|
||
|
|
execSync('node -c src/mocks/resumeInterviewMock.js', { encoding: 'utf-8' });
|
||
|
|
console.log('✅ Syntax validation passed');
|
||
|
|
|
||
|
|
// Show before/after comparison
|
||
|
|
console.log('\n📋 Before/After comparison:\n');
|
||
|
|
processedAnswers.forEach((item, idx) => {
|
||
|
|
console.log(`Example ${idx + 1}:`);
|
||
|
|
console.log('BEFORE (with indentation):');
|
||
|
|
console.log(item.original);
|
||
|
|
console.log('\nAFTER (left-aligned):');
|
||
|
|
console.log(item.cleaned);
|
||
|
|
console.log('\n' + '='.repeat(60) + '\n');
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('✅ All content is now left-aligned without any indentation.');
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('❌ Syntax error detected, restoring backup...');
|
||
|
|
fs.writeFileSync('src/mocks/resumeInterviewMock.js', mockContent);
|
||
|
|
console.log('Backup restored');
|
||
|
|
console.error('Error:', error.message);
|
||
|
|
}
|