const chalk = require("chalk"); module.exports = class VtexEngineValidator { metaDataPlaceHolderRepeated(file, metaData) { metaData.pages.forEach((pageData) => { let ids = {}; let dups = []; pageData.data.contentPlaceHolders.forEach((val) => { if (ids[val.id]) { dups.push(val); } else { ids[val.id] = true; } }); if (dups.length > 0) { console.log( chalk.red( `\n\n O ID: "${dups[0].id}" foi encontrado multiplas vezes no template: "${pageData.template}" \n\n` ) ); file += this._memeContent("https://i.imgflip.com/4fkkcz.jpg"); } }); return file; } placeHolderRepeated(file, regResult, basename) { let ids = {}; let dups = []; regResult.forEach((regexec) => { if (ids[regexec[1]]) { dups.push(regexec[1]); } else { ids[regexec[1]] = true; } }); if (dups.length > 0) { console.log( chalk.red( `\n\n O ID: "${dups[0]}" foi encontrado multiplas vezes no template: "${basename}" \n\n` ) ); file += this._memeContent("https://i.imgflip.com/4fkkcz.jpg"); } return file; } subTemplatesWithContentPlaceholder(fileContent, subtemplates, regex) { subtemplates.forEach((template) => { const placeholderRegex = new RegExp(regex.placeholder); const regexResult = placeholderRegex.exec(template.content); if (regexResult) { fileContent += this._memeContent( "https://i.imgflip.com/4fkgnr.jpg" ); console.log( chalk.red( ` \n\n Subtemplates não podem ter contentplaceholder ` ) ); console.log( chalk.red( `O Subtemplate "${template.name}" possui um contentPlaceholder \n\n` ) ); } }); return fileContent; } notClosedTags(fileContent) { const reImgNotClosed = new RegExp(/(])*)>/gi); const reInputNotClosed = new RegExp(/(])*)>/gi); const imgTest = reImgNotClosed.exec(fileContent); const inputTest = reInputNotClosed.exec(fileContent); if (imgTest) console.log( chalk.red( `\n\n A Tag: ${imgTest[0]} não foi fechada corretamente \n\n` ) ); if (inputTest) console.log( chalk.red( `\n\n A Tag: ${inputTest[0]} não foi fechada corretamente \n\n` ) ); return fileContent; } _memeContent(memeUrl) { return `
`; } };