Last active
March 6, 2018 19:24
-
-
Save akopcz2/7b676d615caab4e5b41777c5ed4b9098 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gulp.task('dui', () =>{ | |
| return glob("deployment/public/services/print-at-your-service.html", function(er, files) { | |
| let totalFiles = []; | |
| let imageCount = 0; | |
| let currentWorkingDirectory = process.env.PWD + '/'; | |
| if(er){ | |
| throw(er); | |
| return; | |
| } | |
| (async function loop(){ | |
| for(let i = 0; i < files.length; i ++){ | |
| await new Promise(resolve => { | |
| let fullFile = currentWorkingDirectory + files[i]; | |
| checkForImage(fullFile); | |
| function checkForImage(fullFile){ | |
| fsc.readFile(fullFile).then(function($){ | |
| let documentBody = $('body').find('*'); | |
| for(let i = 0; i < documentBody.length; i ++){ | |
| let individualNode = documentBody[i]; | |
| if(individualNode.type === 'tag' && individualNode.name === 'img'){ | |
| imageCount++; | |
| let fileName = individualNode.attribs.src.split('/').pop(); | |
| totalFiles.push(fileName) | |
| } | |
| if(individualNode.type === 'tag' && individualNode.name === 'div'){ | |
| if(individualNode.attribs['data-mobile-image']){ | |
| let fileNameMobile = individualNode.attribs['data-mobile-image'].split('/').pop(); | |
| totalFiles.push(fileNameMobile); | |
| } | |
| if(individualNode.attribs['data-desktop-image']){ | |
| let fileNameDesktop = individualNode.attribs['data-desktop-image'].split('/').pop(); | |
| totalFiles.push(fileNameDesktop); | |
| } | |
| if(individualNode.attribs['data-tablet-image']){ | |
| let fileNameTablet = individualNode.attribs['data-tablet-image'].split('/').pop(); | |
| totalFiles.push(fileNameTablet); | |
| } | |
| } | |
| } | |
| // return totalFiles | |
| imageCount = 0; | |
| if(i == files.length - 1 ){ | |
| let cwd = process.env.PWD + '/public/uploads/images/'; | |
| let usedImagesFolder = process.env.PWD + '/public/uploads/chr/' | |
| for(let i = 0; i < totalFiles.length; i++){ | |
| let file = totalFiles[i]; | |
| find.file(file, cwd, function(image){ | |
| console.log(image, ' FOUND'); | |
| shell.exec(`cp ${image} ${usedImagesFolder}`); | |
| }); | |
| } | |
| } | |
| resolve(); | |
| }); | |
| } | |
| }) | |
| } | |
| })(); | |
| }); | |
| }); | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment