lib/files.js
/** 
 * Reads and parses html file, finds all <img> and adds tumbnails, then rewrites file
 *
 * @returns Promise 
 */
Reads and parses html file, finds all  and adds tumbnails, then rewrites file
@returns Promise
Reads and parses html file finds all and adds tumbnails then rewrites file @returns Promise
function processFile( filename, cacheFolder) {
  return new Promise((resolve, reject) => {
    fs.stat(cacheFolder, (err, stat) => {
      if (err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')) {
        reject('Cannot find folder "' + cacheFolder + '"');
      } else {
        resolve();
      }
    })
  })
  .then(() => {
    const data = fs.readFileSync(filename).toString();
    const html = parse5.parse(data);
    const imgs = getByTagName('img', html);
    if (imgs.length > 0 ) {
      return Promise.resolve()
      .then(() => {
        return processImages(html, cacheFolder);
      })
      .then(() => {
        return addScripts(html, cacheFolder);
      })
      .then(() => {
        fs.writeFileSync(filename, parse5.serialize(html))
      });
    }
  });
}
function processFile ( filename , cacheFolder ) { return new Promise ( ( resolve , reject ) => { fs . stat ( cacheFolder , ( err , stat ) => { if ( err && ( err . code === 'ENOENT' || err . code === 'ENOTDIR' ) ) { reject ( 'Cannot find folder "' + cacheFolder + '"' ) ; } else { resolve ( ) ; } } ) } ) . then ( ( ) => { const data = fs . readFileSync ( filename ) . toString ( ) ; const html = parse5 . parse ( data ) ; const imgs = getByTagName ( 'img' , html ) ; if ( imgs . length > 0 ) { return Promise . resolve ( ) . then ( ( ) => { return processImages ( html , cacheFolder ) ; } ) . then ( ( ) => { return addScripts ( html , cacheFolder ) ; } ) . then ( ( ) => { fs . writeFileSync ( filename , parse5 . serialize ( html ) ) } ) ; } } ) ; }
Reads and parses html file, finds all <img> and adds tumbnails, then rewrites file
 @returns Promise
Reads and parses html file finds all <img > and adds tumbnails then rewrites file @returns Promise