- 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
import fs from 'fs-extra';
import needle from 'needle';
const createFile = ( filePath, content ) => {
fs.outputFile(filePath, content )
.then((data) => { console.log( filePath, "created!") })
.catch(( err) => { console.log(filePath, err) });
}
const initEnsureDirectory = (filePathDesktop, filePathMobile ) => {
fs.ensureDirSync(filePathDesktop)
fs.ensureDirSync(filePathMobile)
}
const createImages = ( { RSI, MastheadImage, MobileMastheadImage }, dataSourceStrategy ) => {
const filePathDesktop = dataSourceStrategy.filepath+'/masthead/sbsr/';
const filePathMobile = dataSourceStrategy.filepath+'/masthead/mobile/';
initEnsureDirectory( filePathDesktop, filePathMobile )
// var options = {
// headers: {
// 'Keep-Alive': true
// }
// }
// needle.get(MastheadImage[0].url, {output: `${filePathDesktop}/${RSI}.jpg`}, e => {
// if (e)
// {
// console.log(`Error happened creating ${filePathDesktop}/${RSI}.jpg`)
// console.log(e)
// }
// })
// needle.get(MastheadImage[0].url, {output: `${filePathMobile}/${RSI}.jpg`}, e => {
// if (e)
// {
// console.log(`Error happened creating ${filePathMobile}/${RSI}.jpg`)
// }
// })
const desktopImage = fs.createWriteStream(filePathDesktop+RSI+".jpg");
const mobileImage = fs.createWriteStream(filePathMobile+RSI+".jpg");
needle.get( MastheadImage[0].url).pipe(desktopImage).on('finish', function() {
console.log('Pipe finished!');
});
needle.get( MobileMastheadImage[0].url).pipe(mobileImage).on('finish', function() {
console.log('Pipe finished!');
});
}
export {
createFile,
createImages
}