src/index.js
function loadAndSaveShoots(settings, folderPath) {
  var promisesPool = [];
  var semaphore = new Semaphore({rooms: 6});

  settings.pages.forEach((page) => {
    settings.sizes.forEach((size) => {

      promisesPool.push(semaphore.add(() => {
        return new Promise((resolve, reject) => {

          console.log(`Start ${page.name} for ${size.width}x${size.height}`);

          screenshot({
            url : settings.urlBase + page.url,
            width : size.width,
            height : size.height,
            page: size.page === undefined ? true : size.page,
            cookies: settings.cookies,
            auth: settings.auth,
            delay: settings.delay,
          })
          .then(function(img){
            var fileName = getFileName(page, size);

            fs.writeFile(path.join(folderPath, fileName), img.data, function(err){
              if (err) {
                console.info(`Failed to save ${fileName}`, err)
              }

              resolve();
            });
          })
          .catch((err) => {
            console.info(`Failed to retrieve ${page.url}`, err)
            resolve();
          })

        })
      }))

    })
  })

  var promise = Promise.all(promisesPool);

  // Close screenshot service
  promise = promise.then(() => {
    console.log(`Done`)
    screenshot.close();
  }).catch(() => {
    console.log(`Done with errors`)
    screenshot.close();
  })

  return promise
}
function loadAndSaveShoots(settings, folderPath) {
  var promisesPool = [];
  var semaphore = new Semaphore({rooms: 6});

  settings.pages.forEach((page) => {
    settings.sizes.forEach((size) => {

      promisesPool.push(semaphore.add(() => {
        return new Promise((resolve, reject) => {

          console.log(`Start ${page.name} for ${size.width}x${size.height}`);

          screenshot({
            url : settings.urlBase + page.url,
            width : size.width,
            height : size.height,
            page: size.page === undefined ? true : size.page,
            cookies: settings.cookies,
            auth: settings.auth,
            delay: settings.delay,
          })
          .then(function(img){
            var fileName = getFileName(page, size);

            fs.writeFile(path.join(folderPath, fileName), img.data, function(err){
              if (err) {
                console.info(`Failed to save ${fileName}`, err)
              }

              resolve();
            });
          })
          .catch((err) => {
            console.info(`Failed to retrieve ${page.url}`, err)
            resolve();
          })

        })
      }))

    })
  })

  var promise = Promise.all(promisesPool);

  // Close screenshot service
  promise = promise.then(() => {
    console.log(`Done`)
    screenshot.close();
  }).catch(() => {
    console.log(`Done with errors`)
    screenshot.close();
  })

  return promise
}
function loadAndSaveShoots ( settings , folderPath ) { var promisesPool = [ ] ; var semaphore = new Semaphore ( { rooms : 6 } ) ; settings . pages . forEach ( ( page ) => { settings . sizes . forEach ( ( size ) => { promisesPool . push ( semaphore . add ( ( ) => { return new Promise ( ( resolve , reject ) => { console . log ( ` ${ page . name } ${ size . width } ${ size . height } ` ) ; screenshot ( { url : settings . urlBase + page . url , width : size . width , height : size . height , page : size . page === undefined ? true : size . page , cookies : settings . cookies , auth : settings . auth , delay : settings . delay , } ) . then ( function ( img ) { var fileName = getFileName ( page , size ) ; fs . writeFile ( path . join ( folderPath , fileName ) , img . data , function ( err ) { if ( err ) { console . info ( ` ${ fileName } ` , err ) } resolve ( ) ; } ) ; } ) . catch ( ( err ) => { console . info ( ` ${ page . url } ` , err ) resolve ( ) ; } ) } ) } ) ) } ) } ) var promise = Promise . all ( promisesPool ) ; // Close screenshot service promise = promise . then ( ( ) => { console . log ( ` ` ) screenshot . close ( ) ; } ) . catch ( ( ) => { console . log ( ` ` ) screenshot . close ( ) ; } ) return promise }
Creates screenshots based on provided settings and saves them into provided folder
@param  {Object} settings
@param  {String} folderPath
@return {Promise}
Creates screenshots based on provided settings and saves them into provided folder