Fix syntax errors in perfis-catalog.js for Vite compatibility
This commit is contained in:
41
fix_catalog.js
Normal file
41
fix_catalog.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const fs = require('fs');
|
||||
const path = 'm:/OFICIAIS E FUNCIONANDO/STEELBASE/js/sections/perfis-catalog.js';
|
||||
let content = fs.readFileSync(path, 'utf8');
|
||||
|
||||
// The main problem is that internal backticks are NOT escaped correctly,
|
||||
// or the outer ones ARE escaped.
|
||||
// We need:
|
||||
// return ` ... inner content ... `;
|
||||
// If inner content has backticks, they must be \`
|
||||
|
||||
// But the file currently has lots of \` and ` mixed up.
|
||||
|
||||
// Strategy:
|
||||
// 1. Unescape ALL backticks first.
|
||||
content = content.replace(/\\`/g, '`');
|
||||
|
||||
// 2. Find functions that start with return ` and ends with `; }
|
||||
// And escape all backticks INSIDE that range.
|
||||
|
||||
const functions = [
|
||||
'getCantoneirasContent',
|
||||
'getTubosRHSContent',
|
||||
'getChapasContent',
|
||||
'getPerfisHPContent',
|
||||
'getBarrasRoscadasContent',
|
||||
'getFerramentasSoldaContent',
|
||||
'getPerfisWContent'
|
||||
];
|
||||
|
||||
functions.forEach(fn => {
|
||||
const regex = new RegExp('(function\\s+' + fn + '\\s*\\(\\)\\s*\\{\\s*(?:console\\.log\\(.*?\\);\\s*)?return\\s+`)(.*?)(`;\\s*\\})', 'gs');
|
||||
content = content.replace(regex, (match, header, body, footer) => {
|
||||
// Escape backticks in body, but be careful about already escaped ones?
|
||||
// No, we unescaped them all in step 1.
|
||||
const escapedBody = body.replace(/`/g, '\\`');
|
||||
return header + escapedBody + footer;
|
||||
});
|
||||
});
|
||||
|
||||
fs.writeFileSync(path, content);
|
||||
console.log('Fixed perfis-catalog.js');
|
||||
Reference in New Issue
Block a user